def execute(self, server, options_dict, non_option_args): if not non_option_args: rctalk.error("No user specified.") sys.exit(1) username = non_option_args[0] # Damn you, python 1.5.x. I want my lexical closures! matching = filter(lambda x,y=username:x[0] == y, server.rcd.users.get_all()) if not matching: rctalk.error("Unknown user '%s'" % username) sys.exit(1) new_password = "******" if options_dict.has_key("change-password"): new_password = get_password() set_privs = 1 try: set_privs = server.rcd.users.has_privilege("superuser") except ximian_xmlrpclib.Fault, f: # If our daemon doesn't have has_privilege, just let them # try. if f.faultCode != rcfault.undefined_method: raise
def find_latest_patch(server, patch, allow_unsub, quiet): plist = server.rcd.you.search([["name", "is", patch], ["installed", "is", "false"]]) if not plist: if not quiet: if allow_unsub: rctalk.error("Unable to find patch '%s'" % patch) else: rctalk.error("Unable to find patch '%s' in any " \ "subscribed channel" % patch) return [] pkeys = {} pl = [] for p in plist: if not pkeys.has_key(p["name"]): latest_p = get_latest_version(server, p["name"], allow_unsub, quiet) if latest_p: pl.append(latest_p) pkeys[p["name"]] = p return pl
def usage_basic(): rctalk.message("Usage: rug <command> <options> ...") rctalk.message("") keys = command_dict.keys() if keys: keys.sort() command_list = [] for k in keys: description, constructor, aliases, hidden, basic, category = command_dict[ k] if not hidden and basic: command_list.append([k, aliases, description, category]) rctalk.message("Some basic commands are:") print_command_list(command_list) rctalk.message("") rctalk.message( "For a more complete list of commands and important options,") rctalk.message("run \"rug help\".") rctalk.message("") else: rctalk.error("<< No commands found --- something is wrong! >>")
def execute(self, server, options_dict, non_option_args): if len(non_option_args) == 0: self.usage() sys.exit(1) error_flag = 0 for filename in non_option_args: full_fn = os.path.abspath(filename) try: plist = server.rcd.packsys.find_package_for_file(full_fn) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.package_not_found: rctalk.error("No package owns file '%s'" % full_fn) error_flag = 1 continue else: raise prefix = "" if len(non_option_args) > 1: prefix = "%s: " % full_fn for p in plist: if options_dict.has_key("no-abbrev"): rctalk.message("%s%s %s" % (prefix, p["name"], rcformat.evr_to_str(p))) else: rctalk.message( "%s%s %s" % (prefix, p["name"], rcformat.evr_to_abbrev_str(p)))
def usage_full(): rctalk.message("Usage: rug <command> <options> ...") rctalk.message("") rctalk.message("The following options are understood by all commands:") rcformat.opt_table(default_opt_table) keys = command_dict.keys() if keys: command_list = [] for k in keys: description, constructor, aliases, hidden, basic, category = command_dict[ k] if not hidden: command_list.append([k, aliases, description, category]) print_command_list(command_list, with_categories=1) rctalk.message("") rctalk.message( "For more detailed information about a specific command,") rctalk.message("run 'rug <command name> --help'.") rctalk.message("") else: rctalk.error("<< No commands found --- something is wrong! >>")
def execute(self, server, options_dict, non_option_args): if len(non_option_args) == 0: self.usage() sys.exit(1) error_flag = 0 for filename in non_option_args: full_fn = os.path.abspath(filename) try: plist = server.rcd.packsys.find_package_for_file(full_fn) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.package_not_found: rctalk.error("No package owns file '%s'" % full_fn) error_flag = 1 continue else: raise prefix = "" if len(non_option_args) > 1: prefix = "%s: " % full_fn for p in plist: if options_dict.has_key("no-abbrev"): rctalk.message("%s%s %s" % (prefix, p["name"], rcformat.evr_to_str(p))) else: rctalk.message("%s%s %s" % (prefix, p["name"], rcformat.evr_to_abbrev_str(p)))
def execute(self, server, options_dict, non_option_args): if len(non_option_args) != 1: self.usage() sys.exit(1) plist = rcpackageutils.find_package(server, non_option_args[0], 1) if not plist: rctalk.message("--- No package found ---") sys.exit(1) pkg = None for p in plist: if p["installed"] or p.get("package_filename", None): pkg = p break if not pkg: rctalk.message("--- File information not available ---") sys.exit(1) try: file_list = server.rcd.packsys.file_list(pkg) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.undefined_method: rctalk.error("File list is not supported by this daemon") sys.exit(1) else: raise
def execute(self, server, options_dict, non_option_args): packages_to_remove = [] for a in non_option_args: plist = rcpackageutils.find_package_on_system(server, a) if not plist: rctalk.error("Unable to find package '" + a + "'") sys.exit(1) for p in plist: dups = filter(lambda x, pn=p:x["name"] == pn["name"], packages_to_remove) if dups: rctalk.warning("Duplicate entry found: " + dups[0]["name"]) else: packages_to_remove.append(p) if not packages_to_remove: rctalk.message("--- No packages to remove ---") sys.exit(0) install_deps, remove_deps, dep_info = \ resolve_dependencies(server, [], packages_to_remove, []) self.transact(server, options_dict, [], [], packages_to_remove, remove_deps)
def find_latest_package(server, package, allow_unsub, quiet): plist = server.rcd.packsys.search([["name", "is", package], ["installed", "is", "false"]]) if not plist: if not quiet: if allow_unsub: rctalk.error("Unable to find package '" + package + "'") else: rctalk.error("Unable to find package '" + package + "' in any subscribed channel") return [] pkeys = {} pl = [] for p in plist: if not pkeys.has_key(p["name"]): latest_p = get_latest_version(server, p["name"], allow_unsub, quiet) if latest_p: pl.append(latest_p) pkeys[p["name"]] = p return pl
def execute(self, server, options_dict, non_option_args): packages_to_remove = [] for a in non_option_args: plist = rcpackageutils.find_package_on_system(server, a) if not plist: rctalk.error("Unable to find package '" + a + "'") sys.exit(1) for p in plist: dups = filter(lambda x, pn=p: x["name"] == pn["name"], packages_to_remove) if dups: rctalk.warning("Duplicate entry found: " + dups[0]["name"]) else: packages_to_remove.append(p) if not packages_to_remove: rctalk.message("--- No packages to remove ---") sys.exit(0) install_deps, remove_deps, dep_info = \ resolve_dependencies(server, [], packages_to_remove, []) self.transact(server, options_dict, [], [], packages_to_remove, remove_deps)
def execute(self, server, options_dict, non_option_args): if non_option_args: try: f = open(non_option_args[0], "w") except IOError, e: rctalk.error("Couldn't open '" + non_option_args[0] + "' for writing: " + e.strerror) sys.exit(1) my_open = 1
class PrefsSetCmd(rccommand.RCCommand): def name(self): return "set-prefs" def aliases(self): return ["set"] def arguments(self): return "<pref name> <value>" def description_short(self): return "Set a preference variable" def category(self): return "prefs" def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 2: self.usage() sys.exit(0) try: pref = server.rcd.prefs.get_pref(non_option_args[0]) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.invalid_preference: rctalk.error("There is no preference named '" + non_option_args[0] + "'") sys.exit(1) else: raise if string.lower(non_option_args[1]) == "true" or \ string.lower(non_option_args[1]) == "on" or \ string.lower(non_option_args[1]) == "yes": value = ximian_xmlrpclib.True elif string.lower(non_option_args[1]) == "false" or \ string.lower(non_option_args[1]) == "off" or \ string.lower(non_option_args[1]) == "no": value = ximian_xmlrpclib.False else: try: value = int(non_option_args[1]) except ValueError: value = non_option_args[1] success = 0 try: server.rcd.prefs.set_pref(non_option_args[0], value) success = 1 except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.type_mismatch: # FIXME: This error message sucks rctalk.error("Can't set preference: " + f.faultString) elif f.faultCode == rcfault.cant_set_preference: rctalk.error(f.faultString) else: raise
def verify_dependencies(server): try: return server.rcd.packsys.verify_dependencies() except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.failed_dependencies: rctalk.error(f.faultString) sys.exit(1) else: raise
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1: self.usage() sys.exit(1) try: when = int(date_converter(string.join(non_option_args, " "))) except ValueError, e: rctalk.error("Unable to rollback: %s" % e) return 1
def execute(self, server, options_dict, non_option_args): try: items = server.rcd.system.get_recurring() except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.undefined_method: rctalk.error("Server does not support 'recurring'.") sys.exit(1) else: raise
def find_package_in_channel(server, channel, package, allow_unsub): plist = server.rcd.packsys.search([["name", "is", package], ["installed", "is", "false"], ["channel", "is", str(channel)]]) if not plist: rctalk.error("Unable to find package '" + package + "'") return [] return plist
def find_patch_in_channel(server, channel, patch, allow_unsub): plist = server.rcd.you.search([["name", "is", patch], ["installed", "is", "false"], ["channel", "is", str(channel)]]) if not plist: rctalk.error("Unable to find patch '" + patch + "'") return [] return plist
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 2: self.usage() sys.exit(0) try: pref = server.rcd.prefs.get_pref(non_option_args[0]) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.invalid_preference: rctalk.error("There is no preference named '" + non_option_args[0] + "'") sys.exit(1) else: raise
def parse_dep_str(server, dep_str): dep = {} package = string.split(dep_str) if len(package) > 1: valid_relations = ["=", "<", "<=", ">", ">=", "!="] if not package[1] in valid_relations: rctalk.error("Invalid relation.") sys.exit(1) channel_id, name = split_channel_and_name(server, package[0]) if channel_id: dep["channel"] = channel_id dep["name"] = name dep["relation"] = package[1] version_regex = re.compile("^(?:(\d+):)?(.*?)(?:-([^-]+))?$") match = version_regex.match(package[2]) if match.group(1): dep["has_epoch"] = 1 dep["epoch"] = int(match.group(1)) else: dep["has_epoch"] = 0 dep["epoch"] = 0 dep["version"] = match.group(2) if match.group(3): dep["release"] = match.group(3) else: dep["release"] = "" else: channel_id, name = split_channel_and_name(server, dep_str) if channel_id: dep["channel"] = channel_id dep["name"] = name dep["relation"] = "(any)" dep["has_epoch"] = 0 dep["epoch"] = 0 dep["version"] = "*" dep["release"] = "*" return dep
def get_latest_version(server, patch, allow_unsub, quiet): try: if allow_unsub: b = ximian_xmlrpclib. False else: b = ximian_xmlrpclib. True p = server.rcd.you.find_latest_version(patch, b) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.package_not_found: if not quiet: if allow_unsub: rctalk.error("Unable to find patch '%s'" % patch) else: rctalk.error("Unable to find patch '%s' in any " \ "subscribed channel" % patch) p = None elif f.faultCode == rcfault.package_is_newest: if not quiet: if allow_unsub: rctalk.error("There is no newer version of '%s'" % patch) else: rctalk.error("There is no newer version of '%s'" \ "in any subscribed channel" % patch) p = None else: raise
def get_latest_version(server, patch, allow_unsub, quiet): try: if allow_unsub: b = ximian_xmlrpclib.False else: b = ximian_xmlrpclib.True p = server.rcd.you.find_latest_version(patch, b) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.package_not_found: if not quiet: if allow_unsub: rctalk.error("Unable to find patch '%s'" % patch) else: rctalk.error("Unable to find patch '%s' in any " \ "subscribed channel" % patch) p = None elif f.faultCode == rcfault.package_is_newest: if not quiet: if allow_unsub: rctalk.error("There is no newer version of '%s'" % patch) else: rctalk.error("There is no newer version of '%s'" \ "in any subscribed channel" % patch) p = None else: raise
def resolve_dependencies(server, install_packages, remove_packages, extra_reqs): install_packages = filter_dups(install_packages) remove_packages = filter_dups(remove_packages) extra_reqs = filter_dups(extra_reqs) try: return server.rcd.packsys.resolve_dependencies(install_packages, remove_packages, extra_reqs) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.failed_dependencies: rctalk.error(f.faultString) sys.exit(1) else: raise
def resolve_dependencies(server, install_packages, remove_packages, extra_reqs): install_packages = filter_dups(install_packages) remove_packages = filter_dups(remove_packages) extra_reqs = filter_dups(extra_reqs) try: return server.rcd.packsys.resolve_dependencies (install_packages, remove_packages, extra_reqs) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.failed_dependencies: rctalk.error(f.faultString) sys.exit(1) else: raise
def execute(self, server, options_dict, non_option_args): if options_dict.has_key("strict"): all_users = map(lambda x:x[0], server.rcd.users.get_all()) failed = 0 for username in non_option_args: if not username in all_users: rctalk.warning("User '" + username + "' does not exist") failed = 1 if failed: rctalk.error("User deletion cancelled") for username in non_option_args: if not server.rcd.users.remove(username): rctalk.warning("Attempt to delete user '" + username + "' failed") else: rctalk.message("User '" + username + "' deleted.")
def execute(self, server, options_dict, non_option_args): if len(non_option_args) > 1: self.usage() sys.exit(1) if non_option_args: services = rcserviceutils.get_services(server) s = rcserviceutils.find_service(services, non_option_args[0]) if not s: rctalk.error("No service matches '%s'" % non_option_args[0]) sys.exit(1) rcchannelutils.refresh_channels(server, s["id"]) else: rcchannelutils.refresh_channels(server)
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1 or len(non_option_args) > 2: self.usage() sys.exit(1) services = rcserviceutils.get_services(server) service = rcserviceutils.find_service(services, non_option_args[0]) if not service: rctalk.error("No service matches '%s'" % non_option_args[0]) sys.exit(1) verbose = options_dict.has_key("verbose") list_only = options_dict.has_key("list-only") select_str = "" show_list = 1 allow_select = not list_only if len(non_option_args) > 1: show_list = 0 allow_select = 0 select_str = non_option_args[1] current_host = service["url"] def sort_cb(a, b): aname = string.lower(a["name"]) bname = string.lower(b["name"]) # "All Animals Are Equal / But Some Are More Equal Than Others." if aname[:6] == "ximian": aname = "a" * 10 if bname[:6] == "ximian": bname = "a" * 10 return cmp(aname, bname) try: mirrors = server.rcd.service.get_mirrors(service["id"]) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.invalid_service: mirrors = None
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 execute(self, server, options_dict, non_option_args): if not non_option_args: self.usage() sys.exit(1) path = os.path.abspath(non_option_args[0]) path_base = os.path.basename(path) aliases = map(rcchannelutils.get_channel_alias, rcchannelutils.get_channels(server)) complain_about_collision = 0 alias = string.lower(path_base) if options_dict.has_key("alias"): alias = options_dict["alias"] complain_about_collision = 1 # Ensure we don't have an alias collision old_alias = alias count = 1 while alias in aliases: alias = "%s-%d" % (old_alias, count) count = count + 1 if old_alias != alias and complain_about_collision: rctalk.warning("Alias '%s' already in use. Using '%s' instead." % (old_alias, alias)) name = options_dict.get("name", path) if options_dict.has_key("recurse"): recursive = 1 else: recursive = 0 try: server.rcd.packsys.mount_directory(path, name, alias, recursive) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.invalid_service: rctalk.error(f.faultString) sys.exit(1) else: raise
def execute(self, server, options_dict, non_option_args): if not non_option_args: self.usage() sys.exit(1) if not server_has_patch_support (server): rctalk.error ("Current rcd daemon does not have patch support") sys.exit(1) if options_dict.has_key("allow-unsubscribed"): allow_unsub = 1 else: allow_unsub = 0 plist = [] for a in non_option_args: inform = 0 channel = None package = None plist = plist + find_patch(server, a, allow_unsub) if not plist: rctalk.message("--- No patches found ---") sys.exit(1) for p in plist: pinfo = server.rcd.you.patch_info(p) rctalk.message("") rctalk.message("Name: %s" % p['name']) rctalk.message("Version: %s" % p['version']) installed = "no" if p['installed']: installed = "yes" rctalk.message("Installed: %s" % installed) rctalk.message("Summary: %s" % pinfo['summary']) rctalk.message("Description:\n%s" % pinfo['description']) rctalk.message("")
def execute(self, server, options_dict, non_option_args): if not non_option_args: self.usage() sys.exit(1) if not server_has_patch_support(server): rctalk.error("Current rcd daemon does not have patch support") sys.exit(1) if options_dict.has_key("allow-unsubscribed"): allow_unsub = 1 else: allow_unsub = 0 plist = [] for a in non_option_args: inform = 0 channel = None package = None plist = plist + find_patch(server, a, allow_unsub) if not plist: rctalk.message("--- No patches found ---") sys.exit(1) for p in plist: pinfo = server.rcd.you.patch_info(p) rctalk.message("") rctalk.message("Name: %s" % p['name']) rctalk.message("Version: %s" % p['version']) installed = "no" if p['installed']: installed = "yes" rctalk.message("Installed: %s" % installed) rctalk.message("Summary: %s" % pinfo['summary']) rctalk.message("Description:\n%s" % pinfo['description']) rctalk.message("")
def execute(self, server, options_dict, non_option_args): min_importance = None if options_dict.has_key("importance"): if not rcpackageutils.update_importances.has_key( options_dict["importance"]): rctalk.error("Invalid importance: " + options_dict["importance"]) sys.exit(1) else: min_importance = rcpackageutils.update_importances[ options_dict["importance"]] update_list = rcpackageutils.get_updates(server, non_option_args) if min_importance != None: up = [] for u in update_list: # higher priorities have lower numbers... i know, i know... if u[1]["importance_num"] <= min_importance: up.append(u) else: up = update_list # x[1] is the package to be updated packages_to_install = map(lambda x: x[1], up) if not packages_to_install: rctalk.message("--- No packages to update ---") sys.exit(0) if not options_dict.has_key("download-only"): install_deps, remove_deps, dep_info = \ resolve_dependencies(server, packages_to_install, [], []) else: install_deps = [] remove_deps = [] self.transact(server, options_dict, packages_to_install, install_deps, [], remove_deps)
def execute(self, server, options_dict, non_option_args): if len(non_option_args) == 0: rctalk.error("No channel specified.") sys.exit(1) channel_name = non_option_args[0] channels = rcchannelutils.get_channels_by_name(server, channel_name) if not rcchannelutils.validate_channel_list(channel_name, channels): sys.exit(1) channel = channels[0] retval = server.rcd.packsys.unmount_directory(channel["id"]) if retval: rctalk.message("Unmounted channel '%s'" % channel["name"]) else: rctalk.error("Unmount of channel '%s' failed" % channel["name"])
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1: self.usage() sys.exit(1) services = rcserviceutils.get_services(server) for o in non_option_args: for s in services: if string.lower(s["url"]) == o: rctalk.error("Service '%s' already exists" % s["name"]) sys.exit(1) try: server.rcd.service.add(o) except ximian_xmlrpclib.Fault, f: rctalk.error(f.faultString) sys.exit(1) else: rctalk.message("Service '%s' successfully added." % o)
def execute(self, server, options_dict, non_option_args): min_importance = None if options_dict.has_key("importance"): if not rcpackageutils.update_importances.has_key(options_dict["importance"]): rctalk.error("Invalid importance: " + options_dict["importance"]) sys.exit(1) else: min_importance = rcpackageutils.update_importances[options_dict["importance"]] update_list = rcpackageutils.get_updates(server, non_option_args) if min_importance != None: up = [] for u in update_list: # higher priorities have lower numbers... i know, i know... if u[1]["importance_num"] <= min_importance: up.append(u) else: up = update_list # x[1] is the package to be updated packages_to_install = map(lambda x:x[1], up) if not packages_to_install: rctalk.message("--- No packages to update ---") sys.exit(0) if not options_dict.has_key("download-only"): install_deps, remove_deps, dep_info = \ resolve_dependencies(server, packages_to_install, [], []) else: install_deps = [] remove_deps = [] self.transact(server, options_dict, packages_to_install, install_deps, [], remove_deps)
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1: self.usage() sys.exit(1) services = rcserviceutils.get_services(server) for o in non_option_args: s = rcserviceutils.find_service(services, o) if not s: rctalk.error("No service matches '%s'" % o) sys.exit(1) try: server.rcd.service.remove(s["id"]) except ximian_xmlrpclib.Fault, f: if f.faultCode != rcfault.invalid_service: raise rctalk.error(f.faultString) else: rctalk.message("Service '%s' successfully removed." % s["name"])
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 2: self.usage() sys.exit(1) err_str = None success = 0 activation_info = {} activation_info["activation_code"] = non_option_args[0] activation_info["email"] = non_option_args[1] if options_dict.has_key("service"): services = rcserviceutils.get_services(server) s = rcserviceutils.find_service(services, options_dict["service"]) if not s: rctalk.error("No service matches '%s'" % options_dict["service"]) sys.exit(1) activation_info["service"] = s["id"] if options_dict.has_key("alias"): activation_info["alias"] = options_dict["alias"] try: server.rcd.service.activate(activation_info) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.cant_activate \ or f.faultCode == rcfault.invalid_service: err_str = f.faultString success = 0 else: raise
def execute(self, server, options_dict, non_option_args): users = map(lambda x:x[0], server.rcd.users.get_all()) valid_privs = map(string.lower, server.rcd.users.get_valid_privileges()) privs = [] if non_option_args: for p in non_option_args[1:]: if p and string.lower(p) in valid_privs: privs.append(string.lower(p)) else: rctalk.warning("Ignoring unrecognized privilege '"+p+"'") if non_option_args: username = non_option_args[0] else: print "New Username: "******"" if not username: rctalk.message("Exiting") sys.exit(0) if not re.compile("^\w+$").match(username): rctalk.error("Invalid user name") sys.exit(1) if username in users: rctalk.error("User '" + username + "' already exists.") sys.exit(1) passwd = get_password() if not passwd: rctalk.message("Exiting.") sys.exit(0) if not privs and "view" in valid_privs: privs = ["view"] privs = get_privileges(privs, valid_privs) privs_str = string.join(privs, ", ") rc = server.rcd.users.update(username, passwd, privs_str) rctalk.message("") if rc: rctalk.message("User '" + username + "' added.") else: rctalk.error("User '" + username + "' could not be added.")
def refresh_channels(server, service=None): stuff_to_poll = [] rctalk.message("Refreshing channel data") try: if service: stuff_to_poll = server.rcd.service.refresh(service) else: stuff_to_poll = server.rcd.service.refresh() except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.locked: rctalk.error("The daemon is busy processing another " "request.") rctalk.error("Please try again shortly.") sys.exit(1) elif f.faultCode == rcfault.cant_refresh: rctalk.error("Error trying to refresh: " + f.faultString) sys.exit(1) elif f.faultCode == rcfault.invalid_service: rctalk.error("No service matches '%s'" % service) sys.exit(1) else: raise
def register(constructor): obj = constructor() name = obj.name() aliases = obj.aliases() hidden = obj.is_hidden() basic = obj.is_basic() description = obj.description_short() or "<No Description Available>" category = obj.category() if command_dict.has_key(name): rctalk.error("Command name collision: '" + name + "'") else: command_dict[name] = (description, constructor, aliases, hidden, basic, category) for a in aliases: al = string.lower(a) if command_dict.has_key(al): rctalk.error("Command/alias collision: '" + a + "'") elif alias_dict.has_key(al): rctalk.error("Alias collision: '" + a + "'") else: alias_dict[al] = name
def execute(self, server, options_dict, non_option_args): if not server_has_patch_support (server): rctalk.error ("Current rcd daemon does not have patch support") sys.exit(1) patches = [] patch_table = [] multiple_channels = 1 query = [] clist = [] for a in non_option_args: cl = rcchannelutils.get_channels_by_name(server, a) if rcchannelutils.validate_channel_list(a, cl): clist = clist + cl if non_option_args and not clist: sys.exit(1) query = map(lambda c:["channel", "=", c["id"]], clist) if len(clist) > 1: query.insert(0, ["", "begin-or", ""]) query.append(["", "end-or", ""]) if options_dict.has_key("installed-only"): query.append(["name-installed", "=", "true"]) elif options_dict.has_key("uninstalled-only"): query.append(["patch-installed", "=", "false"]) if len(clist) == 1: multiple_channels = 0 patches = server.rcd.you.search (query) if options_dict.has_key("sort-by-channel"): for p in patches: rcchannelutils.add_channel_name(server, p) patches.sort(lambda x,y:cmp(string.lower(x["channel_name"]), string.lower(y["channel_name"])) \ or cmp(string.lower(x["name"]), string.lower(y["name"]))) else: patches.sort(lambda x,y:cmp(string.lower(x["name"]),string.lower(y["name"]))) if multiple_channels: keys = ["installed", "channel", "name", "version", "product"] headers = ["S", "Channel", "Name", "Version", "Product"] else: keys = ["installed", "name", "version", "product"] headers = ["S", "Name", "Version", "Product"] # If we're getting all of the packages available to us, filter out # ones in the "hidden" channels, like the system packages channel. patches = rcpackageutils.filter_visible_channels(server, patches) for p in patches: row = rcformat.package_to_row(server, p, options_dict.has_key("no-abbrev"), keys) patch_table.append(row) if patch_table: rcformat.tabular(headers, patch_table) else: rctalk.message("--- No Patches found ---")
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1: self.usage() sys.exit(1) match = {} # Split non-option args on whitespace, reassembling the # pieces into a new list. non_option_args = reduce(lambda x,y: x+y, map(string.split, non_option_args)) if len(non_option_args) == 3: name, relation, version = non_option_args if "?" in name or "*" in name: rctalk.warning("Wildcards are not allowed when specifying versioned locks.") sys.exit(1) valid_relations = ("=", "<", ">", "<=", ">=") if relation not in valid_relations: valid_str = string.join(map(lambda x: "'%s'" % x, valid_relations), ", ") rctalk.warning("'%s' is not a valid relation." % relation) rctalk.warning("Valid relations are: %s" % valid_str) sys.exit(1) match["dep"] = {"name": name, "relation":relation, "version_str":version } elif len(non_option_args) == 1: glob = non_option_args[0] # FIXME: It would be nice to verify that the incoming glob # is valid. (It probably shouldn't contain whitespace, shouldn't # be the empty string, etc.) match["glob"] = glob elif len(non_option_args) != 0: rctalk.error("Unrecognized input \"%s\"" % string.join(non_option_args, " ")) sys.exit(1) if options_dict.has_key("channel"): cname = options_dict["channel"] clist = rcchannelutils.get_channels_by_name(server, cname) if not rcchannelutils.validate_channel_list(cname, clist): sys.exit(1) match["channel"] = clist[0]["id"] if options_dict.has_key("name"): # FIXME: It would be nice to verify that the incoming glob # is valid. (It probably shouldn't contain whitespace, shouldn't # be the empty string, etc.) match["glob"] = options_dict["name"] if options_dict.has_key("importance"): num = rcformat.importance_str_to_num(options_dict["importance"]) if num < 0: rctalk.error("'%s' is not a valid importance level" % options_dict["importance"]) sys.exit(1) # We want to match (i.e. lock) all packages below the given # importance. Remember, in a match the opposite of >= is # <=, not <. (Maybe this is broken, but it seems pretty # unnecessary to offer the full selection of comparison # operators.) match["importance_num"] = num match["importance_gteq"] = 0 # FIXME: validate that the match isn't empty, etc. server.rcd.packsys.add_lock(match) rctalk.message("--- Added Lock ---") display_match(server, match)
def execute(self, server, options_dict, non_option_args): if not server_has_patch_support(server): rctalk.error("Current rcd daemon does not have patch support") sys.exit(1) patches = [] patch_table = [] multiple_channels = 1 query = [] clist = [] for a in non_option_args: cl = rcchannelutils.get_channels_by_name(server, a) if rcchannelutils.validate_channel_list(a, cl): clist = clist + cl if non_option_args and not clist: sys.exit(1) query = map(lambda c: ["channel", "=", c["id"]], clist) if len(clist) > 1: query.insert(0, ["", "begin-or", ""]) query.append(["", "end-or", ""]) if options_dict.has_key("installed-only"): query.append(["name-installed", "=", "true"]) elif options_dict.has_key("uninstalled-only"): query.append(["patch-installed", "=", "false"]) if len(clist) == 1: multiple_channels = 0 patches = server.rcd.you.search(query) if options_dict.has_key("sort-by-channel"): for p in patches: rcchannelutils.add_channel_name(server, p) patches.sort(lambda x,y:cmp(string.lower(x["channel_name"]), string.lower(y["channel_name"])) \ or cmp(string.lower(x["name"]), string.lower(y["name"]))) else: patches.sort(lambda x, y: cmp(string.lower(x["name"]), string.lower(y["name"]))) if multiple_channels: keys = ["installed", "channel", "name", "version", "product"] headers = ["S", "Channel", "Name", "Version", "Product"] else: keys = ["installed", "name", "version", "product"] headers = ["S", "Name", "Version", "Product"] # If we're getting all of the packages available to us, filter out # ones in the "hidden" channels, like the system packages channel. patches = rcpackageutils.filter_visible_channels(server, patches) for p in patches: row = rcformat.package_to_row(server, p, options_dict.has_key("no-abbrev"), keys) patch_table.append(row) if patch_table: rcformat.tabular(headers, patch_table) else: rctalk.message("--- No Patches found ---")