Add version stamping
This commit is contained in:
parent
75d8716a0a
commit
cfbc3e70c5
3 changed files with 62 additions and 0 deletions
17
versionstamping/.project
Normal file
17
versionstamping/.project
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>versionstamping</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
8
versionstamping/.pydevproject
Normal file
8
versionstamping/.pydevproject
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/${PROJECT_DIR_NAME}</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python35</pydev_property>
|
||||
</pydev_project>
|
||||
37
versionstamping/versionstamper.py
Normal file
37
versionstamping/versionstamper.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import argparse
|
||||
import sys
|
||||
import shutil
|
||||
from builtins import FileNotFoundError
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description="Look for version number pattern in file and replace with autobuild version number")
|
||||
|
||||
# Call once arguments to allow or disallow something
|
||||
parser.add_argument('-f', '--filetoconvert', help='The file to convert')
|
||||
parser.add_argument('-p', '--pattern', default='1.30000.0.0', help='The pattern to search for and replace')
|
||||
parser.add_argument('-s', '--substitute', help='The new version number that will substitute the pattern')
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
filetoconvert = args.filetoconvert
|
||||
pattern = args.pattern
|
||||
substitute = args.substitute
|
||||
|
||||
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, 'x') as f:
|
||||
with open(filecopy) as c:
|
||||
converted = c.read().replace(pattern, substitute)
|
||||
f.write(converted)
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue