cutthecord/patches/branding/addpatch.py

47 lines
960 B
Python
Raw Normal View History

2019-01-25 12:48:05 +00:00
#!/bin/env python3
import os
2019-01-25 12:48:05 +00:00
import sys
fname = sys.argv[1]
persistdir = "/home/ave/distokrepos/versionlogs/"
def counterup():
# HACKY
cfname = persistdir + fname.split("/")[-1].replace(".patch", "")
if os.path.isfile(fname):
with open(cfname, 'r') as file:
countdata = file.read()
else:
countdata = 0
countdata = int(countdata) + 1
with open(cfname, 'w') as file:
file.write(str(countdata))
return countdata
2019-01-25 12:48:05 +00:00
# Read in the file
with open(fname, 'r') as file:
filedata = file.read()
buildnum = counterup()
2019-01-25 12:48:05 +00:00
name = "CutTheCord"
branch = "base"
if "customtheme" in sys.argv:
branch = "themed"
# name += " Themed"
2019-01-25 12:48:05 +00:00
# Replace the target string
filedata = filedata.replace("CTCBRANCH", branch)\
.replace("CTCBUILD", buildnum)\
2019-01-25 12:48:05 +00:00
.replace("CTCNAME", name)
# Write the file out again
with open(fname.replace(".patch", "-custom.patch"), 'w') as file:
file.write(filedata)