Beispiel #1
0
    def execute(self, server, options_dict, non_option_args):

        service = None
        if options_dict.has_key("service"):
            services = rcserviceutils.get_services(server)
            service = rcserviceutils.find_service(services,
                                                  options_dict["service"])

            if not service:
                rctalk.error("Unknown service '%s'" % options_dict["service"])
                sys.exit(1)

        failed = 0
        to_do = []
        if options_dict.has_key("all"):
            to_do = filter(lambda c:not c["hidden"],
                           rcchannelutils.get_channels(server))
            if service:
                to_do = filter(lambda c,s=service:c.get("service") == s["id"],
                               to_do)
        else:
            for a in non_option_args:
                clist = rcchannelutils.get_channels_by_name(server, a, service)
                if not rcchannelutils.validate_channel_list(a, clist):
                    failed = 1
                else:
                    c = clist[0]
                    to_do.append(c)
                    if options_dict.has_key("strict") and not c["subscribed"]:
                        rctalk.error("Not subscribed to channel " + \
                                     rcchannelutils.channel_to_str(c))
                        failed = 1

        if failed:
            sys.exit(1)

        for c in to_do:
            if c:
                if server.rcd.packsys.unsubscribe(c["id"]):
                    rctalk.message("Unsubscribed from channel " + \
                                   rcchannelutils.channel_to_str(c))
                else:
                    rctalk.warning("Attempt to unsubscribe to channel " + \
                                   rcchannelutils.channel_to_str(c) + " failed")
Beispiel #2
0
def get_updates(server, non_option_args, allow_dups=0):
    up = server.rcd.packsys.get_updates()

    # If channels are specified by the command line, filter out all except
    # for updates from those channels.
    if non_option_args:
        channel_id_list = []
        failed = 0
        for a in non_option_args:
            clist = rcchannelutils.get_channels_by_name(server, a)
            if not rcchannelutils.validate_channel_list(a, clist):
                failed = 1
            else:
                c = clist[0]
                if c["subscribed"]:
                    channel_id_list.append(c["id"])
                else:
                    rctalk.warning("You are not subscribed to "
                                   + rcchannelutils.channel_to_str(c)
                                   + ", so no updates are available.")
                    
        if failed:
            sys.exit(1)

        up = filter(lambda x, cidl=channel_id_list:x[1]["channel"] in cidl, up)

    # Filter out exact duplicates
    if not allow_dups:
        def pkg_to_key(p):
            return "%s:%d:%s:%s" % \
                   (p["name"], p["epoch"], p["version"], p["release"])

        dup_dict = {}
        for u in up:
            key = pkg_to_key(u[1]) # u[1] is the new version of the package
            if not dup_dict.has_key(key):
                dup_dict[key] = u

        up = dup_dict.values()

        del dup_dict

    return up
Beispiel #3
0
    def execute(self, server, options_dict, non_option_args):

        if len(non_option_args) == 0:
            rctalk.error("No channel specified.")
            sys.exit(1)

        channel_name = non_option_args[0]
        channels = rcchannelutils.get_channels_by_name(server, channel_name)

        if not rcchannelutils.validate_channel_list(channel_name, channels):
            sys.exit(1)

        channel = channels[0]

        retval = server.rcd.packsys.unmount_directory(channel["id"])

        if retval:
            rctalk.message("Unmounted channel '%s'" % channel["name"])
        else:
            rctalk.error("Unmount of channel '%s' failed" % channel["name"])
Beispiel #4
0
    def execute(self, server, options_dict, non_option_args):

        if len(non_option_args) == 0:
            rctalk.error("No channel specified.")
            sys.exit(1)

        channel_name = non_option_args[0]
        channels = rcchannelutils.get_channels_by_name(server, channel_name)

        if not rcchannelutils.validate_channel_list(channel_name, channels):
            sys.exit(1)

        channel = channels[0]

        retval = server.rcd.packsys.unmount_directory(channel["id"])

        if retval:
            rctalk.message("Unmounted channel '%s'" % channel["name"])
        else:
            rctalk.error("Unmount of channel '%s' failed" % channel["name"])
