Ejemplo n.º 1
0
 def get_use_flags(self, ebuild=None):
     """ Get use flags selected by user """
     if not ebuild:
         iter = self.combobox.get_active_iter()
         model = self.combobox.get_model()
         sel_ver = model.get_value(iter, 0)
         verInfo = self.get_verInfo(sel_ver)
         ebuild = verInfo["name"]
     flaglist = []
     ebuild_use_flags = get_reduced_flags(ebuild)
     for child in self.ufList:
         flag = child[1]
         if flag in ebuild_use_flags:
             flag_active = True
         else:
             flag_active = False
         if child[0].get_active():
             if not flag_active:
                 flaglist.append(flag)
         else:
             if flag_active:
                 flaglist.append('-' + flag)
     flags = ' '.join(flaglist)
     debug.dprint("ADVEMERGE: get_use_flags(); flags = %s" % str(flags))
     return flags
Ejemplo n.º 2
0
 def emerge_changed(self, widget):
     """ Swap between emerge and unmerge """
     debug.dprint("ADVEMERGE: emerge_changed()")
     iter = self.emerge_combobox.get_active_iter()
     model = self.emerge_combobox.get_model()
     self.emerge_unmerge = model.get_value(iter, 0)
     self.display_emerge_command()
Ejemplo n.º 3
0
 def get_verInfo(self, version):
     # Find selected version
     sel_ver = version.split(' ')[0]
     for x in range(len(self.verList)):
         ver = self.verList[x]
         if sel_ver == ver["number"]:
             verInfo = ver
             break
     if not verInfo:
         debug.dprint(
             "ADVEMERGE: get_verInfo(); freaking out! what's \"verInfo\"?")
         verInfo = "?"
     return verInfo
Ejemplo n.º 4
0
 def version_changed(self, widget):
     """ Version has changed, update the dialog window """
     debug.dprint("ADVEMERGE: changing version")
     iter = self.combobox.get_active_iter()
     model = self.combobox.get_model()
     sel_ver = model.get_value(iter, 0)
     if len(sel_ver) > 2:
         verInfo = self.current_verInfo = self.get_verInfo(sel_ver)
         # Reset use flags
         self.build_use_flag_widget(verInfo["use_flags"], verInfo["name"])
         # Reset keywords
         self.build_keywords_widget(verInfo["keywords"])
     self.display_emerge_command()
Ejemplo n.º 5
0
 def on_package_keywords_commit(self, button_widget):
     debug.dprint("ADVEMERGE: on_package_keywords_commit()")
     keyword = self.get_keyword()
     if not keyword: return
     addlist = [keyword]
     if keyword.startswith("-"):
         removelist = [keyword[1:]]
     else:
         removelist = ["-" + keyword]
     verInfo = self.current_verInfo
     ebuild = verInfo["name"]
     okay = db.userconfigs.set_user_config('package.keywords',
                                           ebuild=ebuild,
                                           add=addlist,
                                           remove=removelist,
                                           callback=self.reload)
Ejemplo n.º 6
0
 def on_package_use_commit(self, button_widget):
     debug.dprint("ADVEMERGE: on_package_use_commit()")
     use_flags = self.get_use_flags()
     if not use_flags: return
     addlist = use_flags.split()
     removelist = []
     for item in addlist:  # get opposite of flags
         if item.startswith('-'):
             removelist.append(item[1:])
         else:
             removelist.append('-' + item)
     okay = db.userconfigs.set_user_config('USE',
                                           name=self.package.full_name,
                                           add=addlist,
                                           remove=removelist,
                                           callback=self.reload,
                                           parent_window=self.window)
     self.version_changed(button_widget)
