create_release updated for wg_create_release.py refactoring

This commit is contained in:
Ken Conley 2009-10-09 19:03:49 +00:00
parent dfa049b3bf
commit 6536461411
1 changed files with 78 additions and 59 deletions

View File

@ -18,8 +18,11 @@ except ImportError:
class ReleaseException(Exception): pass
def main():
try:
def load_sys_args():
"""
@return: name, version, distro_file
@rtype: (str, str, str)
"""
from optparse import OptionParser
parser = OptionParser(usage="usage: %prog stack-or-app version distro.yaml", prog=NAME)
options, args = parser.parse_args()
@ -28,7 +31,14 @@ def main():
name, version, distro_file = args
if not os.path.isfile(distro_file):
parser.error("[%s] does not appear to be a valid file"%distro_file)
return name, version, distro_file
def load_and_validate_properties():
"""
@return: name, version, distro_file, source_dir, distro, release_props
@rtype: (str, str, str, str, str, dict)
"""
name, version, distro_file = load_sys_args()
# for now, we only work with stacks
source_dir = roslib.stacks.get_stack_dir(name)
if not source_dir:
@ -53,8 +63,15 @@ def main():
if cmake_version != version:
raise ReleaseException("version number in CMakeLists.txt appears to be incorrect:\n\n%s"%cmake_version)
return name, version, distro_file, source_dir, distro, release_props
def main():
try:
props = load_and_validate_properties()
name, version, distro_file, source_dir, distro, release_props = props[:6]
if 1:
make_dist(name, version, distro, source_dir, release_props)
dist = make_dist(name, version, distro, source_dir, release_props)
if 1:
tag_url = tag_subversion(name, version, distro, release_props)
@ -114,31 +131,10 @@ def tag_subversion(name, version, distro, release_props):
release_name = "%s-%s"%(name, version)
cmd = ['svn', 'ls', tag_url]
output = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
cmds = [['svn', 'cp', '--parents', '-m', 'Tagging %s release'%release_name, from_url, tag_url]]
if output[0]:
cmds = [['svn', 'rm', '-m', 'Deleting old tag', tag_url],
cmds[0]]
# Pretty-print a string version of the commands (I'm sure that Ken can
# do this in half a line of code)
cmd_str = ''
for c in cmds:
for s in c:
if ' ' in s:
cmd_str += '"%s" '%s
else:
cmd_str += '%s '%s
cmd_str += '\n'
print "Okay to execute:\n\n%s\n(y/n)?"%(cmd_str)
while 1:
input = sys.stdin.readline().strip()
if input in ['y', 'n']:
break
if input == 'y':
for c in cmds:
check_call(c)
else:
cmds = []
append_rm_if_exists(tag_url, cmds, 'Deleting old tag')
cmds.append(['svn', 'cp', '--parents', '-m', 'Tagging %s release'%release_name, from_url, tag_url])
if not ask_and_call(cmds):
print "create_release will not tag this release in subversion"
return tag_url
@ -227,6 +223,7 @@ def make_dist(name, version, distro, source_dir, release_props):
shutil.copyfile(src, dst)
shutil.rmtree(tmp_dir)
print_bold("Release should be in %s"%dst)
return dst
# this is copied from rosdistro -- need to change how
# rosdistro works so that it can be used as a library
@ -310,6 +307,28 @@ def check_svn_status(source_dir):
if output[1]:
raise ReleaseException("svn status in [%s] reported errors:\n%s"%(source_dir, output[0]))
def append_rm_if_exists(url, cmds, msg):
cmd = ['svn', 'ls', url]
output = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
if output[0]:
cmds.append(['svn', 'rm', '-m', msg, url])
## Pretty print cmds, ask if they should be run, and if so, runs them.
## Returns true if they were run.
def ask_and_call(cmds):
# Pretty-print a string version of the commands
def quote(s):
return '"%s"'%s if ' ' in s else s
print "Okay to execute:\n\n%s\n(y/n)?"%('\n'.join([' '.join([quote(s) for s in c]) for c in cmds]))
while 1:
input = sys.stdin.readline().strip()
if input in ['y', 'n']:
break
accepted = input == 'y'
if accepted:
for c in cmds:
check_call(c)
return accepted
if __name__ == '__main__':
main()