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

        ### For now, we just do something pretty mindless

        ### FIXME: the channel selection aren't supported yet

        news = server.rcd.news.get_all()

        if not news:
            rctalk.message("--- No news available ---")
            sys.exit(0)

        for n in news:
            if n.has_key("service_name"):
                rctalk.message("[%s]" % n["service_name"])
            if n.has_key("title"):
                rctalk.message(textify_entities(n["title"]))
            if n.has_key("time_str"):
                rctalk.message("("+n["time_str"]+")")
            if n.has_key("summary"):
                summary = re.sub("\s+", " ", n["summary"])
                lines = rcformat.linebreak(textify_entities(summary), 75)
                for l in lines:
                    rctalk.message(l)
            if n.has_key("url"):
                rctalk.message("To learn more, visit " + n["url"])
            rctalk.message("")
Beispiel #2
0
    def usage(self):

        rctalk.message("")
        rctalk.message("Usage: rug " + self.name() + " <options> " + \
                       self.arguments())
        rctalk.message("")

        description = self.description_long() or self.description_short()
        if description:
            description = "'" + self.name() + "': " + description
            for l in rcformat.linebreak(description, 72):
                rctalk.message(l)
            rctalk.message("")

        opts = self.local_opt_table()
        if opts:
            rctalk.message("'" + self.name() + "' Options:")
            rcformat.opt_table(opts)
            rctalk.message("")

        opts = self.default_opt_table()
        if opts:
            rctalk.message("General Options:")
            rcformat.opt_table(opts)
            rctalk.message("")
Beispiel #3
0
    def execute(self, server, options_dict, non_option_args):

        ### For now, we just do something pretty mindless

        ### FIXME: the channel selection aren't supported yet

        news = server.rcd.news.get_all()

        if not news:
            rctalk.message("--- No news available ---")
            sys.exit(0)

        for n in news:
            if n.has_key("service_name"):
                rctalk.message("[%s]" % n["service_name"])
            if n.has_key("title"):
                rctalk.message(textify_entities(n["title"]))
            if n.has_key("time_str"):
                rctalk.message("(" + n["time_str"] + ")")
            if n.has_key("summary"):
                summary = re.sub("\s+", " ", n["summary"])
                lines = rcformat.linebreak(textify_entities(summary), 75)
                for l in lines:
                    rctalk.message(l)
            if n.has_key("url"):
                rctalk.message("To learn more, visit " + n["url"])
            rctalk.message("")
Beispiel #4
0
class InstallYouPatchCmd(rccommand.RCCommand):
    def name(self):
        return "patch-install"

    def aliases(self):
        return ["pin"]

    def description_short(self):
        return "Install YOU patches"

    def category(self):
        return "YOU patches"

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

    def local_opt_table(self):
        return [
            [
                "u", "allow-unsubscribed", "",
                "Include unsubscribed channels when searching for software"
            ],
            [
                "d", "download-only", "",
                "Only download packages, don't install them"
            ],
            [
                "", "entire-channel", "",
                "Install all of the packages in the channels specified on the command line"
            ]
        ]

    def check_licenses(self, server, patches):
        try:
            licenses = server.rcd.you.licenses(patches)
        except ximian_xmlrpclib.Fault, f:
            if f.faultCode == rcfault.undefined_method:
                return
            else:
                raise
        if licenses:
            if len(licenses) > 1:
                lstr = "licenses"
            else:
                lstr = "license"
            rctalk.message("")
            rctalk.message("You must agree to the following %s before "
                           "installing this software:" % lstr)
            rctalk.message("")

            for l in licenses:
                rctalk.message(string.join(rcformat.linebreak(l, 72), "\n"))
                rctalk.message("")

            confirm = rctalk.prompt("Do you agree to the above "
                                    "%s? [y/N]" % lstr)
            if not confirm or not (confirm[0] == "y" or confirm[0] == "Y"):
                rctalk.message("Cancelled.")
                sys.exit(0)
Beispiel #5
0
def print_command_list(commands, with_categories=0):

    max_len = 0
    cmd_list = []

    for c in commands:
        name, aliases, description, category = c

        if aliases:
            name = name + " (" + string.join(aliases, ", ") + ")"

        cmd_list.append([name, description, category])
        max_len = max(max_len, len(name))

    desc_len = max_len + 4

    cmd_list.sort(command_sort)

    previous_category = "we will banish all dwarves from the love kingdom"

    for c in cmd_list:

        name, description, category = c

        if with_categories and category != previous_category:
            if category_data.has_key(category):
                category_name = category_data[category][0]
            else:
                category_name = string.upper(category[0]) + category[1:]

            rctalk.message("\n" + category_name + " commands:")
            previous_category = category

        # If, for some reason, the command list is *really* wide (which it never should
        # be), don't do something stupid.
        if 79 - desc_len > 10:
            desc = rcformat.linebreak(description, 79 - desc_len)
        else:
            desc = [description]

        desc_first = desc.pop(0)
        rctalk.message("  " + string.ljust(name, max_len) + "  " + desc_first)
        for d in desc:
            rctalk.message(" " * desc_len + d)