Beispiel #5
0
def split_channel_and_name(server, s):
    # Try to split the string into "channel:name"
    off = string.find(s, ":")
    if off != -1:
        channel = s[:off]
        name = s[off+1:]
    else:
        channel = None
        name = s

    # Validate the channel
    if channel:
        clist = rcchannelutils.get_channels_by_name(server, channel)

        if not rcchannelutils.validate_channel_list(channel, clist):
            sys.exit(1)
            
        channel_id = clist[0]["id"]
    else:
        channel_id = None

    return (channel_id, name)
Beispiel #6
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 ---")
Beispiel #7
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)

        install_list = []

        if options_dict.has_key("download-only"):
            flags = rcmain.DOWNLOAD_ONLY
        else:
            flags = 0

        if options_dict.has_key("allow-unsubscribed"):
            allow_unsub = 1
        else:
            allow_unsub = 0

        if options_dict.has_key("entire-channel"):
            channel_list = []
            for a in non_option_args:
                matches = rcchannelutils.get_channels_by_name(server, a)
                if not rcchannelutils.validate_channel_list(a, matches):
                    sys.exit(1)
                channel_list.append(matches[0])

            contributors = 0
            for c in channel_list:
                query = [["channel", "=", c["id"]],
                         ["patch-installed", "=", "false"]]
                patches = server.rcd.you.search(query)
                install_list.extend(patches)
                if len(patches) > 0:
                    contributors = contributors + 1
                msg = "Found %d %s in channel '%s'" % \
                      (len(patches),
                       (len(patches) != 1 and "patches") or "patch",
                       c["name"])
                rctalk.message(msg)

            if contributors > 1:
                msg = "Found a total of %d %s" % \
                      (len(install_list),
                       (len(install_list) != 1 and "patches")
                       or "patch")
                rctalk.message(msg)

            rctalk.message("")
        else:
            for a in non_option_args:
                plist = find_patch(server, a, allow_unsub, allow_system=0)

                if not plist:
                    sys.exit(1)

                for p in plist:
                    dups = filter(lambda x, pn=p: x["name"] == pn["name"],
                                  install_list)

                    if dups:
                        rctalk.error("Duplicate entry found: " +
                                     dups[0]["name"])
                        sys.exit(1)

                    install_list.append(p)

        if not install_list:
            rctalk.message("--- No patches to install ---")
            sys.exit(0)

        self.check_licenses(server, install_list)
        download_id, transact_id, step_id = \
                     server.rcd.you.transact (install_list,
                                              flags,
                                              "",
                                              rcmain.rc_name,
                                              rcmain.rc_version)

        self.poll_transaction(server, download_id, transact_id, step_id)
