def execute(self, server, options_dict, non_option_args): service = None if options_dict.has_key("service"): services = rcserviceutils.get_services(server) service = rcserviceutils.find_service(services, options_dict["service"]) if not service: rctalk.error("Unknown service '%s'" % options_dict["service"]) sys.exit(1) failed = 0 to_do = [] if options_dict.has_key("all"): to_do = filter(lambda c:not c["hidden"], rcchannelutils.get_channels(server)) if service: to_do = filter(lambda c,s=service:c.get("service") == s["id"], to_do) else: for a in non_option_args: clist = rcchannelutils.get_channels_by_name(server, a, service) if not rcchannelutils.validate_channel_list(a, clist): failed = 1 else: c = clist[0] to_do.append(c) if options_dict.has_key("strict") and not c["subscribed"]: rctalk.error("Not subscribed to channel " + \ rcchannelutils.channel_to_str(c)) failed = 1 if failed: sys.exit(1) for c in to_do: if c: if server.rcd.packsys.unsubscribe(c["id"]): rctalk.message("Unsubscribed from channel " + \ rcchannelutils.channel_to_str(c)) else: rctalk.warning("Attempt to unsubscribe to channel " + \ rcchannelutils.channel_to_str(c) + " failed")
def get_updates(server, non_option_args, allow_dups=0): up = server.rcd.packsys.get_updates() # If channels are specified by the command line, filter out all except # for updates from those channels. if non_option_args: channel_id_list = [] failed = 0 for a in non_option_args: clist = rcchannelutils.get_channels_by_name(server, a) if not rcchannelutils.validate_channel_list(a, clist): failed = 1 else: c = clist[0] if c["subscribed"]: channel_id_list.append(c["id"]) else: rctalk.warning("You are not subscribed to " + rcchannelutils.channel_to_str(c) + ", so no updates are available.") if failed: sys.exit(1) up = filter(lambda x, cidl=channel_id_list:x[1]["channel"] in cidl, up) # Filter out exact duplicates if not allow_dups: def pkg_to_key(p): return "%s:%d:%s:%s" % \ (p["name"], p["epoch"], p["version"], p["release"]) dup_dict = {} for u in up: key = pkg_to_key(u[1]) # u[1] is the new version of the package if not dup_dict.has_key(key): dup_dict[key] = u up = dup_dict.values() del dup_dict return up