Skip to content

Instantly share code, notes, and snippets.

@Headline
Created February 5, 2018 10:05
Show Gist options
  • Save Headline/76eca45276fc17a623f79ad824c7741f to your computer and use it in GitHub Desktop.
Save Headline/76eca45276fc17a623f79ad824c7741f to your computer and use it in GitHub Desktop.
Used for replacing version numbers in c# source files (replaces $$version$ w/ APPVEYOR_BUILD_VERSION)
import os
import os.path
def get_clean_path(array):
somestr = ""
for x in range(0, len(array) - 1):
somestr += array[x] + "\\"
return somestr
def do_version_replace(current):
oldlist = 0;
with open(current) as f:
oldlist = f.readlines();
for i, line in enumerate(oldlist):
if "$$version$" in line:
print("Replacing...")
oldlist[i] = line.replace("$$version$", os.getenv('APPVEYOR_BUILD_VERSION', "XX.XX.XX"))
with open(current, 'w') as f:
f.writelines(oldlist)
path = get_clean_path(os.path.realpath(__file__).split("\\"))
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
current = dirpath + "\\" + filename
if filename.endswith(".cs"):
print("Versioning: " + current)
do_version_replace(current)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment