Example #1
0
    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 ***")
Example #2
0
def terse_updates_table(server, update_list):

    update_table = []

    for update_item in update_list:

        old_pkg, new_pkg, descriptions = update_item

        urgency = "?"
        if new_pkg.has_key("importance_str"):
            urgency = new_pkg["importance_str"]

        channel_name = rcchannelutils.channel_id_to_name(
            server, new_pkg["channel"])

        old_ver = rcformat.evr_to_str(old_pkg)
        new_ver = rcformat.evr_to_str(new_pkg)

        update_table.append(
            [urgency, channel_name, new_pkg["name"], old_ver, new_ver])


    update_table.sort(lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or \
                      cmp(string.lower(x[2]), string.lower(y[2])))

    rcformat.tabular([], update_table)
Example #3
0
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.")
Example #4
0
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.")
Example #5
0
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)
Example #6
0
    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 ***")
Example #7
0
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])
Example #8
0
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)
Example #9
0
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])
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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)
Example #13
0
    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)
Example #14
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.")
Example #15
0
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. ***")
Example #16
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.")
Example #17
0
class PrefsListCmd(rccommand.RCCommand):

    def name(self):
        return "get-prefs"

    def aliases(self):
        return ["get", "prefs"]

    def arguments(self):
        return "<pref name> <pref name> ..."

    def description_short(self):
        return "List the system preferences that may be set"

    def category(self):
        return "prefs"

    def local_opt_table(self):
        return [["d", "no-descriptions", "", "Do not show descriptions of the preferences"]]

    def execute(self, server, options_dict, non_option_args):
        headers = ["Name", "Value"]
        pref_table = []
        
        if not non_option_args:
            if options_dict.has_key("no-descriptions"):
                f = lambda p:[p["name"], str(p["value"])]
            else:
                headers.append("Description")
                f = lambda p:[p["name"], str(p["value"]), p["description"]]

            pref_table = map(f, server.rcd.prefs.list_prefs())
        else:
            for a in non_option_args:
                try:
                    p = server.rcd.prefs.get_pref(a)
                except ximian_xmlrpclib.Fault, f:
                    if f.faultCode == rcfault.invalid_preference:
                        rctalk.warning("There is no preference named '" + a + "'")
                    else:
                        raise
                else:
                    pref_table.append([a, str(p)])

        pref_table.sort(lambda x,y:cmp(string.lower(x[0]),
                                       string.lower(y[0])))

        if pref_table:
            rcformat.tabular(headers, pref_table)
Example #18
0
def terse_updates_table(server, update_list):

    update_table = []

    for update_item in update_list:

        old_pkg, new_pkg, descriptions = update_item

        urgency = "?"
        if new_pkg.has_key("importance_str"):
            urgency = new_pkg["importance_str"]

        channel_name = rcchannelutils.channel_id_to_name(server, new_pkg["channel"])

        old_ver = rcformat.evr_to_str(old_pkg)
        new_ver = rcformat.evr_to_str(new_pkg)

        update_table.append([urgency, channel_name, new_pkg["name"], old_ver, new_ver])


    update_table.sort(lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or \
                      cmp(string.lower(x[2]), string.lower(y[2])))

    rcformat.tabular([], update_table)
Example #19
0
    def execute(self, server, options_dict, non_option_args):
        locks = server.rcd.packsys.get_locks()

        verbose = options_dict.has_key("verbose")
        no_abbrev = options_dict.has_key("no-abbrev")
        matches = options_dict.has_key("matches")

        if locks:
            table = []
            count = 1
            for l in locks:
                pkgs = []
                if matches:
                    pkgs = server.rcd.packsys.search_by_package_match(l)
                    pkgs = filter_package_dups(pkgs)

                visible = 1

                if verbose:
                    extra_head = [("Lock #:", str(count))]
                    extra_tail = []
                    if matches:
                        first = 1
                        for p in pkgs:
                            label = (first == 1 and "Matches:") or ""
                            first = 0
                            id = p.get("channel_guess", 0) or p["channel"]
                            if id:
                                channel = rcchannelutils.channel_id_to_name(server, id)
                                channel = "(%s)" % channel
                            else:
                                channel = ""
                            pkg_str = "%s %s %s" % (p["name"],
                                                    rcformat.evr_to_str(p),
                                                    channel)

                            extra_tail.append((label, pkg_str))
                    
                    if display_match(server, l, extra_head, extra_tail):
                        rctalk.message("")
                    else:
                        visible = 0
                            
                else:
                    row = lock_to_table_row(server, l, no_abbrev)
                    if row is not None:
                        row.insert(0, str(count))
                        if matches:
                            row.append(str(len(pkgs)))
                        table.append(row)
                    else:
                        visible = 0

                if visible:
                    count = count + 1

            if not verbose:
                headers = ["#", "Pattern", "Channel", "Importance"]
                if matches:
                    headers.append("Matches")
                rcformat.tabular(headers, table)

        else:
            rctalk.message("--- No Locks Defined ---")
