00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 import os
00038 import sys
00039 from subprocess import call, check_call, Popen
00040 import traceback
00041
00042 import yaml
00043 import rospkg
00044
00045 from xml.dom.minidom import getDOMImplementation, parse
00046
00047 from .repo_util import guess_vcs_uri, get_svn_url
00048
00049 def generate_megastack(ctx, repos, checkouts_dir):
00050 all_stacks = { }
00051 print "generating megastack for repos", repos
00052 for repo_name, repo in repos:
00053 name = repo_name
00054 vcs = repo.type
00055 uri = repo.uri
00056
00057 print "snarfing stacks in local copy of %s"%name
00058 if repo_name == 'ros':
00059 rel_path = os.path.join(checkouts_dir, 'ros-repo')
00060 else:
00061 rel_path = os.path.join(checkouts_dir, repo_name)
00062
00063 abs_co_path = os.path.abspath(rel_path)
00064
00065 repos_stacks = {}
00066 rosstack = rospkg.RosStack([rel_path])
00067 for stack in rospkg.list_by_path('stack.xml', rel_path, cache=repos_stacks):
00068 if len(stack) == 0:
00069 print "empty stack name. i assume the uri was a direct stack checkout. using repo name as stack name: [%s]"%name
00070 stack = name
00071 if stack not in all_stacks:
00072
00073
00074
00075
00076 override_path = None
00077 true_uri = uri
00078 stack_path = rel_path
00079 try:
00080 stack_path = repos_stacks[stack]
00081 if vcs == 'svn':
00082 vcs0, true_uri = guess_vcs_uri(stack_path)
00083
00084
00085
00086 if true_uri != uri:
00087 url_path = get_svn_url(stack_path)
00088 override_path = url_path[len(true_uri):]
00089 else:
00090
00091
00092
00093 stack_path = os.path.abspath(stack_path)
00094 override_path = stack_path[len(abs_co_path):]
00095
00096 else:
00097
00098 override_path = ''
00099 if vcs == 'git':
00100
00101 vcs1, true_uri = guess_vcs_uri(stack_path)
00102 if 'github.com/' in uri and uri.endswith('.git'):
00103 true_uri = uri[:-4]
00104 except:
00105 traceback.print_exc()
00106 pass
00107
00108
00109 try:
00110 stack_packages = rosstack.packages_of(stack)
00111 all_stacks[stack] = [stack, name, true_uri, stack_path, override_path, stack_packages]
00112 except rospkg.ResourceNotFound:
00113 sys.stderr.write("ignoring stack [%s], environment improperly configured\n"%(stack))
00114
00115 print "creating megastack.(xml|yaml)"
00116
00117
00118 mega_yaml = []
00119 for k, v in all_stacks.iteritems():
00120 stack_name, repo, uri, rel_path, override_path, packages = v
00121 stack_p = rel_path+os.sep+'stack.xml'
00122 try:
00123 stack = parse(stack_p)
00124 try:
00125 m_obj = ctx.stack_manifests[stack_name]
00126 mega_yaml.append({'name': stack_name, 'brief': m_obj.brief, 'description': m_obj.description or '', 'repo': repo})
00127 except KeyError:
00128 sys.stderr.write("no manifest for [%s]\n"%(pkg))
00129
00130 rel_path = rel_path[len('checkouts/'+repo):]
00131 except Exception as e:
00132 print >> sys.stderr, "error parsing %s: %s"%(stack_p, str(e))
00133
00134 print "writing megastack ..."
00135 try:
00136 os.makedirs(ctx.docdir)
00137 except:
00138 pass
00139
00140 fname2 = os.path.join(ctx.docdir, 'megastack.yaml')
00141 with open(fname2, 'w') as f:
00142 f.write(yaml.safe_dump(mega_yaml, default_style="'"))
00143
00144 return [fname2]