示例#1
0
 def get_useflags(self, ebuild):
     """returns a list of the useflags that are configured for the ebuild"""
     atoms = self.get_atom('USE', None, ebuild)
     myflags = []
     for atom in atoms:
         myflags = myflags + atom.value
     myflags = reduce_flags(myflags)
     return myflags
示例#2
0
    def update_package_info(self, package, _ebuild=None):
        """ Update the notebook of information about a selected package """

        ######################################
        # Begin supporting internal functions

        def append(text, tag=None):
            """ Append (unicode) text to summary buffer """
            iter = self.buffer.get_end_iter()
            buffer = self.buffer
            if tag: buffer.insert_with_tags_by_name(iter, text, tag)
            else: buffer.insert(iter, text)

        def append_url(text, url, colour):
            """ Append URL to textbuffer and connect an event """
            tag = self.buffer.create_tag(url)
            tag.set_property("foreground", colour)
            tag.connect("event", self.on_url_event)
            self.url_tags.append(tag)
            append(text, tag.get_property("name"))

        def nl(x=1):
            """ Append x new lines to the buffer """
            append("\n" * x)

        def show_vnums(ebuilds, show_all=False):
            spam = []
            oldslot = -1
            first_ebuild = True
            for ebuild in ebuilds:
                # set the tag to the default
                tag = "value"
                version = portage_lib.get_version(ebuild)
                keys = package.get_properties(ebuild).get_keywords()
                if not show_all and self.myarch not in keys and ''.join(
                    ['~', self.myarch]) not in keys:
                    # we won't display the ebuild if it's not available to us
                    continue
                slot = portage_lib.get_property(ebuild, "SLOT")
                if not slot == oldslot:
                    if spam:
                        #append(", ".join(spam), "value")
                        nl()
                        spam = []
                    if slot != '0':
                        append(_("\tSlot %s: ") % slot, "property")
                    else:
                        append("\t", "property")
                    oldslot = slot
                    first_ebuild = True

                if not first_ebuild:
                    append(", ", "value")

                if ebuild not in nonmasked:
                    if ebuild in hardmasked:
                        version = "![" + version + "]"
                        # set the tag to highlight this version
                        tag = "useunset"  # fixme:  need to make this user settable and different from use flags
                    else:
                        version = "~(" + version + ")"
                        # set the tag to highlight this version
                        tag = "useset"  # fixme:  need to make this user settable and different from use flags
                append(version, tag)
                first_ebuild = False
                spam += [version
                         ]  # now only used to track the need for a new slot
            if first_ebuild:  # only still true if no ebuilds were acceptable
                append(_('\tNone'), 'value')
            #append(", ".join(spam), "value")
            return

        def create_ebuild_table(versions):
            myarch = self.myarch
            ebuilds = versions[:]  # make a copy
            while '' in ebuilds:
                ebuilds.remove('')
            modified = False
            for entry in installed:
                if entry not in ebuilds:
                    debug.dprint(
                        "SUMMARY; create_ebuild_table(): adding %s to ebuild list %s"
                        % (entry, str(ebuilds)))
                    ebuilds.append(entry)
                    modified = True
            if modified:
                ebuilds = ver_sort(ebuilds)  # otherwise already sorted

            if config.Prefs.globals.enable_archlist:
                archlist = config.Prefs.globals.archlist
                debug.dprint(
                    "SUMMARY: create_ebuild_table: creating archlist enabled table for: "
                    + str(archlist))
            else:
                archlist = [myarch]
                debug.dprint(
                    "SUMMARY: create_ebuild_table: creating single arch table for: "
                    + str(archlist))
            #if True: # saves an unindent for testing change
            rows = 1 + len(ebuilds)
            cols = 3 + len(archlist)
            table = gtk.Table(rows, cols)
            table.attach(boxify(gtk.Label(), "white"), 0, 1, 0, 1)
            label = gtk.Label(_("Slot"))
            label.set_padding(3, 3)
            table.attach(boxify(label, "#EEEEEE"), 1, 2, 0, 1)
            label = gtk.Label(_("Overlay"))
            label.set_padding(3, 3)
            table.attach(boxify(label, "#EEEEEE"), 2, 3, 0, 1)
            x = 2
            for arch in archlist:
                debug.dprint("SUMMARY: create_ebuild_table: arch is: " +
                             str(arch))
                x += 1
                label = gtk.Label(arch)
                label.set_padding(3, 3)
                table.attach(boxify(label, "#EEEEEE"), x, x + 1, 0, 1)
            y = rows
            for ebuild in ebuilds:
                y -= 1
                version = portage_lib.get_version(ebuild)
                ver_label = gtk.Label(str(version))
                ver_label.set_padding(3, 3)
                # slot column
                slot = package.get_properties(ebuild).get_slot()
                slot_label = gtk.Label(str(slot))
                slot_label.set_padding(3, 3)
                # overlay column
                overlay = portage_lib.get_overlay(ebuild)
                if type(overlay) is IntType:  # catch obsolete
                    overlay = _("Ebuild version no longer supported")
                    overlay_label = gtk.Label(_("Obsolete"))
                    label_color = "#ED9191"
                else:
                    overlay_label = gtk.Label(
                        portage_lib.get_overlay_name(overlay))
                    #~ if overlay != portage_lib.settings.portdir:
                    #~ overlay_label = gtk.Label(_("Y"))
                    #~ else:
                    #~ overlay_label = gtk.Label(_("N"))
                    label_color = "#EEEEEE"
                overlay_label.set_padding(3, 3)
                box = boxify(overlay_label, label_color)
                box.set_has_tooltip(True)
                box.set_tooltip_text(overlay)
                # attach version, slot and overlay columns
                table.attach(
                    boxify(ver_label, label_color, ebuild, '.', "version"), 0,
                    1, y, y + 1)
                table.attach(boxify(slot_label, label_color), 1, 2, y, y + 1)
                table.attach(box, 2, 3, y, y + 1)

                keys = package.get_properties(ebuild).get_keywords()
                x = 2
                for arch in archlist:
                    x += 1
                    if "".join(["~", arch]) in keys:
                        text = "~"
                        color = "#EEEE90"
                    elif arch in keys:
                        text = "+"
                        color = "#90EE90"
                    else:
                        text = "-"
                        color = "#EEEEEE"
                    if ebuild in hardmasked and text != "-":
                        text = "".join(["M", text])
                        color = "#ED9191"
                    if ebuild in installed and arch == myarch:
                        color = "#9090EE"
                    #debug.dprint("SUMMARY: create_ebuild_table(); self.keyword_unmasked[ebuild] = " + str(self.keyword_unmasked[ebuild]))
                    if (ebuild in self.keyword_unmasked and '~' in text
                            and ('~' + arch in self.keyword_unmasked[ebuild]
                                 or self.keyword_unmasked[ebuild] == [])):
                        # take account of package.keywords in text but leave colour unchanged
                        text = text.replace('~', '(+)')
                    if ebuild in package_unmasked and 'M' in text:
                        text = '[' + text.replace('M', '') + ']'
                    label = gtk.Label(text)
                    box = boxify(label,
                                 color=color,
                                 ebuild=ebuild,
                                 arch=arch,
                                 text=text)
                    if "M" in text or "[" in text:
                        box.set_has_tooltip(True)
                        box.set_tooltip_text(
                            portage_lib.get_masking_reason(ebuild))
                    table.attach(box, x, x + 1, y, y + 1)
            table.set_row_spacings(1)
            table.set_col_spacings(1)
            table.set_border_width(1)
            tablebox = boxify(table, "darkgrey")
            tablebox.show_all()
            iter = self.buffer.get_end_iter()
            anchor = self.buffer.create_child_anchor(iter)
            self.add_child_at_anchor(tablebox, anchor)
            nl(2)

        def boxify(label, color=None, ebuild=None, arch=None, text=None):
            box = gtk.EventBox()
            box.add(label)
            if color:
                style = box.get_style().copy()
                style.bg[gtk.STATE_NORMAL] = gtk.gdk.color_parse(color)
                box.set_style(style)
            if ebuild:
                box.color = color
                box.ebuild = ebuild
                box.arch = arch
                box.text = text
                box.connect("button-press-event", self.on_table_clicked)
                box.connect("enter-notify-event", self.on_table_mouse)
                box.connect("leave-notify-event", self.on_table_mouse)
            return box

        def show_props(ebuild):
            # Use flags
            ebuild_use_flags = get_reduced_flags(ebuild)
            # parent module defined use_flags
            if use_flags and config.Prefs.summary.showuseflags:
                #debug.dprint("SUMMARY: SHOW_PROPS(); use_flags = " +str(use_flags))
                final_use, use_expand_hidden, usemasked, useforced = portage_lib.get_cpv_use(
                    ebuild)
                iuse_output = False
                myflags = filter_flags(iuse, use_expand_hidden, usemasked,
                                       useforced)
                if myflags != []:
                    iuse_output = True
                    append(_("IUSE: "), "property")
                    append(", ".join(myflags))
                    nl()
                myflags = filter_flags(use_flags, use_expand_hidden, usemasked,
                                       useforced)
                if myflags != []:
                    append(_("Use flags settings: "), "property")
                    show_flags(myflags, ebuild_use_flags)
                    nl()
                myflags = filter_flags(final_use, use_expand_hidden, usemasked,
                                       useforced)
                if myflags != [] or iuse_output:
                    append(_("Final environment Use flags: "), "property")
                    show_flags(myflags, ebuild_use_flags, id_overrides=True)
                    nl(2)

            # Keywords
            if keywords and config.Prefs.summary.showkeywords:
                append(_("Keywords: "), "property")
                first_keyword = True
                for keyword in keywords:
                    if not first_keyword:
                        append(", ", "value")
                    else:
                        first_keyword = False
                    append(keyword, "value")
                nl(2)

            # License
            if licenses and config.Prefs.summary.showlicense:
                append(_("License: "), "property")
                _licenses = licenses.split()
                x = 0
                for license in _licenses:
                    if license not in ["||", "(", ")"]:
                        if x > 0:
                            append(', ')
                        append_url(license, self.license_dir + license, "blue")
                        x += 1
                nl()

        def show_flags(use_flags,
                       ebuild_use_flags,
                       id_overrides=False,
                       first_flag=True):
            """runs through the list of flags and formats and prints them"""
            #debug.dprint("SUMMARY: SHOW_PROPS(),show_flags(); use_flags = " +str( use_flags) + ", ebuild_use_flags = " + str(ebuild_use_flags))
            #first_flag = True
            if id_overrides:
                full_list = abs_list(iuse)
            else:
                full_list = []
            for flag in use_flags:
                if id_overrides:
                    debug.dprint(
                        "SUMMARY: SHOW_PROPS(),show_flags(); flag = " +
                        str(flag) + " " + str(full_list))
                else:
                    debug.dprint(
                        "SUMMARY: SHOW_PROPS(),show_flags(); flag = " +
                        str(flag))
                # Check to see if flag applies:
                flag_active = False
                myflag = abs_flag(flag)
                if myflag in ebuild_use_flags:
                    debug.dprint(
                        "SUMMARY: SHOW_PROPS(),show_flags(); flag in ebuild_use_flags = True"
                    )
                    flag_active = True
                elif '-' + myflag in ebuild_use_flags:
                    flag = '-' + myflag
                if not first_flag:
                    append(", ", "value")
                else:
                    first_flag = False
                show_flag(flag, flag_active, id_overrides)
                if myflag in full_list:
                    full_list.remove(myflag)
                else:
                    debug.dprint(
                        "SUMMARY: SHOW_PROPS(),show_flags(); flag in full_list: "
                        + myflag)
            if id_overrides and len(full_list):
                # print remaining flags
                for flag in full_list:
                    if not first_flag:
                        append(", ", "value")
                    else:
                        first_flag = False
                    flag_override = False
                    if flag in ebuild_use_flags:
                        debug.dprint(
                            "SUMMARY: SHOW_PROPS(),show_flags(); flag_override = True"
                        )
                        flag_override = True
                    elif '-' + flag in ebuild_use_flags:
                        flag = '-' + flag
                    show_flag(flag, False, flag_override)

        def show_flag(flag, flag_active, id_overrides):
            # Added +/- for color impaired folks
            if not id_overrides:
                if flag_active:
                    if flag.startswith('+'):
                        append(flag, "useset")
                    else:
                        append('+' + flag, "useset")
                else:
                    if flag.startswith('-'):
                        append(flag, "useunset")
                    else:
                        append('-' + flag, "useunset")
            else:  # id the overrides
                #if flag_active:
                if flag.startswith('+'):
                    append("(" + flag + ")", "useset")
                elif not flag.startswith('-'):
                    append('+' + flag, "useset")
                else:
                    if flag.startswith('-'):
                        append("(" + flag + ")", "useunset")
                    else:
                        append('-' + flag, "useunset")

        def show_configs(ebuild):
            append(_("User Configs: "), "property")
            nl()
            for type in self.config_types:
                append('\t' + type + ': ', "property")
                config_atoms = db.userconfigs.get_atom(type, None, ebuild)
                if len(config_atoms):
                    line = 0
                    for atom in config_atoms:
                        if line > 0:
                            append('\t\t\t   ', "property")
                        append(str(atom), "value")
                        nl()
                        line += 1
                else:
                    append(_("None"))
                    nl()

        # End supporting internal functions
        ####################################

        # build info into buffer
        self.buffer.set_text("", 0)
        if not package:
            # Category is selected, just exit
            return

        self.package = package

        # Get the package info
        #debug.dprint("SUMMARY: get package info")
        metadata = package.get_metadata()
        installed = self.installed = package.get_installed()
        debug.dprint("SUMMARY: installed = " + str(installed))
        versions = package.get_versions()
        debug.dprint("SUMMARY: versions = " + str(versions))
        nonmasked = package.get_versions(include_masked=False)
        debug.dprint("SUMMARY: nonmasked = " + str(nonmasked))

        # added by Tommy
        hardmasked = package.get_hard_masked()
        #self.keyword_unmasked = portage_lib.get_keyword_unmasked_ebuilds(
        #                    archlist=config.Prefs.globals.archlist, full_name=package.full_name)
        debug.dprint("SUMMARY: get package info, name = " + package.full_name)
        self.keyword_unmasked = db.userconfigs.get_user_config(
            'KEYWORDS', name=package.full_name)
        package_unmasked = db.userconfigs.get_user_config(
            'UNMASK', name=package.full_name)

        best = portage_lib.get_best_ebuild(package.full_name)
        debug.dprint("SUMMARY: best = %s" % best)
        if _ebuild:
            self.ebuild = _ebuild
        else:
            if best == "":  # all versions are masked and the package is not installed
                debug.dprint("SUMMARY: best = '', getting latest ebuild")
                self.ebuild = package.get_latest_ebuild(
                    True)  # get latest masked version
            else:
                self.ebuild = best
        #debug.dprint("SUMMARY: getting properties for ebuild version %s" %ebuild)
        props = package.get_properties(self.ebuild)
        iuse = props.get_use_flags()
        description = props.description
        homepages = props.get_homepages()  # may be more than one
        #debug.dprint("SUMMARY: Summary; getting use flags")
        use_flags = reduce_flags(iuse)
        keywords = props.get_keywords()
        licenses = props.license
        slot = unicode(props.get_slot())

        # Sort the versions in release order
        versions = ver_sort(versions)

        # Get the tag table and remove all URL tags
        table = self.buffer.get_tag_table()
        for tag in self.url_tags:
            table.remove(tag)
        self.url_tags = []

        # get system use flags
        system_use_flags = portage_lib.settings.SystemUseFlags

        #############################
        # Begin adding text to tab
        #############################

        # Full package name
        append(package.full_name, "name")
        nl()

        # Description, if available
        if description:
            append(description, "description")
            nl(2)

        # Metadata long description(s), if available
        if metadata and metadata.longdescription and config.Prefs.summary.showlongdesc:
            append(_("Long Description: "), "property")
            append(metadata.longdescription, "description")
            nl(2)

        # Insert homepage(s), if any
        x = 0
        if homepages and config.Prefs.summary.showurl:
            for homepage in homepages:
                if x > 0:
                    append(', ')
                append_url(homepage, homepage, "blue")
                x += 1
            nl(2)

        # display a table of architectures and support / stability
        # like on packages.gentoo.org :)
        if config.Prefs.summary.showtable: create_ebuild_table(versions)

        # Installed version(s)
        if config.Prefs.summary.showinstalled:
            if installed:
                append(_("Installed versions:\n"), "property")
                show_vnums(installed, show_all=True)
                nl(2)
            else:
                append(_("Not installed"), "property")
                nl(2)

        # Remaining versions
        if versions and config.Prefs.summary.showavailable:
            append(_("Available versions for %s:\n") % self.myarch, "property")
            show_vnums(versions)
            nl(2)

        append(_("Properties for version: "), "property")
        append(portage_lib.get_version(self.ebuild))
        nl(2)
        show_props(self.ebuild)
        nl()
        show_configs(self.ebuild)