Example #20
0
    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 ---")
Example #21
0
    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("obsoletes"):
                continue

            table = []

            for dep in dep_info["obsoletes"]:
                provided_by = map(lambda x: x[0],
                                  server.rcd.packsys.what_provides(dep))
                ob_dict = {}

                name = rcformat.dep_to_str(dep)
                status = ""
                for provider in provided_by:
                    if provider["installed"]:
                        status = "*"

                count = 0
                for provider in provided_by:
                    # skip self-obsoletes
                    if evr_eq(provider, pkg):
                        continue

                    if provider["installed"]:
                        status = "*"
                    else:
                        status = ""

                    row = rcformat.package_to_row(
                        server, provider, 0, ["name", "installed", "channel"])
                    key = string.join(row)
                    if not ob_dict.has_key(key):
                        table.append([status, name] + row)
                        ob_dict[key] = 1
                        status = ""
                        name = ""
                        count = count + 1

                if count == 0:
                    table.append(["", name, "", "", ""])
                elif count > 1:
                    table.append(["", "", "", "", ""])

            if len(plist) > 1:
                rctalk.message("--- %s %s ---" %
                               (pkg["name"], rcformat.evr_to_str(pkg)))

            if not table:
                rctalk.message("--- No obsoletes ---")
            else:
                rcformat.tabular(
                    ["!", "Obsoletes", "Provided by", "S", "Channel"], table)

            if len(plist) > 1:
                rctalk.message("")
Example #22
0
    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("")
Example #23
0
    def execute(self, server, options_dict, non_option_args):

        if len(non_option_args) < 1:
            self.usage()
            sys.exit(1)

        no_abbrev = options_dict.has_key("no-abbrev")

        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("children"):
                continue

            table = []

            row_spec = ["name", "channel"]
            row_headers = ["Provided By", "Channel"]
            pad = []

            if options_dict.has_key("show-versions"):
                row_spec.insert(1, "version")
                row_headers.insert(1, "Version")
                pad = pad + [""]

            if options_dict.has_key("all-providers"):
                row_spec.insert(2, "installed")
                row_headers.insert(2, "S")
                pad = pad + [""]

            for dep in dep_info["children"]:
                providers = map(lambda x: x[0],
                                server.rcd.packsys.what_provides(dep))
                prov_dict = {}

                name = rcformat.dep_to_str(dep)
                status = "*"
                for prov in providers:
                    if prov["installed"]:
                        status = ""

                if status == "" \
                       and not options_dict.has_key("all-providers"):
                    providers = filter(lambda x: x["installed"], providers)

                count = 0
                for prov in providers:
                    row = rcformat.package_to_row(server, prov, no_abbrev,
                                                  row_spec)
                    key = string.join(row)
                    if not prov_dict.has_key(key):
                        table.append([status, name] + row)
                        prov_dict[key] = 1
                        status = ""
                        name = ""
                        count = count + 1

                if count == 0:
                    table.append(["*", name, "(none)", "(none)"] + pad)
                elif count > 1 and not rctalk.be_terse:
                    table.append(["", "", "", ""] + pad)

            if len(plist) > 1:
                rctalk.message("--- %s %s ---" %
                               (pkg["name"], rcformat.evr_to_str(pkg)))

            if not table:
                rctalk.message("--- No Children ---")
            else:
                rcformat.tabular(["!", "Requirement"] + row_headers, table)

            if len(plist) > 1:
                rctalk.message("")
