summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2014-01-21 16:20:29 +0100
committerDamien Regad <dregad@mantisbt.org>2014-01-21 16:20:29 +0100
commitcad340f87ec83b0d972fb1141855e7181ae9a7f2 (patch)
treeedfeffb4be1e6bb30b74efe62c5ad976b15e9387
parent42110d5ec8d963aaba63544386029b315d52d08a (diff)
parent2be0a05462820b723de42671735a5b6fda00a57c (diff)
downloadadodb-cad340f87ec83b0d972fb1141855e7181ae9a7f2.tar.gz
adodb-cad340f87ec83b0d972fb1141855e7181ae9a7f2.tar.bz2
adodb-cad340f87ec83b0d972fb1141855e7181ae9a7f2.zip
New 'updateversion.py' script
-rwxr-xr-xscripts/buildrelease.py81
-rwxr-xr-xscripts/updateversion.py175
2 files changed, 192 insertions, 64 deletions
diff --git a/scripts/buildrelease.py b/scripts/buildrelease.py
index 5059c051..8b2c8578 100755
--- a/scripts/buildrelease.py
+++ b/scripts/buildrelease.py
@@ -3,7 +3,6 @@
ADOdb release build script
'''
-from datetime import date
import errno
import getopt
import re
@@ -14,6 +13,8 @@ import subprocess
import sys
import tempfile
+import updateversion
+
# ADOdb Repository reference
origin_repo = "git://git.code.sf.net/p/adodb/git adodb-git"
@@ -72,6 +73,7 @@ def main():
if len(args) < 2:
usage()
+ print "ERROR: please specify the version and release_path"
sys.exit(1)
fresh_clone = False
@@ -89,18 +91,12 @@ def main():
cleanup = False
# Mandatory parameters
- version = args[0]
- if not re.search("^%s$" % version_regex, version):
- usage()
- print "ERROR: invalid version ! \n"
- sys.exit(1)
- else:
- version = version.lstrip("Vv")
- global release_prefix
- release_prefix += version.split(".")[0]
-
+ version = updateversion.version_check(args[0])
release_path = args[1]
+ global release_prefix
+ release_prefix += version.split(".")[0]
+
# Start the build
print "Building ADOdb release %s into '%s'\n" % (
version,
@@ -160,69 +156,26 @@ def main():
print "\nERROR: branch must be aligned with upstream"
sys.exit(4)
+ # Updating the version
print "Preparing version bump commit"
- release_date = date.today().strftime("%d %b %Y")
-
- # Build sed script to update version information in source files
- copyright_string = "\(c\)"
-
- # - Part 1: version number and release date
- sed_script = "s/%s\s+%s\s+(%s)/V%s %s \\1/\n" % (
- version_regex,
- "[0-9].*[0-9]", # release date
- copyright_string,
- version,
- release_date
- )
- # - Part 2: copyright year
- sed_script += "s/(%s)\s*%s(.*Lim)/\\1 \\2-%s\\3/" % (
- copyright_string,
- "([0-9]+)-[0-9]+", # copyright years
- date.today().strftime("%Y")
- )
-
- # Build list of files to update
- def sed_filter(name):
- return name.lower().endswith((".php", ".htm", ".txt"))
- dirlist = []
- for root, dirs, files in os.walk(".", topdown=True):
- for name in filter(sed_filter, files):
- dirlist.append(path.join(root, name))
-
- # Bump version and set release date in source files, then commit
- print "Updating version and date in source files"
- subprocess.call(
- "sed -r -i '%s' %s " % (
- sed_script,
- " ".join(dirlist)
- ),
- shell=True
- )
- print "Committing"
- subprocess.call(
- "git commit --all --message '%s'" % (
- "Bump version to %s" % version
- ),
- shell=True
- )
+ updateversion.version_set(version, True)
# Create the tag
print "Creating release tag '%s'" % release_tag
subprocess.call(
"git tag --sign --message '%s' %s" % (
- "ADOdb version %s released %s" % (version, release_date),
+ "ADOdb version %s released %s" % (
+ version,
+ updateversion.release_date(version)
+ ),
release_tag
),
shell=True
)
- print '''
-NOTE: you should carefully review the new commit, making sure updates
-to the files are correct and no additional changes are required.
-If everything is fine, then the commit should be pushed upstream;
-otherwise:
- - Make the required corrections
- - Amend the commit ('git commit --all --amend' ) or create a new one
- - Drop the tag ('git tag --delete %s') and run this script again
+ print '''If the tag is incorrect (e.g. if you need to amend the version
+bump commit, you must then
+ - Drop the tag ('git tag --delete %1s')
+ - run this script again
''' % (
release_tag
)
diff --git a/scripts/updateversion.py b/scripts/updateversion.py
new file mode 100755
index 00000000..3fd4bc40
--- /dev/null
+++ b/scripts/updateversion.py
@@ -0,0 +1,175 @@
+#!/usr/bin/python -u
+'''
+ ADOdb version update script
+
+ Updates the version number, date and copyright year in
+ all php, txt and htm files
+'''
+
+from datetime import date
+import getopt
+import os
+from os import path
+import re
+import subprocess
+import sys
+
+# ADOdb version validation regex
+_version_dev = "dev"
+_version_regex = "[Vv]?[0-9]\.[0-9]+([a-z]|%s)?" % _version_dev
+_release_date_regex = "[0-9?]+.*[0-9]+"
+
+# Command-line options
+options = "hc"
+long_options = ["help", "commit"]
+
+
+def usage():
+ print '''Usage: %s version
+
+ Parameters:
+ version ADOdb version, format: [v]X.YY[a-z|dev]
+
+ Options:
+ -c | --commit Automatically commits the changes
+ -h | --help Show this usage message
+''' % (
+ path.basename(__file__)
+ )
+#end usage()
+
+
+def version_check(version):
+ ''' Checks that the given version is valid, exits with error if not.
+ Returns the version without the "v" prefix
+ '''
+ if not re.search("^%s$" % _version_regex, version):
+ usage()
+ print "ERROR: invalid version ! \n"
+ sys.exit(1)
+
+ return version.lstrip("Vv")
+
+
+def release_date(version):
+ ''' Returns the release date in DD-MMM-YYYY format
+ For development releases, DD-MMM will be ??-???
+ '''
+ # Development release
+ if version.endswith(_version_dev):
+ date_format = "??-???-%Y"
+ else:
+ date_format = "%d-%b-%Y"
+
+ # Define release date
+ return date.today().strftime(date_format)
+
+
+def sed_script(version):
+ ''' Builds sed script to update version information in source files
+ '''
+ copyright_string = "\(c\)"
+
+ # - Part 1: version number and release date
+ script = "s/%s\s+%s\s+(%s)/V%s %s \\2/\n" % (
+ _version_regex,
+ _release_date_regex,
+ copyright_string,
+ version,
+ release_date(version)
+ )
+
+ # - Part 2: copyright year
+ script += "s/(%s)\s*%s(.*Lim)/\\1 \\2-%s\\3/" % (
+ copyright_string,
+ "([0-9]+)-[0-9]+", # copyright years
+ date.today().strftime("%Y")
+ )
+
+ return script
+
+
+def sed_filelist():
+ ''' Build list of files to update
+ '''
+ def sed_filter(name):
+ return name.lower().endswith((".php", ".htm", ".txt"))
+
+ dirlist = []
+ for root, dirs, files in os.walk(".", topdown=True):
+ for name in filter(sed_filter, files):
+ dirlist.append(path.join(root, name))
+
+ return dirlist
+
+
+def version_set(version, do_commit):
+ ''' Bump version number and set release date in source files
+ '''
+ print "Updating version and date in source files"
+ subprocess.call(
+ "sed -r -i '%s' %s " % (
+ sed_script(version),
+ " ".join(sed_filelist())
+ ),
+ shell=True
+ )
+ print "Version set to %s" % version
+
+ if do_commit:
+ # Commit changes
+ print "Committing"
+ subprocess.call(
+ "git commit --all --message '%s'" % (
+ "Bump version to %s" % version
+ ),
+ shell=True
+ )
+
+ print '''
+NOTE: you should carefully review the new commit, making sure updates
+to the files are correct and no additional changes are required.
+If everything is fine, then the commit can be pushed upstream;
+otherwise:
+ - Make the required corrections
+ - Amend the commit ('git commit --all --amend' ) or create a new one
+'''
+ else:
+ print "Note: changes have been staged but not committed."
+#end version_set()
+
+
+def main():
+ # Get command-line options
+ try:
+ opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
+ except getopt.GetoptError, err:
+ print str(err)
+ usage()
+ sys.exit(2)
+
+ if len(args) < 1:
+ usage()
+ print "ERROR: please specify the version"
+ sys.exit(1)
+
+ do_commit = False
+
+ for opt, val in opts:
+ if opt in ("-h", "--help"):
+ usage()
+ sys.exit(0)
+
+ elif opt in ("-c", "--commit"):
+ do_commit = True
+
+ # Mandatory parameters
+ version = version_check(args[0])
+
+ # Let's do it
+ version_set(version, do_commit)
+#end main()
+
+
+if __name__ == "__main__":
+ main()