Ejemplo n.º 7
0
 def on_make_conf_commit(self, button_widget):
     debug.dprint("ADVEMERGE: on_make_conf_commit()")
     use_flags = self.get_use_flags()
     if not use_flags: return
     addlist = use_flags.split()
     removelist = []
     for item in addlist:  # get opposite of flags
         if item.startswith('-'):
             removelist.append(item[1:])
         else:
             removelist.append('-' + item)
     # set_user_config must be performed after set_make_conf has finished or we get problems.
     # we need to set package.use in case the flag was set there originally!
     package_use_callback = Dispatcher( db.userconfigs.set_user_config,\
             'USE', self.package.full_name, '', '', removelist, self.reload )
     portage_lib.set_make_conf('USE',
                               add=addlist,
                               remove=removelist,
                               callback=package_use_callback)
     self.version_changed(button_widget)
Ejemplo n.º 8
0
    def build_use_flag_widget(self, use_flags, ebuild):
        """ Create a table layout and populate it with 
            checkbox widgets representing the available
            use flags
        """
        debug.dprint("ADVEMERGE: build_use_flag_widget()")
        UseFlagFrame = self.wtree.get_widget("frameUseFlags")
        button_make_conf = self.wtree.get_widget("button_make_conf")
        button_package_use = self.wtree.get_widget("button_package_use")
        # If frame has any children, remove them
        child = UseFlagFrame.child
        if child != None:
            UseFlagFrame.remove(child)
        # If no use flags, hide the frame
        if not use_flags:
            UseFlagFrame.hide()
            self.btnMakeConf.hide()
            self.btnPkgUse.hide()
        else:
            UseFlagFrame.show()
            if self.is_root or utils.can_gksu():
                self.btnPkgUse.show()
                if config.Prefs.advemerge.show_make_conf_button:
                    self.btnMakeConf.show()
                else:
                    self.btnMakeConf.hide()
        # Build table to hold checkboxes
        size = len(use_flags)
        maxcol = 3  # = number of columns - 1 = index of last column
        maxrow = (size - 1) / (maxcol + 1)  # = number of rows - 1
        # resize the table if it's taller than it is wide
        table = gtk.Table(maxrow + 1, maxcol + 1, True)
        if maxrow + 1 >= 6:  # perhaps have this number configurable?
            # perhaps add window based on size (in pixels) of table somehow...
            scrolledwindow = gtk.ScrolledWindow()
            scrolledwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
            UseFlagFrame.add(scrolledwindow)
            scrolledwindow.add_with_viewport(table)
            scrolledwindow.set_size_request(1, 100)  # min height of 100 pixels
            scrolledwindow.show()
        else:
            UseFlagFrame.add(table)

        self.ufList = []

        # Iterate through use flags collection, create checkboxes
        # and attach to table
        col = 0
        row = 0
        ebuild_use_flags = get_reduced_flags(ebuild)
        for flag in use_flags:
            flag_active = False
            myflag = abs_flag(flag)
            if myflag in ebuild_use_flags:
                flag_active = True
            button = gtk.CheckButton(flag)
            button.set_use_underline(False)
            button.set_active(flag_active)
            self.ufList.append([button, flag])

            # Add tooltip, attach button to table and show it off
            # Use lower case flag, since that is how it is stored
            # in the UseFlagDict.  In case flag doesn't exist
            # we'll trap the error
            button.set_has_tooltip(True)
            try:
                button.set_tooltip_text(
                    portage_lib.settings.UseFlagDict[flag.lower()][2])
            except KeyError:
                button.set_tooltip_text(_('Unsupported use flag'))
            table.attach(button, col, col + 1, row, row + 1)
            # connect to on_toggled so we can show changes
            button.connect("toggled", self.on_toggled)
            button.show()
            # Increment col & row counters
            col += 1
            if col > maxcol:
                col = 0
                row += 1

        # Display the entire table
        table.show()