Example #24
0
    def execute(self, server, options_dict, non_option_args):

        if options_dict.has_key("search-descriptions"):
            key = "text"
        else:
            key = "name"

        if options_dict.has_key("match-words"):
            op = "contains_word"
        else:
            op = "contains"

        query = []
        for s in non_option_args:
            query.append([key, op, s])

        if query and options_dict.has_key("match-any"):
            query.insert(0, ["", "begin-or", ""])
            query.append(["", "end-or", ""])

        if options_dict.has_key("installed-only"):
            query.append(["package-installed", "=", "true"])
        elif options_dict.has_key("uninstalled-only"):
            query.append(["package-installed", "=", "false"])

        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)
            c = clist[0]

            query.append(["channel", "=", c["id"]])

        packages = server.rcd.packsys.search(query)

        if options_dict.has_key("locked-only") or options_dict.has_key("unlocked-only"):
            if options_dict.has_key("locked-only"):
                packages = filter(lambda p:p["locked"], packages)
            elif options_dict.has_key("unlocked-only"):
                packages = filter(lambda p:not p["locked"], packages)

        # Filter out packages which are in "hidden" channels, like the
        # system packages channel.
        packages = rcpackageutils.filter_visible_channels(server, packages)

        package_table = []
        no_abbrev = options_dict.has_key("no-abbrev")

        for p in packages:
            row = rcformat.package_to_row(server, p, no_abbrev,
                                          ["installed", "channel", "name", "version"])
            package_table.append(row)

        if package_table:
            
            if options_dict.has_key("sort-by-channel"):
                package_table.sort(lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or\
                                   cmp(string.lower(x[2]), string.lower(y[2])))
            else:
                package_table.sort(lambda x,y:cmp(string.lower(x[2]), string.lower(y[2])))
                
            rcformat.tabular(["S", "Channel", "Name", "Version"], package_table)
        else:
            rctalk.message("--- No packages found ---")
Example #25
0
    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("obsoletes"):
                continue

            table = []

            for dep in dep_info["obsoletes"]:
                provided_by = map(lambda x:x[0], server.rcd.packsys.what_provides(dep))
                ob_dict = {}

                name = rcformat.dep_to_str(dep)
                status = ""
                for provider in provided_by:
                    if provider["installed"]:
                        status = "*"

                count = 0
                for provider in provided_by:
                    # skip self-obsoletes
                    if evr_eq(provider, pkg):
                        continue

                    if provider["installed"]:
                        status = "*"
                    else:
                        status = ""
                    
                    row = rcformat.package_to_row(server, provider, 0, ["name", "installed", "channel"])
                    key = string.join(row)
                    if not ob_dict.has_key(key):
                        table.append([status, name] + row)
                        ob_dict[key] = 1
                        status = ""
                        name = ""
                        count = count + 1

                if count == 0:
                    table.append(["", name, "", "", ""])
                elif count > 1:
                    table.append(["", "", "", "", ""])

            if len(plist) > 1:
                rctalk.message("--- %s %s ---" %
                               (pkg["name"], rcformat.evr_to_str(pkg)))

            if not table:
                rctalk.message("--- No obsoletes ---")
            else:
                rcformat.tabular(["!", "Obsoletes", "Provided by", "S", "Channel"], table)

            if len(plist) > 1:
                rctalk.message("")
Example #26
0
    def execute(self, server, options_dict, non_option_args):

        if options_dict.has_key("search-descriptions"):
            key = "text"
        else:
            key = "name"

        if options_dict.has_key("match-words"):
            op = "contains_word"
        else:
            op = "contains"

        query = []
        for s in non_option_args:
            query.append([key, op, s])

        if query and options_dict.has_key("match-any"):
            query.insert(0, ["", "begin-or", ""])
            query.append(["", "end-or", ""])

        if options_dict.has_key("installed-only"):
            query.append(["package-installed", "=", "true"])
        elif options_dict.has_key("uninstalled-only"):
            query.append(["package-installed", "=", "false"])

        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)
            c = clist[0]

            query.append(["channel", "=", c["id"]])

        packages = server.rcd.packsys.search(query)

        if options_dict.has_key("locked-only") or options_dict.has_key(
                "unlocked-only"):
            if options_dict.has_key("locked-only"):
                packages = filter(lambda p: p["locked"], packages)
            elif options_dict.has_key("unlocked-only"):
                packages = filter(lambda p: not p["locked"], packages)

        # Filter out packages which are in "hidden" channels, like the
        # system packages channel.
        packages = rcpackageutils.filter_visible_channels(server, packages)

        package_table = []
        no_abbrev = options_dict.has_key("no-abbrev")

        for p in packages:
            row = rcformat.package_to_row(
                server, p, no_abbrev,
                ["installed", "channel", "name", "version"])
            package_table.append(row)

        if package_table:

            if options_dict.has_key("sort-by-channel"):
                package_table.sort(lambda x,y:cmp(string.lower(x[1]), string.lower(y[1])) or\
                                   cmp(string.lower(x[2]), string.lower(y[2])))
            else:
                package_table.sort(
                    lambda x, y: cmp(string.lower(x[2]), string.lower(y[2])))

            rcformat.tabular(["S", "Channel", "Name", "Version"],
                             package_table)
        else:
            rctalk.message("--- No packages found ---")
