23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
24 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
24 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING |
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 # |
31 # |
32 |
32 |
33 import argparse |
33 import argparse |
34 import outputfile |
34 import outputfile |
35 |
35 |
36 def main(): |
36 def main(): |
37 import subprocess |
37 import subprocess |
38 from datetime import datetime |
38 from datetime import datetime |
39 parser = argparse.ArgumentParser (description='Writes a header file with Hg commit information') |
39 parser = argparse.ArgumentParser(description='Writes a header file with Hg commit information') |
40 parser.add_argument ('output') |
40 parser.add_argument('--cwd', default = '.') |
|
41 parser.add_argument('output') |
41 args = parser.parse_args() |
42 args = parser.parse_args() |
42 f = outputfile.OutputFile (args.output) |
43 f = outputfile.OutputFile(args.output) |
43 data = subprocess.check_output (['hg', 'log', '-r.', '--template', |
44 data = subprocess.check_output(['hg', 'log', '--cwd', args.cwd, '-r.', '--template', |
44 '{node|short} {branch} {date|hgdate}']).replace ('\n', '').split (' ') |
45 '{node|short} {branch} {date|hgdate}']).decode().replace('\n', '').split(' ') |
45 |
46 |
46 rev = data[0] |
47 rev = data[0] |
47 branch = data[1] |
48 branch = data[1] |
48 timestamp = int (data[2]) |
49 timestamp = int(data[2]) |
49 date = datetime.utcfromtimestamp (timestamp) |
50 date = datetime.utcfromtimestamp(timestamp) |
50 datestring = date.strftime ('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' |
51 datestring = date.strftime('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' |
51 |
52 |
52 if len(rev) > 7: |
53 if len(rev) > 7: |
53 rev = rev[0:7] |
54 rev = rev[0:7] |
54 |
55 |
55 if subprocess.check_output (['hg', 'id', '-n']).replace ('\n', '')[-1] == '+': |
56 if subprocess.check_output(['hg', 'id', '--cwd', args.cwd, '-n']).decode().replace('\n', '').endswith('+'): |
56 rev += '+' |
57 rev += '+' |
57 |
58 |
58 f.write ('#define HG_NODE "%s"\n' % rev) |
59 f.write('#define HG_NODE "%s"\n' % rev) |
59 f.write ('#define HG_BRANCH "%s"\n' % branch) |
60 f.write('#define HG_BRANCH "%s"\n' % branch) |
60 f.write ('#define HG_DATE_VERSION "%s"\n' % datestring) |
61 f.write('#define HG_DATE_VERSION "%s"\n' % datestring) |
61 f.write ('#define HG_DATE_STRING "%s"\n' % date.strftime ('%d %b %Y')) |
62 f.write('#define HG_DATE_STRING "%s"\n' % date.strftime('%d %b %Y')) |
62 f.write ('#define HG_DATE_TIME %d\n' % int (timestamp)) |
63 f.write('#define HG_DATE_TIME %d\n' % int(timestamp)) |
63 if f.save(): |
64 if f.save(): |
64 print '%s updated to %s' % (f.filename, rev) |
65 print('%s updated to %s' %(f.filename, rev)) |
65 |
66 |
66 if __name__ == '__main__': |
67 if __name__ == '__main__': |
67 main() |
68 main() |