1
#!/cygdrive/C/Python25/python
2
"""A script to help automate the build process."""
4
# When preparing a new release, make sure to set all of these to the latest
13
# This will be passed to 'make' to ensure we build with the right python
14
PYTHON='/cygdrive/c/Python25/python'
16
# Create the final build in this directory
19
DEBUG_SUBPROCESS = True
31
if BZR_EXE is not None:
34
subprocess.call(['bzr', '--version'], stdout=subprocess.PIPE,
35
stderr=subprocess.PIPE)
39
subprocess.call(['bzr.bat', '--version'], stdout=subprocess.PIPE,
40
stderr=subprocess.PIPE)
43
raise RuntimeError('Could not find bzr or bzr.bat on your path.')
47
def call_or_fail(*args, **kwargs):
48
"""Call a subprocess, and fail if the return code is not 0."""
50
print ' calling: "%s"' % (' '.join(args[0]),)
51
p = subprocess.Popen(*args, **kwargs)
52
(out, err) = p.communicate()
54
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs))
61
if TARGET is not None:
63
out = call_or_fail([sys.executable, get_bzr_dir() + '/bzr',
64
'version', '--short'], stdout=subprocess.PIPE)
66
TARGET = os.path.abspath(TARGET_ROOT + '-' + version)
71
"""Nuke the target directory so we know we are starting from scratch."""
73
if os.path.isdir(target):
74
print "Deleting: %s" % (target,)
78
return 'bzr.' + VERSIONS['bzr']
82
"""Make sure we have the latest bzr in play."""
83
bzr_dir = get_bzr_dir()
84
if not os.path.isdir(bzr_dir):
85
bzr_version = VERSIONS['bzr']
86
bzr_url = 'http://bazaar-vcs.org/bzr/bzr.' + bzr_version
87
print "Getting bzr release %s from %s" % (bzr_version, bzr_url)
88
call_or_fail([bzr(), 'co', bzr_url])
90
print "Ensuring %s is up-to-date" % (bzr_dir,)
91
call_or_fail([bzr(), 'update', bzr_dir])
96
print "Creating target dir: %s" % (target,)
97
call_or_fail([bzr(), 'co', get_bzr_dir(), target])
100
def get_plugin_trunk_dir(plugin_name):
101
return '%s/trunk' % (plugin_name,)
104
def get_plugin_release_dir(plugin_name):
105
return '%s/%s' % (plugin_name, VERSIONS[plugin_name])
108
def get_plugin_trunk_branch(plugin_name):
109
return 'lp:%s' % (plugin_name,)
112
def update_plugin_trunk(plugin_name):
113
trunk_dir = get_plugin_trunk_dir(plugin_name)
114
if not os.path.isdir(trunk_dir):
115
plugin_trunk = get_plugin_trunk_branch(plugin_name)
116
print "Getting latest %s trunk" % (plugin_name,)
117
call_or_fail([bzr(), 'co', plugin_trunk,
120
print "Ensuring %s is up-to-date" % (trunk_dir,)
121
call_or_fail([bzr(), 'update', trunk_dir])
125
def _plugin_tag_name(plugin_name):
126
if plugin_name == 'bzr-svn':
127
return 'bzr-svn-' + VERSIONS['bzr-svn']
128
# bzrtools and qbzr use 'release-X.Y.Z'
129
return 'release-' + VERSIONS[plugin_name]
132
def update_plugin(plugin_name):
133
release_dir = get_plugin_release_dir(plugin_name)
134
if not os.path.isdir(plugin_name):
135
if plugin_name == 'bzr-svn':
136
# bzr-svn uses a different repo format
137
call_or_fail([bzr(), 'init-repo', '--rich-root-pack', plugin_name])
139
os.mkdir(plugin_name)
140
if os.path.isdir(release_dir):
141
print "Removing existing dir: %s" % (release_dir,)
142
shutil.rmtree(release_dir)
144
trunk_dir = update_plugin_trunk(plugin_name)
145
# Now create the tagged directory
146
tag_name = _plugin_tag_name(plugin_name)
147
print "Creating the branch %s" % (release_dir,)
148
call_or_fail([bzr(), 'co', '-rtag:%s' % (tag_name,),
149
trunk_dir, release_dir])
153
def install_plugin(plugin_name):
154
release_dir = update_plugin(plugin_name)
155
# at least bzrtools doesn't like you to call 'setup.py' unless you are in
156
# that directory specifically, so we cd, rather than calling it from
158
print "Installing %s" % (release_dir,)
159
call_or_fail([sys.executable, 'setup.py', 'install', '-O1',
160
'--install-lib=%s' % (get_target(),)],
165
tbzr_loc = os.environ.get('TBZR', None)
167
raise ValueError('You must set TBZR to the location of tortoisebzr.')
168
print 'Updating %s' % (tbzr_loc,)
169
call_or_fail([bzr(), 'update', tbzr_loc])
172
def build_installer():
173
target = get_target()
177
print 'Building standalone installer'
178
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'],
185
p = optparse.OptionParser(usage='%prog [OPTIONS]')
186
opts, args = p.parse_args(args)
192
install_plugin('bzrtools')
193
install_plugin('qbzr')
194
install_plugin('bzr-svn')
199
if __name__ == '__main__':
202
# vim: ts=4 sw=4 sts=4 et ai