Beispiel #8
0
    def execute(self, server, options_dict, non_option_args):
        packages_to_install = []
        packages_to_remove = []

        if options_dict.has_key("allow-unsubscribed"):
            allow_unsub = 1
        else:
            allow_unsub = 0

        if options_dict.has_key("entire-channel"):

            channel_list = []
            for a in non_option_args:
                matches = rcchannelutils.get_channels_by_name(server, a)
                if not rcchannelutils.validate_channel_list(a, matches):
                    sys.exit(1)
                channel_list.append(matches[0])

            contributors = 0
            for c in channel_list:
                query = [["channel", "=", c["id"]],
                         ["package-installed", "=", "false"]]
                packages = server.rcd.packsys.search(query)
                packages_to_install.extend(packages)
                if len(packages) > 0:
                    contributors = contributors + 1
                msg = "Found %d %s in channel '%s'" % \
                      (len(packages),
                       (len(packages) != 1 and "packages") or "package",
                       c["name"])
                rctalk.message(msg)

            if contributors > 1:
                msg = "Found a total of %d %s" % \
                      (len(packages_to_install),
                       (len(packages_to_install) != 1 and "packages")
                       or "package")
                rctalk.message(msg)

            rctalk.message("")

        else:

            for a in non_option_args:
                inform = 0
                channel = None
                package = None

                if a[0] == "!" or a[0] == "~":
                    pn = a[1:]
                    plist = rcpackageutils.find_package_on_system(server, pn)

                    if not plist:
                        rctalk.error("Unable to find package '" + pn + "'")
                        sys.exit(1)

                    for p in plist:
                        packages_to_remove.append(p)
                else:
                    plist = rcpackageutils.find_package(server,
                                                        a,
                                                        allow_unsub,
                                                        allow_system=0)

                    if not plist:
                        sys.exit(1)

                    for p in plist:
                        dups = filter(lambda x, pn=p: x["name"] == pn["name"],
                                      packages_to_install)

                        if dups and not options_dict.has_key("download-only"):
                            rctalk.error("Duplicate entry found: " +
                                         dups[0]["name"])
                            sys.exit(1)

                        packages_to_install.append(p)

        if not packages_to_install and not packages_to_remove:
            rctalk.message("--- No packages to install ---")
            sys.exit(0)

        if not options_dict.has_key("download-only"):
            install_deps, remove_deps, dep_info = \
                          resolve_dependencies(server,
                                               packages_to_install,
                                               packages_to_remove,
                                               [])
        else:
            install_deps = []
            remove_deps = []

        self.transact(server, options_dict, packages_to_install, install_deps,
                      packages_to_remove, remove_deps)
Beispiel #9
0
    def execute(self, server, options_dict, non_option_args):

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

        match = {}

        # Split non-option args on whitespace, reassembling the
        # pieces into a new list.
        non_option_args = reduce(lambda x,y: x+y,
                                 map(string.split, non_option_args))

        if len(non_option_args) == 3:
            name, relation, version = non_option_args

            if "?" in name or "*" in name:
                rctalk.warning("Wildcards are not allowed when specifying versioned locks.")
                sys.exit(1)

            valid_relations = ("=", "<", ">", "<=", ">=")
            if relation not in valid_relations:
                valid_str = string.join(map(lambda x: "'%s'" % x, valid_relations), ", ")
                rctalk.warning("'%s' is not a valid relation." % relation)
                rctalk.warning("Valid relations are: %s" % valid_str)
                sys.exit(1)

            match["dep"] = {"name": name,
                            "relation":relation,
                            "version_str":version }
            
        elif len(non_option_args) == 1:
            glob = non_option_args[0]
            # FIXME: It would be nice to verify that the incoming glob
            # is valid.  (It probably shouldn't contain whitespace, shouldn't
            # be the empty string, etc.)
            match["glob"] = glob
        elif len(non_option_args) != 0:
            rctalk.error("Unrecognized input \"%s\"" %
                         string.join(non_option_args, " "))
            sys.exit(1)
            
        if options_dict.has_key("channel"):
            cname = options_dict["channel"]
            clist = rcchannelutils.get_channels_by_name(server, cname)
            if not rcchannelutils.validate_channel_list(cname, clist):
                sys.exit(1)
            match["channel"] = clist[0]["id"]

        if options_dict.has_key("name"):
            # FIXME: It would be nice to verify that the incoming glob
            # is valid.  (It probably shouldn't contain whitespace, shouldn't
            # be the empty string, etc.)
            match["glob"] = options_dict["name"]

        if options_dict.has_key("importance"):
            num = rcformat.importance_str_to_num(options_dict["importance"])
            if num < 0:
                rctalk.error("'%s' is not a valid importance level" %
                             options_dict["importance"])
                sys.exit(1)

            # We want to match (i.e. lock) all packages below the given
            # importance.  Remember, in a match the opposite of >= is
            # <=, not <.  (Maybe this is broken, but it seems pretty
            # unnecessary to offer the full selection of comparison
            # operators.)
            match["importance_num"] = num
            match["importance_gteq"] = 0

        # FIXME: validate that the match isn't empty, etc.
        server.rcd.packsys.add_lock(match)

        rctalk.message("--- Added Lock ---")
        display_match(server, match)
