updaterevision/updaterevision.py

Sun, 17 May 2015 22:07:48 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 17 May 2015 22:07:48 +0300
branch
protocol5
changeset 80
f992b027374b
parent 77
32ef969adeed
child 124
c5ff5a4704dd
permissions
-rw-r--r--

Added support for SVRC_YOUREDISCONNECTED

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 # Copyright 2014 Teemu Piippo
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 # All rights reserved.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 #
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 # Redistribution and use in source and binary forms, with or without
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 # modification, are permitted provided that the following conditions
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 # are met:
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 #
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 # 3. Neither the name of the copyright holder nor the names of its
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 # contributors may be used to endorse or promote products derived from
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 # this software without specific prior written permission.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 #
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 import sys
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 import subprocess
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 from datetime import datetime
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 if len (sys.argv) != 2:
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
36 print 'usage: %s <output>' % sys.argv[0]
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
37 quit (1)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 oldrev = ''
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 try:
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
42 with open (sys.argv[1]) as fp:
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
43 oldrev = fp.readline().replace ('\n', '').replace ('// ', '')
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 except IOError:
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 pass
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
47 delim='@'*10
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
48 rev, branch, timestampstr, tags = subprocess.check_output (['hg', 'log', '-r.', '--template',
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
49 delim.join (['{node|short}', '{branch}', '{date|hgdate}', '{tags}'])]).replace ('\n', '').split (delim)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
51 timestamp = int (timestampstr.split(' ')[0])
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 date = datetime.utcfromtimestamp (timestamp)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000'
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 if len(rev) > 7:
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
56 rev = rev[0:7]
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+':
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
59 rev += '+'
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 if rev == oldrev:
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
62 print "%s is up to date at %s" % (sys.argv[1], rev)
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
63 quit (0)
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 with open (sys.argv[1], 'w') as fp:
77
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
66 fp.write ('// %s\n' % rev)
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
67 fp.write ('#define HG_NODE "%s"\n' % rev)
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
68 fp.write ('#define HG_BRANCH "%s"\n' % branch)
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
69 fp.write ('#define HG_DATE_VERSION "%s"\n' % datestring)
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
70 fp.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y'))
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
71 fp.write ('#define HG_DATE_TIME %d\n' % int (timestamp))
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
72
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
73 if tags and tags != 'tip':
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
74 fp.write ('#define HG_TAG "%s"\n' % tags.split(' ')[0])
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
75
32ef969adeed Updated updaterevision.py, now handles tags and provides HG_TAG if appropriate
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
76 print '%s updated to %s' % (sys.argv[1], rev)

mercurial