Example #27
0
    def execute(self, server, options_dict, non_option_args):

        if len(non_option_args) < 1:
            self.usage()
            sys.exit(1)

        no_abbrev = options_dict.has_key("no-abbrev")

        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("children"):
                continue

            table = []

            row_spec = ["name", "channel"]
            row_headers = ["Provided By", "Channel"]
            pad = []

            if options_dict.has_key("show-versions"):
                row_spec.insert(1, "version")
                row_headers.insert(1, "Version")
                pad = pad + [""]

            if options_dict.has_key("all-providers"):
                row_spec.insert(2, "installed")
                row_headers.insert(2, "S")
                pad = pad + [""]

            for dep in dep_info["children"]:
                providers = map(lambda x:x[0], server.rcd.packsys.what_provides(dep))
                prov_dict = {}

                name = rcformat.dep_to_str(dep)
                status = "*"
                for prov in providers:
                    if prov["installed"]:
                        status = ""

                if status == "" \
                       and not options_dict.has_key("all-providers"):
                    providers = filter(lambda x:x["installed"], providers)


                count = 0
                for prov in providers:
                    row = rcformat.package_to_row(server, prov, no_abbrev, row_spec)
                    key = string.join(row)
                    if not prov_dict.has_key(key):
                        table.append([status, name] + row)
                        prov_dict[key] = 1
                        status = ""
                        name = ""
                        count = count + 1

                if count == 0:
                    table.append(["*", name, "(none)", "(none)"] + pad)
                elif count > 1 and not rctalk.be_terse:
                    table.append(["", "", "", ""] + pad)

            if len(plist) > 1:
                rctalk.message("--- %s %s ---" %
                               (pkg["name"], rcformat.evr_to_str(pkg)))

            if not table:
                rctalk.message("--- No Children ---")
            else:
                rcformat.tabular(["!", "Requirement"] + row_headers, table)

            if len(plist) > 1:
                rctalk.message("")
Example #28
0
    def execute(self, server, options_dict, non_option_args):

        channels = rcchannelutils.get_channels(server)
        channel_table = []

        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)

            channels = filter(lambda c,s=service:c.get("service") == s["id"],
                              channels)

        headers = ["subd?", "Alias", "Name"]
        if options_dict.has_key("show-ids"):
            headers.insert(2, "ID")
        if options_dict.has_key("show-services"):
            headers.append("Service")

        for c in channels:

            show = 1

            if c["hidden"]:
                show = 0

            if c["subscribed"]:
                if rctalk.be_terse:
                    subflag = "Yes"
                else:
                    subflag = " Yes "
                if options_dict.has_key("unsubscribed"):
                    show = 0
            else:
                subflag = ""
                if options_dict.has_key("subscribed"):
                    show = 0

            if options_dict.has_key("mounted") and not c["mounted"]:
                show = 0

            if show:
                row = [subflag, rcchannelutils.get_channel_alias(c), c["name"]]
                if options_dict.has_key("show-ids"):
                    row.insert(2, c["id"])
                if options_dict.has_key("show-services"):
                    services = rcserviceutils.get_services(server)
                    service = rcserviceutils.find_service(services, c["service"])
                    row.append(service["name"])
                channel_table.append(row)

        if channel_table:
            channel_table.sort(lambda x, y:cmp(x[2],y[2]))
            rcformat.tabular(headers, channel_table)
        else:
            if options_dict.has_key("unsubscribed"):
                rctalk.message("--- No unsubscribed channels ---")
            elif options_dict.has_key("subscribed"):
                rctalk.message("--- No subscribed channels ---")
            elif options_dict.has_key("mounted"):
                rctalk.message("--- No mounted channels ---")
            else:
                rctalk.warning("--- No channels available ---")
