diff --git a/osc/commandline.py b/osc/commandline.py index b6cbdee5..c4ddad05 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -436,6 +436,36 @@ class Osc(cmdln.Cmdln): return 1 link_pac(src_project, src_package, dst_project, dst_package) + def do_aggregatepac(self, subcmd, opts, *args): + """${cmd_name}: "Aggregate" a package to another package + + The DESTPAC name is optional; the source packages' name will be used if + DESTPAC is omitted. + + usage: + osc aggregatepac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC] + ${cmd_option_list} + """ + + args = slash_split(args) + + if not args or len(args) < 3: + print >>sys.stderr, 'Incorrect number of argument.' + self.do_help([None, 'aggregatepac']) + return 2 + + src_project = args[0] + src_package = args[1] + dst_project = args[2] + if len(args) > 3: + dst_package = args[3] + else: + dst_package = src_package + + if src_project == dst_project and src_package == dst_package: + print >>sys.stderr, 'Error: source and destination are the same.' + return 1 + aggregate_pac(src_project, src_package, dst_project, dst_package) @cmdln.option('-t', '--to-apiurl', metavar='URL', help='URL of destination api server. Default is the source api server.') diff --git a/osc/core.py b/osc/core.py index 91441e77..17d1698a 100755 --- a/osc/core.py +++ b/osc/core.py @@ -1423,6 +1423,50 @@ def link_pac(src_project, src_package, dst_project, dst_package): http_PUT(u, data=link_template) print 'Done.' +def aggregate_pac(src_project, src_package, dst_project, dst_package): + """ + aggregate package + - "src" is the original package + - "dst" is the "aggregate" package that we are creating here + """ + + src_meta = show_package_meta(conf.config['apiurl'], src_project, src_package) + + # replace package name and username + # using a string buffer + # and create the package + tree = ET.parse(StringIO(''.join(src_meta))) + root = tree.getroot() + root.set('name', dst_package) + root.set('project', dst_project) + tree.find('person').set('userid', conf.config['user']) + buf = StringIO() + tree.write(buf) + src_meta = buf.getvalue() + + edit_meta('pkg', + path_args=(dst_project, dst_package), + data=src_meta) + + # create the _aggregate file + # but first, make sure not to overwrite an existing one + if '_aggregate' in meta_get_filelist(conf.config['apiurl'], dst_project, dst_package): + print >>sys.stderr + print >>sys.stderr, '_aggregate file already exists...! Aborting' + sys.exit(1) + + print 'Creating _aggregate...', + aggregate_template = """\ + + + %s + + +""" % (src_project, src_package) + + u = makeurl(conf.config['apiurl'], ['source', dst_project, dst_package, '_aggregate']) + http_PUT(u, data=aggregate_template) + print 'Done.' def copy_pac(src_apiurl, src_project, src_package, dst_apiurl, dst_project, dst_package): @@ -1625,6 +1669,8 @@ def get_prj_results(apiurl, prj, show_legend=False): line = [] line.append(' ') for pac in pacs[startpac:startpac+max_pacs]: + if not status.has_key(pac): # for newly added packages, status may be missing + status[pac] = '?' line.append(status[pac]) line.append(' ') line.append(' %s %s' % (target['repo'], target['arch']))