ba56b0d9c3e40f449f555edf4ceb99fb0fc3c88a
[dcpomatic.git] / release
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import datetime
6 import shutil
7
8 def command(c):
9     os.system(c)
10     print c
11
12 def release_version(s):
13     s = s[1:-1]
14     if s.endswith('pre'):
15         s = s[0:-3]
16     p = s.split('.')
17     return '0.%02d' % int(p[1])
18
19 def new_pre_version(s):
20     s = s[1:-1]
21     p = s.split('.')
22     return '0.%02dpre' % (int(p[1]) + 1)
23
24 def rewrite_wscript(version_maker):
25     f = open('wscript', 'rw')
26     o = open('wscript.tmp', 'w')
27     while 1:
28         l = f.readline()
29         if l == '':
30             break
31
32         s = l.split()
33         if len(s) == 3 and s[0] == "VERSION":
34             v = version_maker(s[2])
35             print "REWRITE %s -> %s" % (s[2], v)
36             print >>o,"VERSION = '%s'" % v
37         else:
38             print >>o,l,
39     f.close()
40     o.close()
41
42     os.rename('wscript.tmp', 'wscript')
43     return v
44
45 def append_to_changelog(version):
46     f = open('ChangeLog', 'r')
47     c = f.read()
48     f.close()
49
50     f = open('ChangeLog', 'w')
51     now = datetime.datetime.now()
52     f.write('%d-%02d-%02d  Carl Hetherington  <cth@carlh.net>\n\n\t* Version %s released.\n\n' % (now.year, now.month, now.day, version))
53     f.write(c)
54
55 command("git checkout master")
56
57 release_version_string = rewrite_wscript(release_version)
58 append_to_changelog(release_version_string)
59
60 command("git diff")
61 if (raw_input() != "y"):
62     command("git reset --hard")
63     print 'Aborted'
64     sys.exit(1)
65
66 command("git commit -a -m \"Bump version\"")
67 command("git tag -m \"v%s\" v%s" % (release_version_string, release_version_string))
68 command("./waf clean")
69 command("./waf")
70 command("./waf configure")
71 command("./waf dist")
72 command("./builds/windows-32")
73 shutil.copy(os.path.join('build', 'windows', 'DVD-o-matic %s 32-bit Installer.exe' % release_version_string), '.')
74 command("./builds/windows-64")
75 shutil.copy(os.path.join('build', 'windows', 'DVD-o-matic %s 64-bit Installer.exe' % release_version_string), '.')
76
77 rewrite_wscript(new_pre_version)
78
79 command("git diff")
80 if (raw_input() != "y"):
81     command("git reset --hard")
82     print 'Aborted'
83     sys.exit(1)
84
85 command("git commit -a -m \"Bump version\"")
86 command("cp DVD-o-matic*.exe dvdomatic-*.tar.bz2 /home/carl/public_html/carlh.net/software/dvdomatic")