def lock_to_table_row(server, lock, no_abbrev): name = "(any)" channel = "(any)" importance = "(any)" # A match should have a glob or a dep, never both. if lock.has_key("glob"): name = lock["glob"] if lock.has_key("dep"): name = rcformat.dep_to_str(lock["dep"]) if lock.has_key("channel"): channel = rcchannelutils.channel_id_to_name(server, lock["channel"]) if not channel: return None if not no_abbrev: channel = rcformat.abbrev_channel_name(channel) if lock.has_key("importance_num"): imp = rcformat.importance_num_to_str(lock["importance_num"]) op = (lock["importance_gteq"] and "<=") or ">=" importance = op + " " + imp return [name, channel, importance]
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 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 execute(self, server, options_dict, non_option_args): no_abbrev = options_dict.has_key("no-abbrev") update_list = rcpackageutils.get_updates(server, []) if not update_list: rctalk.message("There are no available updates at this time.") sys.exit(0) count = len(update_list) necessary_count = 0 urgent_count = 0 seen_channels = {} seen_importance = {} tally = {} tally_by_urgency = {} for update_item in update_list: old_pkg, new_pkg, descriptions = update_item imp = new_pkg["importance_str"] if imp == "necessary": necessary_count = necessary_count + 1 if imp == "urgent": urgent_count = urgent_count + 1 ch = rcchannelutils.channel_id_to_name(server, new_pkg["channel"]) seen_channels[ch] = 1 seen_importance[imp] = new_pkg["importance_num"] key = ch + "||" + imp if tally.has_key(key): tally[key] = tally[key] + 1 else: tally[key] = 1 if tally_by_urgency.has_key(imp): tally_by_urgency[imp] = tally_by_urgency[imp] + 1 else: tally_by_urgency[imp] = 1 rctalk.message("") rctalk.message("There %s %d update%s available at this time." \ % ((count != 1 and "are") or "is", count, (count != 1 and "") or "s")) if necessary_count: rctalk.message("%d update%s marked as 'necessary'." \ % (necessary_count, (necessary_count != 1 and "s are") or " is")) if urgent_count: rctalk.message("%d update%s marked as 'urgent'." \ % (urgent_count, (urgent_count != 1 and "s are") or " is")) rctalk.message("") channels = seen_channels.keys() channels.sort(lambda x,y:cmp(string.lower(x), string.lower(y))) importances = seen_importance.keys() importances.sort(lambda x,y,f=seen_importance:cmp(f[x], f[y])) header = ["Channel"] if no_abbrev or len(importances) <= 4: header = header + importances else: header = header + map(rcformat.abbrev_importance, importances) header = header + ["total"] table = [] for ch in channels: if no_abbrev: row = [ch] else: row = [rcformat.abbrev_channel_name(ch)] row_count = 0 for imp in importances: key = ch + "||" + imp if tally.has_key(key): row.append(string.rjust(str(tally[key]), 3)) row_count = row_count + tally[key] else: row.append("") if count: row.append(string.rjust(str(row_count), 3)) else: row.append("") table.append(row) row = ["total"] for imp in importances: row.append(string.rjust(str(tally_by_urgency[imp]), 3)) row.append(string.rjust(str(count), 3)) table.append(row) rcformat.tabular(header, table) rctalk.message("")
def execute(self, server, options_dict, non_option_args): no_abbrev = options_dict.has_key("no-abbrev") update_list = rcpackageutils.get_updates(server, []) if not update_list: rctalk.message("There are no available updates at this time.") sys.exit(0) count = len(update_list) necessary_count = 0 urgent_count = 0 seen_channels = {} seen_importance = {} tally = {} tally_by_urgency = {} for update_item in update_list: old_pkg, new_pkg, descriptions = update_item imp = new_pkg["importance_str"] if imp == "necessary": necessary_count = necessary_count + 1 if imp == "urgent": urgent_count = urgent_count + 1 ch = rcchannelutils.channel_id_to_name(server, new_pkg["channel"]) seen_channels[ch] = 1 seen_importance[imp] = new_pkg["importance_num"] key = ch + "||" + imp if tally.has_key(key): tally[key] = tally[key] + 1 else: tally[key] = 1 if tally_by_urgency.has_key(imp): tally_by_urgency[imp] = tally_by_urgency[imp] + 1 else: tally_by_urgency[imp] = 1 rctalk.message("") rctalk.message("There %s %d update%s available at this time." \ % ((count != 1 and "are") or "is", count, (count != 1 and "") or "s")) if necessary_count: rctalk.message("%d update%s marked as 'necessary'." \ % (necessary_count, (necessary_count != 1 and "s are") or " is")) if urgent_count: rctalk.message("%d update%s marked as 'urgent'." \ % (urgent_count, (urgent_count != 1 and "s are") or " is")) rctalk.message("") channels = seen_channels.keys() channels.sort(lambda x, y: cmp(string.lower(x), string.lower(y))) importances = seen_importance.keys() importances.sort(lambda x, y, f=seen_importance: cmp(f[x], f[y])) header = ["Channel"] if no_abbrev or len(importances) <= 4: header = header + importances else: header = header + map(rcformat.abbrev_importance, importances) header = header + ["total"] table = [] for ch in channels: if no_abbrev: row = [ch] else: row = [rcformat.abbrev_channel_name(ch)] row_count = 0 for imp in importances: key = ch + "||" + imp if tally.has_key(key): row.append(string.rjust(str(tally[key]), 3)) row_count = row_count + tally[key] else: row.append("") if count: row.append(string.rjust(str(row_count), 3)) else: row.append("") table.append(row) row = ["total"] for imp in importances: row.append(string.rjust(str(tally_by_urgency[imp]), 3)) row.append(string.rjust(str(count), 3)) table.append(row) rcformat.tabular(header, table) rctalk.message("")