def dep_table(server, pairs, dep_name, by_channel=0, no_abbrev=0): if not pairs: rctalk.message("--- No matches ---") sys.exit(0) table = [] if no_abbrev: evr_fn = rcformat.evr_to_str else: evr_fn = rcformat.evr_to_abbrev_str pkg_dict = {} for pkg, dep in pairs: if pkg["installed"]: installed = "i" else: installed = "" pkg_name = pkg["name"] pkg_evr = evr_fn(pkg) if pkg.has_key("channel_guess"): id = pkg["channel_guess"] else: id = pkg["channel"] channel = rcchannelutils.channel_id_to_name(server, id) if not no_abbrev: channel = rcformat.abbrev_channel_name(channel) if not channel: channel = "(none)" if dep.has_key("relation"): dep_str = dep["relation"] + " " + evr_fn(dep) else: dep_str = evr_fn(dep) # We check pkg_dict to avoid duplicates between the installed # and in-channel version of packages. key = pkg_name + "||" + pkg_evr + "||" + dep_str if not pkg_dict.has_key(key): row = [installed, channel, pkg_name, pkg_evr, dep_str] table.append(row) pkg_dict[key] = 1 if by_channel: sort_fn = lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or \ cmp(string.lower(x[2]), string.lower(y[2])) else: sort_fn = lambda x,y:cmp(string.lower(x[2]), string.lower(y[2])) or \ cmp(string.lower(x[1]), string.lower(y[1])) table.sort(sort_fn) rcformat.tabular( ["S", "Channel", "Package", "Version", dep_name + " Version"], table)
def get_password(msg="New Password"): p1, p2 = "foo", "bar" while p1 != p2: try: p1 = getpass.getpass("%s: " % msg) except KeyboardInterrupt: p1 = "" if not p1: return "" try: p2 = getpass.getpass("Confirm %s: " % msg) except KeyboardInterrupt: p2 = "" if not p2: return "" if p1 != p2: rctalk.message("Passwords do not match. Please try again.") rctalk.message("Passwords match.") return rcutil.md5ify_password(p1)
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 columned_output(self, server, services, show_ids=0): table = [] row_no = 1 for serv in services: if serv.has_key("is_invisible") and serv["is_invisible"]: continue if serv.has_key("name"): name = serv["name"] else: name = "(No name available)" if show_ids: row = [str(row_no), serv["id"], serv["url"], name] else: row = [str(row_no), serv["url"], name] table.append(row) row_no = row_no + 1 if table: if show_ids: headers = ["#", "Service ID", "Service URI", "Name"] else: headers = ["#", "Service URI", "Name"] rcformat.tabular(headers, table) else: rctalk.message("*** No services are mounted ***")
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 opt_table(table): opt_list = [] for r in table: opt = "--" + r[1] if r[0]: opt = "-" + r[0] + ", " + opt if r[2]: opt = opt + "=<" + r[2] + ">" opt_list.append([opt + " ", r[3]]) # By appending [0,0], we insure that this will work even if # opt_list is empty (which it never should be) max_len = apply(max, map(lambda x:len(x[0]), opt_list) + [0,0]) for opt, desc_str in opt_list: if 79 - max_len > 10: desc = linebreak(desc_str, 79 - max_len) else: desc = [desc_str] desc_first = desc.pop(0) rctalk.message(string.ljust(opt, max_len) + desc_first) for d in desc: rctalk.message(" " * max_len + d)
def display_match(server, match, extra_head=[], extra_tail=[]): table = [] if match.has_key("glob"): table.append(("Name Pattern:", match["glob"])) if match.has_key("dep"): # looks like a RCPackageDep dep = match["dep"] table.append(("Name:", dep["name"])) vers = rcformat.rel_str(dep) + rcformat.evr_to_str(dep) table.append(("Version:", vers)) if match.has_key("channel"): str = rcchannelutils.channel_id_to_name(server, match["channel"]) if not str: return 0 table.append(("Channel:", str)) if match.has_key("importance_num"): str = rcformat.importance_num_to_str(match["importance_num"]) op = (match["importance_gteq"] and "<=") or ">=" table.append(("Importance:", "%s %s" % (op, str))) table = extra_head + table + extra_tail maxlen = apply(max, map(lambda x:len(x[0]), table) + [0,]) for label, val in table: rctalk.message("%s%s %s" % (" " * (maxlen - len(label)), label, val)) return 1
def execute(self, server, options_dict, non_option_args): if options_dict.has_key("dry-run"): dry_run = 1 else: dry_run = 0 dlist = [] for d in non_option_args: dep = rcpackageutils.parse_dep_str(server, d) dups = filter(lambda x, d=dep:x["name"] == d["name"], dlist) if dups: rctalk.warning("Duplicate entry found: " + dups[0]["name"]) dlist.append(dep) install_deps, remove_deps, dep_info = \ resolve_dependencies(server, [], [], dlist) if not install_deps and not remove_deps: rctalk.message("Requirements are already met on the system. No " "packages need to be") rctalk.message("installed or removed.") sys.exit(0) self.transact(server, options_dict, [], install_deps, [], remove_deps)
def execute(self, server, options_dict, non_option_args): server.rcd.system.restart() if options_dict.has_key("no-wait"): sys.exit(0) rctalk.message("Waiting for daemon to restart...") is_down = 0 while 1: try: server.rcd.system.ping() except (IOError, socket.error), e: eno, str = e if eno == errno.ENOENT \ or eno == errno.ECONNREFUSED \ or eno == errno.ECONNRESET: is_down = 1 else: raise except ximian_xmlrpclib.ProtocolError, e: if e.errcode == -1: is_down = 1 else: raise
def log_entries_to_table(entries): log_table = [] for x in entries: pkg_initial = "-" if x.has_key("pkg_initial"): pkg_initial = rcformat.evr_to_str(x["pkg_initial"]) pkg_final = "-" if x.has_key("pkg_final"): pkg_final = rcformat.evr_to_str(x["pkg_final"]) if x.has_key("pkg_final"): pkg = x["pkg_final"] else: pkg = x["pkg_initial"] log_table.append([x["time_str"], x["host"], x["user"], x["action"], pkg["name"], pkg_initial, pkg_final]) if log_table: rcformat.tabular(["Time", "Host", "User", "Action", "Package", "Initial", "Final"], log_table) else: rctalk.message("No matches.")
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 options_dict.has_key("dry-run"): dry_run = 1 else: dry_run = 0 dlist = [] for d in non_option_args: dep = rcpackageutils.parse_dep_str(server, d) dups = filter(lambda x, d=dep: x["name"] == d["name"], dlist) if dups: rctalk.warning("Duplicate entry found: " + dups[0]["name"]) dlist.append(dep) install_deps, remove_deps, dep_info = \ resolve_dependencies(server, [], [], dlist) if not install_deps and not remove_deps: rctalk.message("Requirements are already met on the system. No " "packages need to be") rctalk.message("installed or removed.") sys.exit(0) self.transact(server, options_dict, [], install_deps, [], remove_deps)
def opt_table(table): opt_list = [] for r in table: opt = "--" + r[1] if r[0]: opt = "-" + r[0] + ", " + opt if r[2]: opt = opt + "=<" + r[2] + ">" opt_list.append([opt + " ", r[3]]) # By appending [0,0], we insure that this will work even if # opt_list is empty (which it never should be) max_len = apply(max, map(lambda x: len(x[0]), opt_list) + [0, 0]) for opt, desc_str in opt_list: if 79 - max_len > 10: desc = linebreak(desc_str, 79 - max_len) else: desc = [desc_str] desc_first = desc.pop(0) rctalk.message(string.ljust(opt, max_len) + desc_first) for d in desc: rctalk.message(" " * max_len + d)
def find_remote_package(server, package): try: import urllib except ImportError: return None # Figure out if the protocol is valid. Copied mostly from urllib. proto, rest = urllib.splittype(package) if not proto: return None name = "open_" + proto if "-" in name: # replace - with _ name = string.join(string.split(name, "-"), "_") if not hasattr(urllib.URLopener, name): return None rctalk.message("Fetching %s..." % package) u = urllib.URLopener().open(package) pdata = ximian_xmlrpclib.Binary(u.read()) try: p = server.rcd.packsys.query_file(pdata) except ximian_xmlrpclib.Fault,f : if f.faultCode == rcfault.package_not_found: return None elif f.faultCode == rcfault.invalid_package_file: rctalk.warning ("'" + package + "' is not a valid package file") return None 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 display_match(server, match, extra_head=[], extra_tail=[]): table = [] if match.has_key("glob"): table.append(("Name Pattern:", match["glob"])) if match.has_key("dep"): # looks like a RCPackageDep dep = match["dep"] table.append(("Name:", dep["name"])) vers = rcformat.rel_str(dep) + rcformat.evr_to_str(dep) table.append(("Version:", vers)) if match.has_key("channel"): str = rcchannelutils.channel_id_to_name(server, match["channel"]) if not str: return 0 table.append(("Channel:", str)) if match.has_key("importance_num"): str = rcformat.importance_num_to_str(match["importance_num"]) op = (match["importance_gteq"] and "<=") or ">=" table.append(("Importance:", "%s %s" % (op, str))) table = extra_head + table + extra_tail maxlen = apply(max, map(lambda x: len(x[0]), table) + [ 0, ]) for label, val in table: rctalk.message("%s%s %s" % (" " * (maxlen - len(label)), label, val)) return 1
def log_entries_to_table(entries): log_table = [] for x in entries: pkg_initial = "-" if x.has_key("pkg_initial"): pkg_initial = rcformat.evr_to_str(x["pkg_initial"]) pkg_final = "-" if x.has_key("pkg_final"): pkg_final = rcformat.evr_to_str(x["pkg_final"]) if x.has_key("pkg_final"): pkg = x["pkg_final"] else: pkg = x["pkg_initial"] log_table.append([ x["time_str"], x["host"], x["user"], x["action"], pkg["name"], pkg_initial, pkg_final ]) if log_table: rcformat.tabular( ["Time", "Host", "User", "Action", "Package", "Initial", "Final"], log_table) else: rctalk.message("No matches.")
def dep_table(server, pairs, dep_name, by_channel = 0, no_abbrev = 0): if not pairs: rctalk.message("--- No matches ---") sys.exit(0) table = [] if no_abbrev: evr_fn = rcformat.evr_to_str else: evr_fn = rcformat.evr_to_abbrev_str pkg_dict = {} for pkg, dep in pairs: if pkg["installed"]: installed = "i" else: installed = "" pkg_name = pkg["name"] pkg_evr = evr_fn(pkg) if pkg.has_key("channel_guess"): id = pkg["channel_guess"] else: id = pkg["channel"] channel = rcchannelutils.channel_id_to_name(server, id) if not no_abbrev: channel = rcformat.abbrev_channel_name(channel) if not channel: channel = "(none)" if dep.has_key("relation"): dep_str = dep["relation"] + " " + evr_fn(dep) else: dep_str = evr_fn(dep) # We check pkg_dict to avoid duplicates between the installed # and in-channel version of packages. key = pkg_name + "||" + pkg_evr + "||" + dep_str if not pkg_dict.has_key(key): row = [installed, channel, pkg_name, pkg_evr, dep_str] table.append(row) pkg_dict[key] = 1 if by_channel: sort_fn = lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or \ cmp(string.lower(x[2]), string.lower(y[2])) else: sort_fn = lambda x,y:cmp(string.lower(x[2]), string.lower(y[2])) or \ cmp(string.lower(x[1]), string.lower(y[1])) table.sort(sort_fn) rcformat.tabular(["S", "Channel", "Package", "Version", dep_name + " Version"], table)
def exploded_updates_table(server, update_list, no_abbrev): channel_name_dict = {} for update_item in update_list: ch = update_item[1]["channel"] if not channel_name_dict.has_key(ch): channel_name_dict[ch] = rcchannelutils.channel_id_to_name( server, ch) update_list.sort(lambda x,y,cnd=channel_name_dict:\ cmp(string.lower(cnd[x[1]["channel"]]), string.lower(cnd[y[1]["channel"]])) \ or cmp(x[1]["importance_num"], y[1]["importance_num"]) \ or cmp(string.lower(x[1]["name"]), string.lower(y[1]["name"]))) if no_abbrev: evr_fn = rcformat.evr_to_str else: evr_fn = rcformat.evr_to_abbrev_str this_channel_table = [] this_channel_id = -1 # An ugly hack update_list.append(("", {"channel": "last"}, "")) for update_item in update_list: old_pkg, new_pkg, descriptions = update_item chan_id = new_pkg["channel"] if chan_id != this_channel_id or chan_id == "last": if this_channel_table: rctalk.message("") channel_name = channel_name_dict[this_channel_id] rctalk.message("Updates for channel '" + channel_name + "'") rcformat.tabular( ["Urg", "Name", "Current Version", "Update Version"], this_channel_table) if chan_id == "last": break this_channel_table = [] this_channel_id = chan_id urgency = "?" if new_pkg.has_key("importance_str"): urgency = new_pkg["importance_str"] if not no_abbrev: urgency = rcformat.abbrev_importance(urgency) old_ver = evr_fn(old_pkg) new_ver = evr_fn(new_pkg) this_channel_table.append([urgency, new_pkg["name"], old_ver, new_ver])
def execute(self, server, options_dict, non_option_args): install_deps, remove_deps, dep_info = verify_dependencies(server) if not install_deps and not remove_deps: rctalk.message("System dependency tree verified successfully.") sys.exit(0) self.transact(server, options_dict, [], install_deps, [], remove_deps)
def exploded_updates_table(server, update_list, no_abbrev): channel_name_dict = {} for update_item in update_list: ch = update_item[1]["channel"] if not channel_name_dict.has_key(ch): channel_name_dict[ch] = rcchannelutils.channel_id_to_name(server, ch) update_list.sort(lambda x,y,cnd=channel_name_dict:\ cmp(string.lower(cnd[x[1]["channel"]]), string.lower(cnd[y[1]["channel"]])) \ or cmp(x[1]["importance_num"], y[1]["importance_num"]) \ or cmp(string.lower(x[1]["name"]), string.lower(y[1]["name"]))) if no_abbrev: evr_fn = rcformat.evr_to_str else: evr_fn = rcformat.evr_to_abbrev_str this_channel_table = [] this_channel_id = -1 # An ugly hack update_list.append(("", {"channel":"last"}, "")) for update_item in update_list: old_pkg, new_pkg, descriptions = update_item chan_id = new_pkg["channel"] if chan_id != this_channel_id or chan_id == "last": if this_channel_table: rctalk.message("") channel_name = channel_name_dict[this_channel_id] rctalk.message("Updates for channel '" + channel_name + "'") rcformat.tabular(["Urg", "Name", "Current Version", "Update Version"], this_channel_table) if chan_id == "last": break this_channel_table = [] this_channel_id = chan_id urgency = "?" if new_pkg.has_key("importance_str"): urgency = new_pkg["importance_str"] if not no_abbrev: urgency = rcformat.abbrev_importance(urgency) old_ver = evr_fn(old_pkg) new_ver = evr_fn(new_pkg) this_channel_table.append([urgency, new_pkg["name"], old_ver, new_ver])
def find_package(server, str, allow_unsub, allow_system=1): channel = None package = None # Check if the string is a file on the local filesystem. p = find_local_package(server, str) if p: return [p] # Check if the string is a supported URL p = find_remote_package(server, str) if p: return [p] # Okay, try to split the string into "channel:package" channel_id, package = split_channel_and_name(server, str) # Channel is set, so just get the package(s) from the channel. if channel_id: plist = find_package_in_channel(server, channel_id, package, allow_unsub) return plist # Okay, that didn't work. First try to get the package from the list # of system packages. After that, try to get the latest available # package. plist = [] if allow_system: plist = find_package_on_system(server, package) if plist: quiet = 1 else: quiet = 0 new_plist = find_latest_package(server, package, allow_unsub, quiet) # Filter out packages already on the system, so we don't get both # the installed version of a package and the newest available # version. for p in new_plist: if not filter(lambda x, my_p=p:x["name"] == my_p["name"], plist): rctalk.message("Using " + p["name"] + " " + rcformat.evr_to_str(p) + " from the '" + rcchannelutils.channel_id_to_name(server, p["channel"]) + "' channel") plist.append(p) return plist
def execute(self, server, options_dict, non_option_args): locks = server.rcd.packsys.get_locks() to_delete = [] indices = [] for x in non_option_args: success = 1 try: i = int(x) except: success = 0 if success: if 0 <= i - 1 < len(locks): indices.append(i) to_delete.append(locks[i - 1]) else: success = 0 if not success: rctalk.warning("Ignoring invalid lock number '%s'" % x) if not to_delete: rctalk.warning("No valid lock numbers specified.") sys.exit(1) table = locks_to_table(server, to_delete, 1) for row, i in map(lambda x, y: (x, y), table, indices): row.insert(0, str(i)) rcformat.tabular(["#", "Pattern", "Channel", "Importance"], table) if not options_dict.has_key("no-confirmation"): rctalk.message("") if len(to_delete) == 1: msg = "this lock" else: msg = "these locks" confirm = rctalk.prompt("Delete %s? [y/N]" % msg) if not confirm or not string.lower(confirm[0]) == "y": rctalk.message("Cancelled.") sys.exit(0) failures = [] for l, i in map(lambda x, y: (x, y), to_delete, indices): retval = server.rcd.packsys.remove_lock(l) if not retval: failures.append(i) if failures: rctalk.warning("Unable to remove lock%s %s", (len(failures) > 1 and "s") or "", string.join(map(str, failures), ", ")) sys.exit(1)
def execute(self, server, options_dict, non_option_args): locks = server.rcd.packsys.get_locks() to_delete = [] indices = [] for x in non_option_args: success = 1 try: i = int(x) except: success = 0 if success: if 0 <= i-1 < len(locks): indices.append(i) to_delete.append(locks[i-1]) else: success = 0 if not success: rctalk.warning("Ignoring invalid lock number '%s'" % x) if not to_delete: rctalk.warning("No valid lock numbers specified.") sys.exit(1) table = locks_to_table(server, to_delete, 1) for row, i in map(lambda x, y:(x, y), table, indices): row.insert(0, str(i)) rcformat.tabular(["#", "Pattern", "Channel", "Importance"], table) if not options_dict.has_key("no-confirmation"): rctalk.message("") if len(to_delete) == 1: msg = "this lock" else: msg = "these locks" confirm = rctalk.prompt("Delete %s? [y/N]" % msg) if not confirm or not string.lower(confirm[0]) == "y": rctalk.message("Cancelled.") sys.exit(0) failures = [] for l, i in map(lambda x, y: (x, y), to_delete, indices): retval = server.rcd.packsys.remove_lock(l) if not retval: failures.append(i) if failures: rctalk.warning("Unable to remove lock%s %s", (len(failures) > 1 and "s") or "", string.join(map(str, failures), ", ")) sys.exit(1)
def execute(self, server, options_dict, non_option_args): if len(non_option_args) < 1: self.usage() sys.exit(1) plist = [] for a in non_option_args: plist = plist + rcpackageutils.find_package(server, a, 1) if not plist: rctalk.message("--- No packages found ---") sys.exit(1) for pkg in plist: dep_info = server.rcd.packsys.package_dependency_info(pkg) if not dep_info.has_key("provides"): continue rctalk.message("--- %s %s ---" % (pkg["name"], rcformat.evr_to_str(pkg))) for dep in dep_info["provides"]: rctalk.message(rcformat.dep_to_str(dep)) rctalk.message("")
def confirm(self, options_dict, removals): if not options_dict.has_key("no-confirmation"): confirm = rctalk.prompt("Do you want to continue? [y/N]") if not confirm or not (confirm[0] == "y" or confirm[0] == "Y"): rctalk.message("Cancelled.") sys.exit(0) allow_remove = self.unattended_removals() \ or options_dict.has_key("allow-removals") if removals \ and options_dict.has_key("no-confirmation") \ and not allow_remove: rctalk.warning("Removals are required. Use the -r option or " "confirm interactively.") sys.exit(1)
def find_patch(server, str, allow_unsub, allow_system=1): channel = None patch = None # Try to split the string into "channel:package" channel_id, patch = rcpackageutils.split_channel_and_name(server, str) # Channel is set, so just get the patch(es) from the channel. if channel_id: plist = find_patch_in_channel(server, channel_id, patch, allow_unsub) return plist # Okay, that didn't work. First try to get the patch from the list # of system patches. plist = [] if allow_system: plist = find_patch_on_system(server, patch) if plist: quiet = 1 else: quiet = 0 new_plist = find_latest_patch(server, patch, allow_unsub, quiet) # Filter out patches already on the system, so we don't get both # the installed version of a patch and the newest available # version. for p in new_plist: if not filter(lambda x, my_p=p:x["name"] == my_p["name"], plist): rctalk.message("Using " + p["name"] + " " + rcformat.evr_to_str(p) + " from the '" + rcchannelutils.channel_id_to_name(server, p["channel"]) + "' channel") plist.append(p) return plist
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 validate_channel_list(name, chan_list): if len(chan_list) == 0: rctalk.warning("Invalid channel: '" + name + "'") return 0 elif len(chan_list) > 1: rctalk.warning("Ambiguous channel: '" + name + "' matches") for c in chan_list: rctalk.warning(" " + c["name"]) return 0 cname = chan_list[0]["name"] if string.lower(name) != string.lower(cname) \ and name != chan_list[0]["id"]: if not rctalk.be_terse: rctalk.message("'" + name + "' matches '" + cname + "'") return 1
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): 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 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): danglers = server.rcd.packsys.find_dangling_requires() if not danglers: rctalk.message("No dangling requires found.") sys.exit(0) table = [] for d in danglers: pkg = d[0]["name"] cid = d[0].get("channel", d[0].get("channel_guess", 0)) channel = rcchannelutils.channel_id_to_name(server, cid) if not channel: channel = "(none)" for r in d[1:]: table.append([pkg, channel, rcformat.dep_to_str(r)]) pkg = "" channel = "" rcformat.tabular(["Package", "Channel", "Requirement"], table)
class PackageFileListCmd(rccommand.RCCommand): def name(self): return "file-list" def is_basic(self): return 1 def aliases(self): return ["fl"] def category(self): return "package" def arguments(self): return "<package or file>" def description_short(self): return "List files within a package" 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 if not file_list: rctalk.message("--- No files available ---") for f in file_list: print f
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 log_entries_to_quick_table(entries): log_table = [] for item in entries: date_str = time.strftime("%Y-%m-%d", time.localtime(item["timestamp"])) if item.has_key("pkg_final"): pkg = item["pkg_final"] else: pkg = item["pkg_initial"] log_table.append([date_str, item["action"], pkg["name"], rcformat.evr_to_abbrev_str(pkg)]) if log_table: rcformat.tabular(["Date", "Action", "Package", "Version"], log_table) else: rctalk.message("No matches.")
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 find_patch(server, str, allow_unsub, allow_system=1): channel = None patch = None # Try to split the string into "channel:package" channel_id, patch = rcpackageutils.split_channel_and_name(server, str) # Channel is set, so just get the patch(es) from the channel. if channel_id: plist = find_patch_in_channel(server, channel_id, patch, allow_unsub) return plist # Okay, that didn't work. First try to get the patch from the list # of system patches. plist = [] if allow_system: plist = find_patch_on_system(server, patch) if plist: quiet = 1 else: quiet = 0 new_plist = find_latest_patch(server, patch, allow_unsub, quiet) # Filter out patches already on the system, so we don't get both # the installed version of a patch and the newest available # version. for p in new_plist: if not filter(lambda x, my_p=p: x["name"] == my_p["name"], plist): rctalk.message( "Using " + p["name"] + " " + rcformat.evr_to_str(p) + " from the '" + rcchannelutils.channel_id_to_name(server, p["channel"]) + "' channel") plist.append(p) return plist
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 format_dependencies(server, dep_list): dep_list.sort(lambda x,y:cmp(string.lower(extract_package(x)["name"]), string.lower(extract_package(y)["name"]))) dlist = [] for d in dep_list: p = extract_package(d) c = rcchannelutils.channel_id_to_name(server, p["channel"]) if c: c = "(" + c + ")" else: c = "" rctalk.message(" " + p["name"] + " " + rcformat.evr_to_str(p) + " " + c) if d.has_key("details"): map(lambda x:rctalk.message(" " + x), d["details"]) rctalk.message("")
def format_dependencies(server, dep_list): dep_list.sort(lambda x, y: cmp(string.lower(extract_package(x)["name"]), string.lower(extract_package(y)["name"]))) dlist = [] for d in dep_list: p = extract_package(d) c = rcchannelutils.channel_id_to_name(server, p["channel"]) if c: c = "(" + c + ")" else: c = "" rctalk.message(" " + p["name"] + " " + rcformat.evr_to_str(p) + " " + c) if d.has_key("details"): map(lambda x: rctalk.message(" " + x), d["details"]) rctalk.message("")
class RecurringCmd(rccommand.RCCommand): def name(self): return "recurring" def aliases(self): return ["rec"] def description_short(self): return "List information about recurring events" def category(self): return "system" 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 items.sort(lambda x, y: cmp(x["when"], y["when"])) table = [] for rec in items: if rec["when_delta"] > 0: when_delta = rcformat.seconds_to_str(rec["when_delta"]) else: when_delta = "running" next_str = "%s (%s)" % (rec["when_str"], when_delta) if rec.has_key("prev_str"): prev_str = "%s (%s)" % (rec["prev_str"], rcformat.seconds_to_str( rec["prev_delta"])) else: prev_str = "" row = [] row.append(rec["label"]) row.append(str(rec["count"])) row.append(next_str) row.append(prev_str) table.append(row) if table: rcformat.tabular(["Label", "#", "Next", "Previous"], table) else: rctalk.message("*** No recurring events are scheduled. ***")
class InstallYouPatchCmd(rccommand.RCCommand): def name(self): return "patch-install" def aliases(self): return ["pin"] def description_short(self): return "Install YOU patches" def category(self): return "YOU patches" def arguments(self): return "<patch-name> ..." def local_opt_table(self): return [ [ "u", "allow-unsubscribed", "", "Include unsubscribed channels when searching for software" ], [ "d", "download-only", "", "Only download packages, don't install them" ], [ "", "entire-channel", "", "Install all of the packages in the channels specified on the command line" ] ] def check_licenses(self, server, patches): try: licenses = server.rcd.you.licenses(patches) except ximian_xmlrpclib.Fault, f: if f.faultCode == rcfault.undefined_method: return else: raise if licenses: if len(licenses) > 1: lstr = "licenses" else: lstr = "license" rctalk.message("") rctalk.message("You must agree to the following %s before " "installing this software:" % lstr) rctalk.message("") for l in licenses: rctalk.message(string.join(rcformat.linebreak(l, 72), "\n")) rctalk.message("") confirm = rctalk.prompt("Do you agree to the above " "%s? [y/N]" % lstr) if not confirm or not (confirm[0] == "y" or confirm[0] == "Y"): rctalk.message("Cancelled.") sys.exit(0)
def log_entries_to_quick_table(entries): log_table = [] for item in entries: date_str = time.strftime("%Y-%m-%d", time.localtime(item["timestamp"])) if item.has_key("pkg_final"): pkg = item["pkg_final"] else: pkg = item["pkg_initial"] log_table.append([ date_str, item["action"], pkg["name"], rcformat.evr_to_abbrev_str(pkg) ]) if log_table: rcformat.tabular(["Date", "Action", "Package", "Version"], log_table) else: rctalk.message("No matches.")
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"])