diff --git a/versionstamping/versionstamper.py b/versionstamping/versionstamper.py index 4c380a6..7a9c397 100644 --- a/versionstamping/versionstamper.py +++ b/versionstamping/versionstamper.py @@ -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: