Add python script and eclipse project files for version numbering
This commit is contained in:
parent
61a6840f7c
commit
9f307dd502
3 changed files with 217 additions and 0 deletions
17
.project
Normal file
17
.project
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Common Build Scripts</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
.pydevproject
Normal file
8
.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 interpreter</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python35</pydev_property>
|
||||
</pydev_project>
|
||||
192
versionnumbering/versioninfo.py
Normal file
192
versionnumbering/versioninfo.py
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
# encoding: utf-8
|
||||
'''
|
||||
versionnumbering -- shortdesc
|
||||
|
||||
versionnumbering generates a version folder with a common set of version information files in it
|
||||
|
||||
@author: dan
|
||||
|
||||
@copyright: 2017 Global Inkjet Systems Ltd. All rights reserved.
|
||||
'''
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from argparse import RawDescriptionHelpFormatter
|
||||
|
||||
__all__ = []
|
||||
__version__ = 0.1
|
||||
__date__ = '2017-11-29'
|
||||
__updated__ = '2017-11-29'
|
||||
|
||||
def resetFolder(versionfolder):
|
||||
print("Removing folders and contents of: {0}".format(versionfolder))
|
||||
try:
|
||||
shutil.rmtree(versionfolder)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
print("Creating folder: {0}".format(versionfolder))
|
||||
os.makedirs(versionfolder)
|
||||
|
||||
def getGitRevision(gitrootpath, basenumber):
|
||||
cwd = os.getcwd()
|
||||
|
||||
path = os.path.expanduser(gitrootpath)
|
||||
print("Changing current working directory to: {0}".format(path))
|
||||
os.chdir(path)
|
||||
|
||||
gitvar = "GIT_EXECUTABLE"
|
||||
if gitvar in os.environ and os.environ[gitvar]:
|
||||
gitexecutable = os.environ[gitvar]
|
||||
else:
|
||||
print("Expecting GIT_EXECUTABLE environment variable to have path to git. Defaulting to 'git'")
|
||||
gitexecutable = "git"
|
||||
|
||||
print("Determining revision info using git command: {0}".format(gitexecutable))
|
||||
completed = subprocess.run([gitexecutable, "rev-list", "HEAD", "--count"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
changecount = completed.stdout.decode("utf-8").strip()
|
||||
print("Change count: {0}".format(changecount))
|
||||
adjustedchangecount = int(changecount) + int(basenumber)
|
||||
print("Adjusted change count: {0}".format(adjustedchangecount))
|
||||
|
||||
print("Determining current revision info using git command: {0}".format(gitexecutable))
|
||||
completed = subprocess.run([gitexecutable, "rev-parse", "HEAD"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
revision = completed.stdout.decode("utf-8").strip()
|
||||
print("Revision: {0}".format(revision))
|
||||
|
||||
os.chdir(cwd)
|
||||
print("Restored current working directory to: {0}".format(cwd))
|
||||
|
||||
return (adjustedchangecount, revision)
|
||||
|
||||
def getVersionPrefix(sourcebranch):
|
||||
print("Determining version number prefix from source branch name: {0}".format(sourcebranch))
|
||||
|
||||
defaultversionprefix = "1.30000.0"
|
||||
splits = sourcebranch.split('/')
|
||||
if len(splits) < 1:
|
||||
print("Source branch name is invalid. Defaulting to: {0}".format(defaultversionprefix))
|
||||
return defaultversionprefix
|
||||
|
||||
sourcebranch = splits[-1]
|
||||
|
||||
if sourcebranch.lower().endswith("master"): # Special case
|
||||
return "1.20000.0."
|
||||
|
||||
splits = sourcebranch.split('.')
|
||||
versionprefix = ""
|
||||
if len(splits) < 1:
|
||||
print("This source branch name has no decimal points in its name so defaulting to: {0}".format(defaultversionprefix))
|
||||
versionprefix = defaultversionprefix
|
||||
else:
|
||||
splitnumbercount = 0
|
||||
for split in splits:
|
||||
if split.isdigit():
|
||||
versionprefix += split + "."
|
||||
splitnumbercount += 1
|
||||
else:
|
||||
break
|
||||
if splitnumbercount > 2:
|
||||
break
|
||||
if splitnumbercount == 0:
|
||||
print("No leading numbers were found in source branch name so defaulting to: {0}".format(defaultversionprefix))
|
||||
versionprefix = defaultversionprefix
|
||||
elif splitnumbercount == 1:
|
||||
versionprefix += "0.0."
|
||||
elif splitnumbercount == 2:
|
||||
versionprefix += "0."
|
||||
|
||||
print("Determined version prefix to be: {0}".format(versionprefix))
|
||||
return versionprefix
|
||||
|
||||
def writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevision, buildnumber, buildstamp):
|
||||
with open(os.path.join(versionfolder, "buildjobname.txt"), 'w') as f:
|
||||
f.write(buildjobname)
|
||||
|
||||
with open(os.path.join(versionfolder, "prefix.txt"), 'w') as f:
|
||||
f.write(versionprefix)
|
||||
|
||||
with open(os.path.join(versionfolder, "revision.txt"), 'w') as f:
|
||||
f.write(gitrevision)
|
||||
|
||||
with open(os.path.join(versionfolder, "buildnumber.txt"), 'w') as f:
|
||||
f.write(buildnumber)
|
||||
|
||||
with open(os.path.join(versionfolder, "buildstamp.txt"), 'w') as f:
|
||||
f.write(buildstamp)
|
||||
|
||||
def main(argv=None): # IGNORE:C0111
|
||||
'''Command line options.'''
|
||||
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
else:
|
||||
sys.argv.extend(argv)
|
||||
|
||||
program_name = os.path.basename(sys.argv[0])
|
||||
program_version = "v%s" % __version__
|
||||
program_build_date = str(__updated__)
|
||||
program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
|
||||
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
|
||||
program_license = '''%s
|
||||
|
||||
Created by dan on %s.
|
||||
Copyright 2017 Global Inkjet Systems Ltd. All rights reserved.
|
||||
|
||||
Distributed on an "AS IS" basis without warranties
|
||||
or conditions of any kind, either express or implied.
|
||||
|
||||
USAGE
|
||||
''' % (program_shortdesc, str(__date__))
|
||||
|
||||
try:
|
||||
# Setup argument parser
|
||||
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
|
||||
parser.add_argument("-s", "--sourcebranch", dest="sourcebranch", action="store", default="origin/master", help="source branch name to discover version number [default: %(default)s]")
|
||||
parser.add_argument("-v", "--versionfolder", dest="versionfolder", action="store", default="version", help="version folder to be created [default: %(default)s]")
|
||||
parser.add_argument("-g", "--gitroot", dest="gitrootfolder", action="store", default="GitRepository", help="root path of source files [default: %(default)s]")
|
||||
parser.add_argument("-b", "--baseversionnumber", dest="baseversionnumber", action="store", default=int(1000), help="base git version number [default: %(default)s]")
|
||||
parser.add_argument("-j", "--buildjobname", dest="buildjobname", action="store", default="-", help="build job name [default: %(default)s]")
|
||||
parser.add_argument("-n", "--buildnumber", dest="buildnumber", action="store", default="1", help="build number [default: %(default)s]")
|
||||
|
||||
# Process arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
sourcebranch = args.sourcebranch
|
||||
versionfolder = args.versionfolder
|
||||
gitrootfolder = args.gitrootfolder
|
||||
baseversionnumber = args.baseversionnumber
|
||||
buildjobname = args.buildjobname
|
||||
buildnumber = args.buildnumber
|
||||
|
||||
print("Source branch:", sourcebranch, "version folder:", versionfolder, "Git root:", gitrootfolder)
|
||||
print("Base version number:", baseversionnumber, "Build job name:", buildjobname, "Build number:", buildnumber)
|
||||
|
||||
resetFolder(versionfolder)
|
||||
|
||||
(gitrevisioncount, gitrevision) = getGitRevision(gitrootfolder, baseversionnumber)
|
||||
|
||||
versionprefix = getVersionPrefix(sourcebranch)
|
||||
|
||||
buildstamp = versionprefix + str(gitrevisioncount)
|
||||
print("Build stamp is: {0}".format(buildstamp))
|
||||
|
||||
writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevision, buildnumber, buildstamp)
|
||||
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Error while creating version info:", e.__repr__())
|
||||
return 1
|
||||
except Exception as e:
|
||||
indent = len(program_name) * " "
|
||||
print(program_name + ": " + repr(e) + "\n")
|
||||
print(indent + " for help use --help")
|
||||
return 2
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue