Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / makelib / buildnum.py
1 #!/usr/bin/python
2
3 import getopt
4 import os
5 import re
6 import subprocess
7 import sys
8
9 #_build_search = re.compile('^(Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)', re.MULTILINE)
10 _build_search = re.compile('</patch>', re.MULTILINE)
11
12 def getBuildNumber():
13   """Counts the number of patches that have been made and
14   returns that as the build number."""
15   
16   p = subprocess.Popen(['darcs', 'changes', '--xml-output'], stdout=subprocess.PIPE)
17   data = p.stdout.read()
18   build_num = len(_build_search.findall(data))
19   return build_num
20   
21 def createVersionHeader(path):
22   """Create a header file contianing our version number.
23   """
24   header = ['#ifdef _AUTOGEN_VERSION_HPP_',
25             '#define _AUTOGEN_VERSION_HPP_',
26             'const char *app_version_id = "%s"' % (getBuildNumber()),
27             '#endif',
28             '']
29   if os.path.exists(path):
30     # we need to see if its one of our headers
31     stream = open(path, 'r')
32     line = stream.readline().strip()
33     stream.close()
34     if line != header[0]:
35       raise RuntimeError("%s is not our header file" % path)
36   open(path,'w').writelines(os.linesep.join(header))
37
38 def main(arg_list):
39   """Basic command line driver script.
40   Call with something like sys.argv[1:]
41   """
42   opts, args = getopt.getopt(arg_list, "h:", 
43                              ["header="])
44   for option, argument in opts:
45     if option in ("-h", "--header"):
46       createVersionHeader(argument)
47       return 0
48
49   print "%s" % (getBuildNumber())
50   return 0
51
52 if __name__ == '__main__':
53   sys.exit(main(sys.argv[1:]))