Example #1
0
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
Example #2
0
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]
Example #3
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 #4
0
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
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 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 #7
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 #8
0
def package_to_row(server, pkg, no_abbrev, key_list):

    row = []

    for key in key_list:

        val = "?"

        if key == "installed":

            if pkg["installed"]:
                val = "i"
            elif pkg["name_installed"]:
                val = "v"
            else:
                val = ""

            if pkg.get("locked"):
                val = val + "L"

            if pkg.get("package_set"):
                val = val + "S"

        elif key == "channel":

            if pkg.has_key("channel_guess"):
                id = pkg["channel_guess"]
            else:
                id = pkg["channel"]

            if id:
                val = rcchannelutils.channel_id_to_name(server, id)
            else:
                val = "(none)"

            if not no_abbrev:
                val = abbrev_channel_name(val)

        elif key == "version":

            if no_abbrev:
                val = evr_to_str(pkg)
            else:
                val = evr_to_abbrev_str(pkg)

        elif key == "name":

            # Trim long names
            val = pkg["name"]
            if not no_abbrev and len(val) > 25:
                val = val[0:22] + "..."

        elif pkg.has_key(key):
            val = pkg[key]

        row.append(val)

    return row
Example #9
0
def package_to_row(server, pkg, no_abbrev, key_list):

    row = []

    for key in key_list:

        val = "?"

        if key == "installed":

            if pkg["installed"]:
                val = "i"
            elif pkg["name_installed"]:
                val = "v"
            else:
                val = ""

            if pkg.get("locked"):
                val = val + "L"

            if pkg.get("package_set"):
                val = val + "S"

        elif key == "channel":

            if pkg.has_key("channel_guess"):
                id = pkg["channel_guess"]
            else:
                id = pkg["channel"]

            if id:
                val = rcchannelutils.channel_id_to_name(server, id)
            else:
                val = "(none)"

            if not no_abbrev:
                val = abbrev_channel_name(val)

        elif key == "version":

            if no_abbrev:
                val = evr_to_str(pkg)
            else:
                val = evr_to_abbrev_str(pkg)

        elif key == "name":

            # Trim long names
            val = pkg["name"]
            if not no_abbrev and len(val) > 25:
                val = val[0:22] + "..."

        elif pkg.has_key(key):
            val = pkg[key]

        row.append(val)

    return row
Example #10
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 #11
0
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
Example #12
0
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
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 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 #15
0
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
Example #16
0
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("")
Example #17
0
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("")
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 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]
Example #20
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 #21
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 #22
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 #23
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("")