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
14
# This will be passed to 'make' to ensure we build with the right python
15
PYTHON='/cygdrive/c/Python25/python'
17
# Create the final build in this directory
20
DEBUG_SUBPROCESS = True
32
if BZR_EXE is not None:
35
subprocess.call(['bzr', '--version'], stdout=subprocess.PIPE,
36
stderr=subprocess.PIPE)
40
subprocess.call(['bzr.bat', '--version'], stdout=subprocess.PIPE,
41
stderr=subprocess.PIPE)
44
raise RuntimeError('Could not find bzr or bzr.bat on your path.')
48
def call_or_fail(*args, **kwargs):
49
"""Call a subprocess, and fail if the return code is not 0."""
51
print ' calling: "%s"' % (' '.join(args[0]),)
52
p = subprocess.Popen(*args, **kwargs)
53
(out, err) = p.communicate()
55
raise RuntimeError('Failed to run: %s, %s' % (args, kwargs))
62
if TARGET is not None:
64
out = call_or_fail([sys.executable, get_bzr_dir() + '/bzr',
65
'version', '--short'], stdout=subprocess.PIPE)
67
TARGET = os.path.abspath(TARGET_ROOT + '-' + version)
72
"""Nuke the target directory so we know we are starting from scratch."""
74
if os.path.isdir(target):
75
print "Deleting: %s" % (target,)
79
return 'bzr.' + VERSIONS['bzr']
83
"""Make sure we have the latest bzr in play."""
84
bzr_dir = get_bzr_dir()
85
if not os.path.isdir(bzr_dir):
86
bzr_version = VERSIONS['bzr']
87
bzr_url = 'http://bazaar-vcs.org/bzr/bzr.' + bzr_version
88
print "Getting bzr release %s from %s" % (bzr_version, bzr_url)
89
call_or_fail([bzr(), 'co', bzr_url])
91
print "Ensuring %s is up-to-date" % (bzr_dir,)
92
call_or_fail([bzr(), 'update', bzr_dir])
97
print "Creating target dir: %s" % (target,)
98
call_or_fail([bzr(), 'co', get_bzr_dir(), target])
101
def get_plugin_trunk_dir(plugin_name):
102
return '%s/trunk' % (plugin_name,)
105
def get_plugin_release_dir(plugin_name):
106
return '%s/%s' % (plugin_name, VERSIONS[plugin_name])
109
def get_plugin_trunk_branch(plugin_name):
110
return 'lp:%s' % (plugin_name,)
113
def update_plugin_trunk(plugin_name):
114
trunk_dir = get_plugin_trunk_dir(plugin_name)
115
if not os.path.isdir(trunk_dir):
116
plugin_trunk = get_plugin_trunk_branch(plugin_name)
117
print "Getting latest %s trunk" % (plugin_name,)
118
call_or_fail([bzr(), 'co', plugin_trunk,
121
print "Ensuring %s is up-to-date" % (trunk_dir,)
122
call_or_fail([bzr(), 'update', trunk_dir])
126
def _plugin_tag_name(plugin_name):
127
if plugin_name in ('bzr-svn', 'subvertpy'):
128
return '%s-%s' % (plugin_name, VERSIONS[plugin_name])
129
# bzrtools and qbzr use 'release-X.Y.Z'
130
return 'release-' + VERSIONS[plugin_name]
133
def update_plugin(plugin_name):
134
release_dir = get_plugin_release_dir(plugin_name)
135
if not os.path.isdir(plugin_name):
136
if plugin_name == 'bzr-svn':
137
# bzr-svn uses a different repo format
138
call_or_fail([bzr(), 'init-repo', '--rich-root-pack', plugin_name])
140
os.mkdir(plugin_name)
141
if os.path.isdir(release_dir):
142
print "Removing existing dir: %s" % (release_dir,)
143
shutil.rmtree(release_dir)
145
trunk_dir = update_plugin_trunk(plugin_name)
146
# Now create the tagged directory
147
tag_name = _plugin_tag_name(plugin_name)
148
print "Creating the branch %s" % (release_dir,)
149
call_or_fail([bzr(), 'co', '-rtag:%s' % (tag_name,),
150
trunk_dir, release_dir])
154
def install_plugin(plugin_name):
155
release_dir = update_plugin(plugin_name)
156
# at least bzrtools doesn't like you to call 'setup.py' unless you are in
157
# that directory specifically, so we cd, rather than calling it from
159
print "Installing %s" % (release_dir,)
160
call_or_fail([sys.executable, 'setup.py', 'install', '-O1',
161
'--install-lib=%s' % (get_target(),)],
166
tbzr_loc = os.environ.get('TBZR', None)
168
raise ValueError('You must set TBZR to the location of tortoisebzr.')
169
print 'Updating %s' % (tbzr_loc,)
170
call_or_fail([bzr(), 'update', tbzr_loc])
173
def build_installer():
174
target = get_target()
178
print 'Building standalone installer'
179
call_or_fail(['make', 'PYTHON=%s' % (PYTHON,), 'installer'],
186
p = optparse.OptionParser(usage='%prog [OPTIONS]')
187
opts, args = p.parse_args(args)
193
install_plugin('subvertpy')
194
install_plugin('bzrtools')
195
install_plugin('qbzr')
196
install_plugin('bzr-svn')
201
if __name__ == '__main__':
204
# vim: ts=4 sw=4 sts=4 et ai