Beispiel #10
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 ---")
Beispiel #11
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)

        install_list = []

        if options_dict.has_key("download-only"):
            flags = rcmain.DOWNLOAD_ONLY
        else:
            flags = 0

        if options_dict.has_key("allow-unsubscribed"):
            allow_unsub = 1
        else:
            allow_unsub = 0

        if options_dict.has_key("entire-channel"):
            channel_list = []
            for a in non_option_args:
                matches = rcchannelutils.get_channels_by_name(server, a)
                if not rcchannelutils.validate_channel_list(a, matches):
                    sys.exit(1)
                channel_list.append(matches[0])

            contributors = 0
            for c in channel_list:
                query = [["channel", "=", c["id"]],
                         ["patch-installed", "=", "false"]]
                patches = server.rcd.you.search(query)
                install_list.extend(patches)
                if len(patches) > 0:
                    contributors = contributors + 1
                msg = "Found %d %s in channel '%s'" % \
                      (len(patches),
                       (len(patches) != 1 and "patches") or "patch",
                       c["name"])
                rctalk.message(msg)

            if contributors > 1:
                msg = "Found a total of %d %s" % \
                      (len(install_list),
                       (len(install_list) != 1 and "patches")
                       or "patch")
                rctalk.message(msg)

            rctalk.message("")
        else:
            for a in non_option_args:
                plist = find_patch(server, a,
                                   allow_unsub,
                                   allow_system=0)

                if not plist:
                    sys.exit(1)

                for p in plist:
                    dups = filter(lambda x, pn=p:x["name"] == pn["name"],
                                  install_list)
                    
                    if dups:
                        rctalk.error("Duplicate entry found: " +
                                     dups[0]["name"])
                        sys.exit(1)

                    install_list.append(p)

        if not install_list:
            rctalk.message("--- No patches to install ---")
            sys.exit(0)
        
        self.check_licenses (server, install_list)
        download_id, transact_id, step_id = \
                     server.rcd.you.transact (install_list,
                                              flags,
                                              "",
                                              rcmain.rc_name,
                                              rcmain.rc_version)

        self.poll_transaction(server, download_id, transact_id, step_id)
Beispiel #12
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 ---")
Beispiel #13
0
    def execute(self, server, options_dict, non_option_args):
        packages_to_install = []
        packages_to_remove = []
        
        if options_dict.has_key("allow-unsubscribed"):
            allow_unsub = 1
        else:
            allow_unsub = 0

        if options_dict.has_key("entire-channel"):

            channel_list = []
            for a in non_option_args:
                matches = rcchannelutils.get_channels_by_name(server, a)
                if not rcchannelutils.validate_channel_list(a, matches):
                    sys.exit(1)
                channel_list.append(matches[0])

            contributors = 0
            for c in channel_list:
                query = [["channel", "=", c["id"]],
                         ["package-installed", "=", "false"]]
                packages = server.rcd.packsys.search(query)
                packages_to_install.extend(packages)
                if len(packages) > 0:
                    contributors = contributors + 1
                msg = "Found %d %s in channel '%s'" % \
                      (len(packages),
                       (len(packages) != 1 and "packages") or "package",
                       c["name"])
                rctalk.message(msg)

            if contributors > 1:
                msg = "Found a total of %d %s" % \
                      (len(packages_to_install),
                       (len(packages_to_install) != 1 and "packages")
                       or "package")
                rctalk.message(msg)

            rctalk.message("")

        else:
            
            for a in non_option_args:
                inform = 0
                channel = None
                package = None

                if a[0] == "!" or a[0] == "~":
                    pn = a[1:]
                    plist = rcpackageutils.find_package_on_system(server, pn)

                    if not plist:
                        rctalk.error("Unable to find package '" + pn + "'")
                        sys.exit(1)

                    for p in plist:
                        packages_to_remove.append(p)
                else:
                    plist = rcpackageutils.find_package(server, a,
                                                        allow_unsub,
                                                        allow_system=0)

                    if not plist:
                        sys.exit(1)

                    for p in plist:
                        dups = filter(lambda x, pn=p:x["name"] == pn["name"],
                                      packages_to_install)

                        if dups and not options_dict.has_key("download-only"):
                            rctalk.error("Duplicate entry found: " +
                                         dups[0]["name"])
                            sys.exit(1)

                        packages_to_install.append(p)

        if not packages_to_install and not packages_to_remove:
            rctalk.message("--- No packages to install ---")
            sys.exit(0)

        if not options_dict.has_key("download-only"):
            install_deps, remove_deps, dep_info = \
                          resolve_dependencies(server,
                                               packages_to_install,
                                               packages_to_remove,
                                               [])
        else:
            install_deps = []
            remove_deps = []

        self.transact(server, options_dict,
                      packages_to_install, install_deps,
                      packages_to_remove, remove_deps)