Beispiel #6
0
class TransactCmd(rccommand.RCCommand):
    def unattended_removals(self):
        return 0

    def local_opt_table(self):
        opts = [[
            "N", "dry-run", "", "Do not actually perform requested actions"
        ],
                [
                    "y", "no-confirmation", "",
                    "Permit all actions without confirmations"
                ]]

        if not self.unattended_removals():
            opts.append([
                "r", "allow-removals", "",
                "Permit removal of software without confirmation"
            ])

        return opts

    def display(self, server, options_dict, install_packages, install_deps,
                remove_packages, remove_deps):

        if options_dict.has_key("download-only"):
            rctalk.message("The following packages will be downloaded:")
            format_dependencies(server, install_packages)
        else:
            if install_packages:
                rctalk.message("The following requested packages will "
                               "be installed:")
                format_dependencies(server, install_packages)

            if install_deps:
                if install_packages:
                    rctalk.message("The following additional packages will "
                                   "be installed:")
                else:
                    rctalk.message("The following packages will be installed:")

                format_dependencies(server, install_deps)

            if remove_packages:
                rctalk.message("The following requested packages will "
                               "be removed:")
                format_dependencies(server, remove_packages)

            if remove_deps:
                if remove_packages:
                    rctalk.message("The following packages must also "
                                   "be REMOVED:")
                else:
                    rctalk.message("The following packages must be REMOVED")

                format_dependencies(server, remove_deps)

            if not options_dict.has_key("terse"):
                msg_list = []
                count = len(install_packages) + len(install_deps)

                if count:
                    msg_list.append("%d packages will be installed" % count)

                count = len(remove_packages) + len(remove_deps)
                if count:
                    msg_list.append("%d packages will be removed" % count)

                rctalk.message("%s." % string.join(msg_list, " and "))

        if not options_dict.has_key("terse"):
            # Of course, this will be inaccurate if packages are already
            # in the cache.  We try to do something reasonable if a
            # file size is missing.
            total_size = 0
            approximate = 0
            for p in install_packages:
                if p.has_key("package_filename") or p.has_key("package_data"):
                    continue

                sz = p.get("file_size", 0)
                total_size = total_size + sz
                if sz == 0:
                    approximate = 1
            for p in install_deps:
                p = extract_package(p)

                if p.has_key("package_filename") or p.has_key("package_data"):
                    continue

                sz = p.get("file_size", 0)
                total_size = total_size + sz
                if sz == 0:
                    approximate = 1

            if total_size > 0:
                size_str = rcformat.bytes_to_str(total_size)
                approx_str = ""
                if approximate:
                    approx_str = "at least "
                rctalk.message("This is %sa %s download." %
                               (approx_str, size_str))

    def confirm(self, options_dict, removals):
        if not options_dict.has_key("no-confirmation"):
            confirm = rctalk.prompt("Do you want to continue? [y/N]")
            if not confirm or not (confirm[0] == "y" or confirm[0] == "Y"):
                rctalk.message("Cancelled.")
                sys.exit(0)

        allow_remove = self.unattended_removals() \
                       or options_dict.has_key("allow-removals")

        if removals \
           and options_dict.has_key("no-confirmation") \
           and not allow_remove:
            rctalk.warning("Removals are required.  Use the -r option or "
                           "confirm interactively.")
            sys.exit(1)

    def check_licenses(self, server, packages):
        try:
            licenses = server.rcd.license.lookup_from_packages(packages)
        except ximian_xmlrpclib.Fault, f:
            if f.faultCode == rcfault.undefined_method:
                return
            else:
                raise

        if licenses:
            if len(licenses) > 1:
                lstr = "licenses"
            else:
                lstr = "license"
            rctalk.message("")
            rctalk.message("You must agree to the following %s before "
                           "installing this software:" % lstr)
            rctalk.message("")

            for l in licenses:
                rctalk.message(string.join(rcformat.linebreak(l, 72), "\n"))
                rctalk.message("")

            confirm = rctalk.prompt("Do you agree to the above "
                                    "%s? [y/N]" % lstr)
            if not confirm or not (confirm[0] == "y" or confirm[0] == "Y"):
                rctalk.message("Cancelled.")
                sys.exit(0)