updaterevision/updaterevision.py

changeset 77
32ef969adeed
parent 2
8be472cb0bca
child 124
c5ff5a4704dd
--- a/updaterevision/updaterevision.py	Fri May 15 20:13:36 2015 +0300
+++ b/updaterevision/updaterevision.py	Fri May 15 21:43:21 2015 +0300
@@ -33,41 +33,44 @@
 from datetime import datetime
 
 if len (sys.argv) != 2:
-    print 'usage: %s <output>' % sys.argv[0]
-    quit (1)
+	print 'usage: %s <output>' % sys.argv[0]
+	quit (1)
 
 oldrev = ''
 
 try:
-    with open (sys.argv[1]) as fp:
-        oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
+	with open (sys.argv[1]) as fp:
+		oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
 except IOError:
     pass
 
-data = subprocess.check_output (['hg', 'log', '-r.', '--template',
-    '{node|short} {branch} {date|hgdate}']).replace ('\n', '').split (' ')
+delim='@'*10
+rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template',
+	delim.join (['{node|short}', '{branch}', '{date|hgdate}', '{tags}'])]).replace ('\n', '').split (delim)
 
-rev = data[0]
-branch = data[1]
-timestamp = int (data[2])
+timestamp = int (timestampstr.split(' ')[0])
 date = datetime.utcfromtimestamp (timestamp)
 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000'
 
 if len(rev) > 7:
-    rev = rev[0:7]
+	rev = rev[0:7]
 
 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+':
-    rev += '+'
+	rev += '+'
 
 if rev == oldrev:
-    print "%s is up to date at %s" % (sys.argv[1], rev)
-    quit (0)
+	print "%s is up to date at %s" % (sys.argv[1], rev)
+	quit (0)
 
 with open (sys.argv[1], 'w') as fp:
-    fp.write ('// %s\n' % rev)
-    fp.write ('#define HG_NODE "%s"\n' % rev)
-    fp.write ('#define HG_BRANCH "%s"\n' % branch)
-    fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
-    fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
-    fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
-    print '%s updated to %s' % (sys.argv[1], rev)
+	fp.write ('// %s\n' % rev)
+	fp.write ('#define HG_NODE "%s"\n' % rev)
+	fp.write ('#define HG_BRANCH "%s"\n' % branch)
+	fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
+	fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
+	fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
+
+	if tags and tags != 'tip':
+		fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0])
+
+	print '%s updated to %s' % (sys.argv[1], rev)

mercurial