Beispiel #14
0
    def execute(self, server, options_dict, non_option_args):

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

        match = {}

        # Split non-option args on whitespace, reassembling the
        # pieces into a new list.
        non_option_args = reduce(lambda x, y: x + y,
                                 map(string.split, non_option_args))

        if len(non_option_args) == 3:
            name, relation, version = non_option_args

            if "?" in name or "*" in name:
                rctalk.warning(
                    "Wildcards are not allowed when specifying versioned locks."
                )
                sys.exit(1)

            valid_relations = ("=", "<", ">", "<=", ">=")
            if relation not in valid_relations:
                valid_str = string.join(
                    map(lambda x: "'%s'" % x, valid_relations), ", ")
                rctalk.warning("'%s' is not a valid relation." % relation)
                rctalk.warning("Valid relations are: %s" % valid_str)
                sys.exit(1)

            match["dep"] = {
                "name": name,
                "relation": relation,
                "version_str": version
            }

        elif len(non_option_args) == 1:
            glob = non_option_args[0]
            # FIXME: It would be nice to verify that the incoming glob
            # is valid.  (It probably shouldn't contain whitespace, shouldn't
            # be the empty string, etc.)
            match["glob"] = glob
        elif len(non_option_args) != 0:
            rctalk.error("Unrecognized input \"%s\"" %
                         string.join(non_option_args, " "))
            sys.exit(1)

        if options_dict.has_key("channel"):
            cname = options_dict["channel"]
            clist = rcchannelutils.get_channels_by_name(server, cname)
            if not rcchannelutils.validate_channel_list(cname, clist):
                sys.exit(1)
            match["channel"] = clist[0]["id"]

        if options_dict.has_key("name"):
            # FIXME: It would be nice to verify that the incoming glob
            # is valid.  (It probably shouldn't contain whitespace, shouldn't
            # be the empty string, etc.)
            match["glob"] = options_dict["name"]

        if options_dict.has_key("importance"):
            num = rcformat.importance_str_to_num(options_dict["importance"])
            if num < 0:
                rctalk.error("'%s' is not a valid importance level" %
                             options_dict["importance"])
                sys.exit(1)

            # We want to match (i.e. lock) all packages below the given
            # importance.  Remember, in a match the opposite of >= is
            # <=, not <.  (Maybe this is broken, but it seems pretty
            # unnecessary to offer the full selection of comparison
            # operators.)
            match["importance_num"] = num
            match["importance_gteq"] = 0

        # FIXME: validate that the match isn't empty, etc.
        server.rcd.packsys.add_lock(match)

        rctalk.message("--- Added Lock ---")
        display_match(server, match)
Beispiel #15
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 ---")