cutthecord/patches/branding/addpatch.py
2019-01-25 16:21:27 +03:00

46 lines
966 B
Python

#!/bin/env python3
import os
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(cfname):
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
# Read in the file
with open(fname, 'r') as file:
filedata = file.read()
buildnum = str(counterup())
name = "CutTheCord"
branch = "base"
if "customtheme" in sys.argv:
branch = "themed"
# name += " Themed"
# Replace the target string
filedata = filedata.replace("CTCBRANCH", branch)\
.replace("CTCBUILD", buildnum)\
.replace("CTCNAME", name)
# Write the file out again
with open(fname.replace(".patch", "-custom.patch"), 'w') as file:
file.write(filedata)