Example #29
0
class ServiceMirrorsCmd(rccommand.RCCommand):
    def name(self):
        return "mirrors"

    def aliases(self):
        return []

    def arguments(self):
        return "<service> <mirror #>"

    def description_short(self):
        return "Select a mirror for a service"

    def category(self):
        return "service"

    def local_opt_table(self):
        return [["l", "list-only", "", "List the available mirrors"]]

    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

        if not mirrors:
            rctalk.message("--- No mirrors available ---")
            return

        mirrors.sort(sort_cb)

        if show_list:
            table = []
            i = 1
            for m in mirrors:
                short_name = m["name"]
                if len(short_name) > 35 and not verbose:
                    short_name = short_name[:32] + "..."

                num = str(i)
                if m["url"] == current_host:
                    num = "*" + num
                else:
                    num = " " + num

                table.append([num, short_name, m.get("location", "Unknown")])
                if verbose:
                    table.append(["", m["url"]])
                i = i + 1

            rcformat.tabular([" #", "Mirror", "Location"], table)

        if allow_select:
            rctalk.message("")
            rctalk.message("To select a mirror, type the mirror's number at")
            rctalk.message("at the prompt and press return.")
            rctalk.message("")

            print "Mirror: ",
            select_str = string.strip(sys.stdin.readline())
            rctalk.message("")
            if not select_str:
                rctalk.message("No mirror selected.")
                return

        if not select_str:
            return

        n = -1
        try:
            n = int(select_str)
        except:
            pass

        if not (1 <= n <= len(mirrors)):
            rctalk.error("'%s' is not a valid mirror." % select_str)
            sys.exit(1)

        choice = mirrors[n - 1]

        sel_table = []
        sel_table.append(["Name", choice["name"]])
        sel_table.append(["Location", choice.get("location", "Unknown")])
        sel_table.append(["URL", choice["url"]])

        key_width = apply(max, map(lambda x: len(x[0]), sel_table))

        rctalk.message("Selected Mirror:")
        for key, val in sel_table:
            key = " " * (key_width - len(key)) + key
            rctalk.message("%s: %s" % (key, val))

        if choice["url"] != current_host:
            rctalk.message("")
            try:
                server.rcd.service.set_url(service["id"], choice["url"])
            except ximian_xmlrpclib.Fault, f:
                if f.faultCode == rcfault.invalid_service:
                    rctalk.error(f.faultString)
                else:
                    raise
Example #30
0
    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 ---")
Example #31
0
    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("")
Example #32
0
 def execute(self, server, options_dict, non_option_args):
     users = server.rcd.users.get_all()
     if users:
         rcformat.tabular(["Username", "Privileges"], users)
     else:
         rctalk.message("--- No users found ---")
Example #33
0
    def execute(self, server, options_dict, non_option_args):
        locks = server.rcd.packsys.get_locks()

        verbose = options_dict.has_key("verbose")
        no_abbrev = options_dict.has_key("no-abbrev")
        matches = options_dict.has_key("matches")

        if locks:
            table = []
            count = 1
            for l in locks:
                pkgs = []
                if matches:
                    pkgs = server.rcd.packsys.search_by_package_match(l)
                    pkgs = filter_package_dups(pkgs)

                visible = 1

                if verbose:
                    extra_head = [("Lock #:", str(count))]
                    extra_tail = []
                    if matches:
                        first = 1
                        for p in pkgs:
                            label = (first == 1 and "Matches:") or ""
                            first = 0
                            id = p.get("channel_guess", 0) or p["channel"]
                            if id:
                                channel = rcchannelutils.channel_id_to_name(
                                    server, id)
                                channel = "(%s)" % channel
                            else:
                                channel = ""
                            pkg_str = "%s %s %s" % (
                                p["name"], rcformat.evr_to_str(p), channel)

                            extra_tail.append((label, pkg_str))

                    if display_match(server, l, extra_head, extra_tail):
                        rctalk.message("")
                    else:
                        visible = 0

                else:
                    row = lock_to_table_row(server, l, no_abbrev)
                    if row is not None:
                        row.insert(0, str(count))
                        if matches:
                            row.append(str(len(pkgs)))
                        table.append(row)
                    else:
                        visible = 0

                if visible:
                    count = count + 1

            if not verbose:
                headers = ["#", "Pattern", "Channel", "Importance"]
                if matches:
                    headers.append("Matches")
                rcformat.tabular(headers, table)

        else:
            rctalk.message("--- No Locks Defined ---")