Ejemplo n.º 9
0
    def __init__(self, package, setup_command, re_init_portage):
        """ Initialize Advanced Emerge Dialog window """
        # Preserve passed parameters
        self.package = package
        self.setup_command = setup_command
        self.re_init_portage = re_init_portage
        self.arch = portage_lib.get_arch()
        self.system_use_flags = portage_lib.settings.SystemUseFlags
        self.emerge_unmerge = "emerge"
        self.is_root = utils.is_root()
        self.package_use_flags = db.userconfigs.get_user_config(
            'USE', package.full_name)
        self.current_verInfo = None

        # Parse glade file
        self.gladefile = config.Prefs.DATA_PATH + "glade/advemerge.glade"
        self.wtree = gtk.glade.XML(self.gladefile, "adv_emerge_dialog",
                                   config.Prefs.APP)

        # register callbacks
        callbacks = {
            "on_ok_clicked":
            self.ok_clicked,
            "on_help_clicked":
            self.help_clicked,
            "on_cancel_clicked":
            self.cancel_clicked,
            #"on_cbAsk_clicked": self.Ask_clicked,
            "on_cbOnlyDeps_clicked":
            (self.set_one_of, 'cbOnlyDeps', 'cbNoDeps'),
            "on_cbNoDeps_clicked": (self.set_one_of, 'cbNoDeps', 'cbOnlyDeps'),
            "on_cbQuiet_clicked": (self.set_one_of, 'cbQuiet', 'cbVerbose'),
            "on_cbVerbose_clicked": (self.set_one_of, 'cbVerbose', 'cbQuiet'),
            "on_cbBuildPkg_clicked":
            (self.set_one_of, 'cbBuildPkg', 'cbBuildPkgOnly'),
            "on_cbBuildPkgOnly_clicked":
            (self.set_one_of, 'cbBuildPkgOnly', 'cbBuildPkg'),
            "on_cbUsePkg_clicked":
            (self.set_one_of, 'cbUsePkg', 'cbUsePkgOnly'),
            "on_cbUsePkgOnly_clicked": (self.set_one_of, 'cbUsePkgOnly',
                                        'cbUsePkg'),
            "on_cmbVersion_changed":
            self.version_changed,
            "on_cmbEmerge_changed":
            self.emerge_changed,
            "on_btnPkgUse_clicked":
            self.on_package_use_commit,
            "on_btnMakeConf_clicked":
            self.on_make_conf_commit,
            "on_btnPkgKeywords_clicked":
            self.on_package_keywords_commit,
            "on_cbColorY_clicked": (self.set_one_of, 'cbColorY', 'cbColorN'),
            "on_cbColorN_clicked": (self.set_one_of, 'cbColorN', 'cbColorY'),
            "on_cbColumns_clicked": (self.set_all, 'cbColumns', 'cbPretend'),
            'on_cbWithBDepsY_clicked': (self.set_one_of, 'cbWithBDepsY',
                                        'cbWithBDepsN'),
            'on_cbWithBDepsN_clicked': (self.set_one_of, 'cbWithBDepsN',
                                        'cbWithBDepsY'),
            'on_cbGetBinPkg_clicked': (self.set_one_of, 'cbGetBinPkg',
                                       'cbGetBinPkgOnly'),
            'on_cbGetBinPkgOnly_clicked': (self.set_one_of, 'cbGetBinPkgOnly',
                                           'cbGetBinPkg'),
            "on_toggled":
            self.on_toggled
        }

        self.wtree.signal_autoconnect(callbacks)
        self.window = self.wtree.get_widget("adv_emerge_dialog")
        self.use_flags_frame = self.wtree.get_widget("frameUseFlags")
        self.keywords_frame = self.wtree.get_widget("frameKeywords")
        self.window.set_title(
            _("Advanced Emerge Settings for %s") % package.full_name)

        self.command_textview = self.wtree.get_widget("command_textview")
        self.command_buffer = self.command_textview.get_buffer()
        style = self.keywords_frame.get_style().copy()
        self.bgcolor = style.bg[gtk.STATE_NORMAL]
        self.command_textview.modify_base(gtk.STATE_NORMAL, self.bgcolor)

        self.btnMakeConf = self.wtree.get_widget("btnMakeConf")
        self.btnPkgUse = self.wtree.get_widget("btnPkgUse")
        self.btnPkgKeywords = self.wtree.get_widget("btnPkgKeywords")
        if not self.is_root and not utils.can_gksu():
            debug.dprint("ADVEMERGE: self.is_root = $s, utils.can_gksu = %s" %
                         (self.is_root, utils.can_gksu))
            self.btnMakeConf.hide()
            self.btnPkgUse.hide()
            self.btnPkgKeywords.hide()

        # Connect option toggles to on_toggled
        for checkbutton in self.wtree.get_widget("table2").get_children():
            if isinstance(checkbutton, gtk.CheckButton):
                checkbutton.connect("toggled", self.on_toggled)
            #else:
            #    debug.dprint("ADVEMERGE: table2 has child not of type gtk.CheckButton")
            #    debug.dprint(checkbutton)

        if not config.Prefs.advemerge.showuseflags:
            self.use_flags_frame.hide()
        if not config.Prefs.advemerge.showkeywords:
            self.keywords_frame.hide()

        # Make tool tips available
        #self.tooltips = gtk.Tooltips()

        # Build version combo list
        self.get_versions()

        # Build a formatted combo list from the versioninfo list
        self.comboList = gtk.ListStore(str)
        index = 0
        for x in range(len(self.verList)):
            ver = self.verList[x]
            info = ver["number"]
            slot = ver["slot"]
            if slot != '0':
                info += ''.join(['   [', _('Slot:%s') % slot, ']'])
            if not ver["available"]:
                info += _('   {unavailable}')
            elif not ver["stable"]:
                info += _('   (unstable)')
            if ver["hard_masked"]:
                info += _('   [MASKED]')
            if ver["best"]:
                if ver["best_downgrades"]:
                    info += _('   (recommended) (downgrade)')
                else:
                    info += _('   (recommended)')
                index = x
            if ver["installed"]:
                info += _('   [installed]')

            self.comboList.append([info])

        # Build version combobox
        self.combobox = self.wtree.get_widget("cmbVersion")
        self.combobox.set_model(self.comboList)
        cell = gtk.CellRendererText()
        self.combobox.pack_start(cell, True)
        self.combobox.add_attribute(cell, 'text', 0)
        self.combobox.set_active(
            index)  # select "recommended" ebuild by default

        # emerge / unmerge combobox:
        self.emerge_combolist = gtk.ListStore(str)
        iter = self.emerge_combolist.append(["emerge"])
        self.emerge_combolist.append(["unmerge"])
        self.emerge_combobox = self.wtree.get_widget("cmbEmerge")
        self.emerge_combobox.set_model(self.emerge_combolist)
        cell = gtk.CellRendererText()
        self.emerge_combobox.pack_start(cell, True)
        self.emerge_combobox.add_attribute(cell, 'text', 0)
        self.emerge_combobox.set_active_iter(iter)

        # Set any emerge options the user wants defaulted
        if config.Prefs.emerge.pretend:
            self.wtree.get_widget("cbPretend").set_active(True)
        if config.Prefs.emerge.verbose:
            self.wtree.get_widget("cbVerbose").set_active(True)
        ## this now just references --update, which is probably not the desired behaviour.
        ## perhaps the current version should be indicated somewhere in the dialog
        #if config.Prefs.emerge.upgradeonly:
        #    self.wtree.get_widget("cbUpgradeOnly").set_active(True)
        if config.Prefs.emerge.fetch:
            self.wtree.get_widget("cbFetchOnly").set_active(True)
        if config.Prefs.emerge.nospinner:
            self.wtree.get_widget("cbNoSpinner").set_active(True)

        # show command in command_label
        self.display_emerge_command()