support for semantic versioning

This commit is contained in:
mdipierro
2012-12-20 15:39:57 -06:00
parent 64d6691e61
commit c1f47cdc44
3 changed files with 26 additions and 6 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ update:
wget -O gluon/contrib/simplejsonrpc.py http://rad2py.googlecode.com/hg/ide2py/simplejsonrpc.py
echo "remember that pymysql was tweaked"
src:
echo 'Version 2.3.2 ('`date +%Y-%m-%d\ %H:%M:%S`') dev' > VERSION
### Use semantic versioning
echo 'Version 2.3.2-alpha.1+timestamp.'`date +%Y.%m.%d.%H.%M.%S` > VERSION
### rm -f all junk files
make clean
### clean up baisc apps
+1 -1
View File
@@ -1 +1 @@
Version 2.3.2 (2012-12-20 09:21:27) dev
Version 2.3.2-alpha.1+timestamp.2012.12.20.15.39.20
+23 -4
View File
@@ -45,14 +45,33 @@ __all__ = [
]
def parse_version(version="Version 1.99.0 (2011-09-19 08:23:26)"):
def parse_semantic(version="Version 1.99.0-rc.1+timestamp.2011.09.19.08.23.26"):
"http://semver.org/"
re_version = re.compile('Version (\d+)\.(\d+)\.(\d+)(\-(?P<pre>[^\s+]*))?(\+(?P<build>\S*))')
m = re_version.match(version)
if not m:
return None
a, b, c = int(m.group(1)), int(m.group(2)), int(m.group(3))
pre_release = m.group('pre') or ''
build = m.group('build') or ''
if build.startswith('timestamp'):
build = datetime.datetime.strptime(build.split('.',1)[1], '%Y.%m.%d.%H.%M.%S')
return (a, b, c, pre_release, build)
def parse_legacy(version="Version 1.99.0 (2011-09-19 08:23:26)"):
re_version = re.compile('[^\d]+ (\d+)\.(\d+)\.(\d+)\s*\((?P<datetime>.+?)\)\s*(?P<type>[a-z]+)?')
m = re_version.match(version)
a, b, c = int(m.group(1)), int(m.group(2)), int(m.group(3)),
s = m.group('type') or 'dev'
d = datetime.datetime.strptime(m.group('datetime'), '%Y-%m-%d %H:%M:%S')
return (a, b, c, d, s)
pre_release = m.group('type') or 'dev'
build = datetime.datetime.strptime(m.group('datetime'), '%Y-%m-%d %H:%M:%S')
return (a, b, c, pre_release, build)
def parse_version(version):
items = parse_semantic(version)
if not items:
items = parse_legacy(version)
(a, b, c, pre_release, build) = items
return (a, b, c, build, pre_release) # build, pre_releas intentionally reversed
def read_file(filename, mode='r'):
"returns content from filename, making sure to close the file explicitly on exit."