implement remove-pkg for the cli

This commit is contained in:
Jay Greguske 2013-02-05 13:39:57 -05:00 committed by Mike McLean
parent d18d03174f
commit 0c2b9b73a1

View file

@ -772,6 +772,35 @@ def handle_block_pkg(options, session, args):
#really should implement multicall...
session.packageListBlock(tag,package)
def handle_remove_pkg(options, session, args):
"[admin] Remove a package from the listing for tag"
usage = _("usage: %prog remove-pkg [options] tag package [package2 ...]")
usage += _("\n(Specify the --help global option for a list of other help options)")
parser = OptionParser(usage=usage)
parser.add_option("--force", action='store_true', help=_("Override blocks if necessary"))
(options, args) = parser.parse_args(args)
if len(args) < 2:
parser.error(_("Please specify a tag and at least one package"))
assert False
activate_session(session)
tag = args[0]
opts = {}
opts['force'] = options.force
# check if list of packages exists for that tag already
dsttag=session.getTag(tag)
pkglist = dict([(p['package_name'], p['package_id']) for p in session.listPackages(tagID=dsttag['id'])])
ret = 0
for package in args[1:]:
package_id = pkglist.get(package, None)
if package_id is None:
print "Package %s is not in tag %s" % (package, tag)
ret = 1
if ret:
return ret
for package in args[1:]:
#really should implement multicall...
session.packageListRemove(tag, package, **opts)
def _unique_path(prefix):
"""Create a unique path fragment by appending a path component
to prefix. The path component will consist of a string of letter and numbers