31 import sys |
31 import sys |
32 import subprocess |
32 import subprocess |
33 from datetime import datetime |
33 from datetime import datetime |
34 |
34 |
35 if len (sys.argv) != 2: |
35 if len (sys.argv) != 2: |
36 print 'usage: %s <output>' % sys.argv[0] |
36 print 'usage: %s <output>' % sys.argv[0] |
37 quit (1) |
37 quit (1) |
38 |
38 |
39 oldrev = '' |
39 oldrev = '' |
40 |
40 |
41 try: |
41 try: |
42 with open (sys.argv[1]) as fp: |
42 with open (sys.argv[1]) as fp: |
43 oldrev = fp.readline().replace ('\n', '').replace ('// ', '') |
43 oldrev = fp.readline().replace ('\n', '').replace ('// ', '') |
44 except IOError: |
44 except IOError: |
45 pass |
45 pass |
46 |
46 |
47 data = subprocess.check_output (['hg', 'log', '-r.', '--template', |
47 delim='@'*10 |
48 '{node|short} {branch} {date|hgdate}']).replace ('\n', '').split (' ') |
48 rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template', |
|
49 delim.join (['{node|short}', '{branch}', '{date|hgdate}', '{tags}'])]).replace ('\n', '').split (delim) |
49 |
50 |
50 rev = data[0] |
51 timestamp = int (timestampstr.split(' ')[0]) |
51 branch = data[1] |
|
52 timestamp = int (data[2]) |
|
53 date = datetime.utcfromtimestamp (timestamp) |
52 date = datetime.utcfromtimestamp (timestamp) |
54 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' |
53 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' |
55 |
54 |
56 if len(rev) > 7: |
55 if len(rev) > 7: |
57 rev = rev[0:7] |
56 rev = rev[0:7] |
58 |
57 |
59 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+': |
58 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+': |
60 rev += '+' |
59 rev += '+' |
61 |
60 |
62 if rev == oldrev: |
61 if rev == oldrev: |
63 print "%s is up to date at %s" % (sys.argv[1], rev) |
62 print "%s is up to date at %s" % (sys.argv[1], rev) |
64 quit (0) |
63 quit (0) |
65 |
64 |
66 with open (sys.argv[1], 'w') as fp: |
65 with open (sys.argv[1], 'w') as fp: |
67 fp.write ('// %s\n' % rev) |
66 fp.write ('// %s\n' % rev) |
68 fp.write ('#define HG_NODE "%s"\n' % rev) |
67 fp.write ('#define HG_NODE "%s"\n' % rev) |
69 fp.write ('#define HG_BRANCH "%s"\n' % branch) |
68 fp.write ('#define HG_BRANCH "%s"\n' % branch) |
70 fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring) |
69 fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring) |
71 fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y')) |
70 fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y')) |
72 fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp)) |
71 fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp)) |
73 print '%s updated to %s' % (sys.argv[1], rev) |
72 |
|
73 if tags and tags != 'tip': |
|
74 fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0]) |
|
75 |
|
76 print '%s updated to %s' % (sys.argv[1], rev) |