HMBXR5601-827 - Versionstamper.py is leaving excess files in package

This commit is contained in:
Dan Hawkins 2019-09-05 08:56:49 +01:00
commit b83050abc0

View file

@ -19,21 +19,15 @@ def main(argv):
print("Converting incidences of {0} with {1} in file: {2}\n".format(pattern, substitute, filetoconvert))
filecopy = filetoconvert + ".orig"
try:
shutil.move(filetoconvert, filecopy)
except FileNotFoundError:
print("Could not find file: {0}\n".format(filetoconvert))
return 1
with open(filetoconvert,'r') as c:
fileread = c.read()
count = 0
with open(filetoconvert, 'x') as f:
with open(filecopy,'r') as c:
fileread = c.read()
print("Detected %s instances of %s pre-conversion"%(fileread.count(pattern),pattern))
converted = fileread.replace(pattern, substitute)
count = converted.count(substitute)
print("Confirmed %s instances of %s post-conversion"%(count,substitute))
print("Detected %s instances of %s pre-conversion"%(fileread.count(pattern),pattern))
converted = fileread.replace(pattern, substitute)
count = converted.count(substitute)
print("Confirmed %s instances of %s post-conversion"%(count,substitute))
f.write(converted)
if count == 0: