Beispiel #1
0
def set_user_config( file, name='', ebuild='', add='', remove='', callback=None):
    """depricated function. this is now part of the db.user_configs module
    Function for parsing package.use, package.mask, package.unmask
    and package.keywords.

    Adds <name> or '=' + <ebuild> to <file> with flags <add>.
    If an existing entry is found, items in <remove> are removed and <add> is added.
    
    If <name> and <ebuild> are not given then lines starting with something in
    remove are removed, and items in <add> are added as new lines.
    """
    debug.dprint("PORTAGELIB: DEPRICATED FUNCTION! set_user_config(); depricated update calling code to use the db.user_configs module")
    command = ''
    maskfiles = ['package.mask', 'package.unmask']
    otherfiles = ['package.use', 'package.keywords']
    package_files = otherfiles + maskfiles
    if file not in package_files:
        debug.dprint(" * PORTAGELIB: set_user_config(); unsupported config file '%s'" % file)
        return False
    if isinstance(add, list):
        add = ' '.join(add)
    if isinstance(remove, list):
        remove = ' '.join(remove)
    config_path = portage_const.USER_CONFIG_PATH
    if not os.access(config_path, os.W_OK):
        commandlist = [config.Prefs.globals.su, '"python', config.Prefs.DATA_PATH + 'backends/set_config.py -d -f %s' %file]
        if name != '':
            commandlist.append('-n %s' %name)
        if ebuild != '':
            commandlist.append('-e %s' %ebuild)
        if add != '':
            items = add.split()
            for item in items:
                commandlist.append('-a %s' % item)
        if remove != '':
            items = remove.split()
            for item in items:
                commandlist.append('-r %s' % item)
        command = ' '.join(commandlist) + '"'
        debug.dprint(" * PORTAGELIB: set_user_config(); command = %s" %command )
        if not callback: callback = reload_portage
        app = SimpleTerminal(command, False, dprint_output='SET_USER_CONFIG CHILD APP: ', callback=Dispatcher(callback))
        app._run()
    else:
        add = add.split()
        remove = remove.split()
        set_config.set_user_config(file, name, ebuild, add, remove)
        if callback: callback()
        else: reload_portage()
    # This is slow, but otherwise portage doesn't notice the change.
    #reload_portage()
    # Note: could perhaps just update portage.settings.
    # portage.settings.pmaskdict, punmaskdict, pkeywordsdict, pusedict
    # or portage.portdb.mysettings ?
    return True
Beispiel #2
0
def set_make_conf(property, add='', remove='', replace='', callback=None):
    """
    Sets a variable in make.conf.
    If remove: removes elements of <remove> from variable string.
    If add: adds elements of <add> to variable string.
    If replace: replaces entire variable string with <replace>.

    if remove contains the variable name, the whole variable is removed.

    e.g. set_make_conf('USE', add=['gtk', 'gtk2'], remove=['-gtk', '-gtk2'])
    e.g. set_make_conf('ACCEPT_KEYWORDS', remove='ACCEPT_KEYWORDS')
    e.g. set_make_conf('PORTAGE_NICENESS', replace='15')
    """
    debug.dprint("PORTAGELIB: set_make_conf()")
    command = ''
    _file = 'make.conf'
    if isinstance(add, list):
        add = ' '.join(add)
    if isinstance(remove, list):
        remove = ' '.join(remove)
    if isinstance(replace, list):
        replace = ' '.join(replace)
    if not os.access(os.path.join(portage.root, portage_const.MAKE_CONF_FILE),
                     os.W_OK):
        command = (config.Prefs.globals.su + ' "python ' +
                   config.Prefs.DATA_PATH +
                   'backends/set_config.py -d -f %s ' % _file)
        command = (command + '-p %s ' % property)
        if add != '':
            command = (command + '-a %s ' % ("'" + add + "'"))
        if remove != '':
            command = (command + '-r %s' % ("'" + remove + "'"))
        command = command + '"'
        debug.dprint(" * PORTAGELIB: set_make_conf(); command = %s" % command)
        if not callback:
            callback = reload_portage
        dispatcher = Dispatcher(callback)
        app = SimpleTerminal(command,
                             False,
                             dprint_output='SET_MAKE_CONF CHILD APP: ',
                             callback=dispatcher)
        app._run()
        del dispatcher
    else:
        add = add.split()
        remove = remove.split()
        set_config.set_make_conf(property, add, remove, replace)
        if callback: callback()
        else: reload_portage()
    # This is slow, but otherwise portage doesn't notice the change.
    #reload_portage()
    # Note: could perhaps just update portage.settings.
    # portage.settings.pmaskdict, punmaskdict, pkeywordsdict, pusedict
    # or portage.portdb.settings ?
    return True
Beispiel #3
0
 def get_system_list( self, emptytree = False ):
     debug.dprint("READERS: UpgradableListReader; getting system package list")
     if emptytree:
         self.terminal = SimpleTerminal(self.system_cmd, need_output=True,  dprint_output='', callback=None)
         self.terminal._run()
         debug.dprint("READERS: UpgradableListReader; waiting for an 'emerge -ep system'...")
         while self.terminal.reader.process_running:
             time.sleep(0.10)
         self.categories[_("System")] = self.make_list(self.terminal.reader.string)
     else:
         self.categories[_("System")] = backends.portage_lib.get_system_pkgs()
     self.progress = 2
     debug.dprint("READERS: UpgradableListReader; new system pkg list %s" %str(self.categories[_("System")]))
Beispiel #4
0
def run_as_root(*args):
    global app, command
    if privileges.can_su:
        app = SimpleTerminal(command, True, dprint_output='Etc=proposals Plug-in;')
        app._run()
    else:
        app = SimpleTerminal(config.Prefs.globals.su + ' ' +command, True, dprint_output='Etc=proposals Plug-in;')
        app._run()
Beispiel #5
0
def run_as_root(*args):
    global app, command
    debug.dprint(plugin_name + " running command: '%s'" %(command)) 
    if privileges.can_su:
        app = SimpleTerminal(command, True, dprint_output='Gpytage Plug-in;')
        app._run()
    else:
        app = SimpleTerminal(config.Prefs.globals.su + ' ' +command, True, dprint_output='Gpytage Plug-in;')
        app._run()
Beispiel #6
0
def run_as_user(*args):
    global app, command
    app = SimpleTerminal(command, False)
    app._run()
Beispiel #7
0
class UpgradableListReader(CommonReader):
    """ Read available upgrades and store them in a tuple """
    def __init__(self, installed, sets=None):
        """ Initialize """
        CommonReader.__init__(self)
        self.installed_items = installed
        ##self.upgrade_only = upgradeonly
        self.sets = sets
        self.reader_type = "Upgradable"
        #self.world = []
        # hack for statusbar updates
        self.progress = 1
        # beginnings of multiple listings for packages in priority order
        # lists could be passed into the function and result in the following
        # eg self.categories = ["Tool Chain", _("System"), _("Sets"), _("World"), _("Dependencies")]
        self.cat_order = [_("System"), _("World"), _("Dependencies")]
        self.categories = {
            _("System"): None,
            _("World"): "World",
            _("Dependencies"): "Dependencies"
        }
        self.pkg_dict = {}
        self.pkg_count = {}
        self.count = 0
        self.pkg_dict_total = 0
        # command lifted fom emwrap and emwrap.sh
        self.system_cmd = "emerge -ep --nocolor --nospinner system | cut -s -f2 -d ']'| cut -f1 -d '[' | sed 's/^[ ]\+//' | sed 's/[ ].*$//'"
        #self.start = self.run

    def run(self):
        """fill upgrade tree"""
        debug.dprint(
            "READERS: UpgradableListReader(); process id = %d *******************"
            % os.getpid())
        print >> stderr, "READERS: UpgradableListReader(); threading.enumerate() = ", threading.enumerate(
        )
        print >> stderr, "READERS: UpgradableListReader(); this thread is :", thread.get_ident(
        ), ' current thread ', threading.currentThread()
        self.get_system_list()
        self.get_sets()
        for key in self.cat_order:
            self.pkg_dict[key] = {}
            self.pkg_count[key] = 0
        ##upgradeflag = self.upgrade_only and True or False
        # find upgradable packages
        for cat, packages in self.installed_items:
            for name, package in packages.items():
                self.count += 1
                if self.cancelled:
                    self.done = True
                    return
                upgradable = package.is_upgradable()
                # if upgradable: # is_upgradable() = 1 for upgrade, -1 for downgrade
                if upgradable == 1 or upgradable == -1:
                    for key in self.cat_order:
                        if package.in_list(self.categories[key]):
                            self.pkg_dict[key][package.full_name] = package
                            self.pkg_count[key] += 1
                            break
        self.pkg_dict_total = 0
        for key in self.pkg_count:
            self.pkg_dict_total += self.pkg_count[key]
            if self.pkg_dict[key] == {}:
                pkg = Package(_("None"))
                self.pkg_dict[key][_("None")] = pkg
                self.pkg_count[key] = 0
        debug.dprint("READERS: UpgradableListReader(); new pkg_dict = " +
                     str(self.pkg_dict))
        debug.dprint("READERS: UpgradableListReader(); new pkg_counts = " +
                     str(self.pkg_count))
        # set the thread as finished
        self.done = True
        return

    def get_system_list(self, emptytree=False):
        debug.dprint(
            "READERS: UpgradableListReader; getting system package list")
        if emptytree:
            self.terminal = SimpleTerminal(self.system_cmd,
                                           need_output=True,
                                           dprint_output='',
                                           callback=None)
            self.terminal._run()
            debug.dprint(
                "READERS: UpgradableListReader; waiting for an 'emerge -ep system'..."
            )
            while self.terminal.reader.process_running:
                time.sleep(0.10)
            self.categories[_("System")] = self.make_list(
                self.terminal.reader.string)
        else:
            self.categories[_("System")] = portage_lib.get_system_pkgs()
        self.progress = 2
        debug.dprint("READERS: UpgradableListReader; new system pkg list %s" %
                     str(self.categories[_("System")]))

    def make_list(self, from_string):
        """parse terminal output and return a list"""
        list1 = from_string.split('\n')
        list2 = []
        for pkg in list1:
            list2.append(portage_lib.get_full_name(pkg.rstrip("\r")))
        return list2

    def get_sets(self):
        """Get any package lists stored in the /etc/portage/sets directory
           and add them to the categories list"""
        sets_list = []
        for key in db.userconfigs.get_source_keys("SETS"):
            name = get_set_name(key)
            self.categories[_("Sets") + "-" +
                            name] = db.userconfigs.get_source_cplist(
                                "SETS", key)
            sets_list.append(_("Sets") + "-" + name)
        self.cat_order = [_("System")] + sets_list + [
            _("World"), _("Dependencies")
        ]
        return  #sets_lists
Beispiel #8
0
def run_as_user(*args):
    global app, command
    app = SimpleTerminal(command, True, dprint_output='Gpytage Plug-in;')
    app._run()
Beispiel #9
0
    def set_user_config(self,
                        mytype,
                        name='',
                        ebuild='',
                        add='',
                        remove='',
                        callback=None,
                        parent_window=None,
                        *comment):
        """
        Adds <name> or '=' + <ebuild> to <file> with flags <add>.
        If an existing entry is found, items in <remove> 
        are removed and <add> is added.
        
        If <name> and <ebuild> are not given then lines starting with 
        something in remove are removed, and items in <add> are added
        as new lines.
        """
        debug.dprint("USER_CONFIGS: set_user_config()")
        self.set_callback = callback
        self.set_type = mytype
        command = ''
        if mytype not in CONFIG_TYPES:
            debug.dprint("USER_CONFIGS: set_user_config(): unsupported " +
                         "config mytype '%s'" % mytype)
            return False
        config_path = os.path.join(portage_lib.settings.config_root,
                                   portage_lib.settings.user_config_dir)
        # get an  existing atom if one exists.  pass both name and ebuild,
        # no need to check which one, I think
        atom = self.get_atom(mytype, name, ebuild)
        if atom == None or atom == []:  # get a target file
            if add == '' and remove != '':
                # then there is no need to create a new file entry
                # this call was probably to check and remove
                # an existing entry if it existed.
                return True
            file = target = CONFIG_FILES[CONFIG_TYPES.index(mytype)]
            target_path = os.path.join(config_path, target)
            debug.dprint("USER_CONFIGS: set_user_config(): target_path = " +
                         target_path)
            if os.path.isdir(
                    target_path):  # Then bring up a file selector dialog
                if parent_window == None:
                    parent_window = config.Mainwindow
                file_picker = FileSelector2(parent_window,
                                            os.path.join(target_path, target),
                                            overwrite_confirm=False)
                file = file_picker.get_filename(
                    _("Porthole: Please select the %s file to use") % (target),
                    'save')
                if file == '': return False
                file = os.path.join(target_path, file)
            else:
                file = target_path
            debug.dprint(
                "USER_CONFIGS: set_user_config(): got a filename :) " +
                "file = " + file)

        else:  # found one
            file = atom[0].file
            debug.dprint("USER_CONFIGS: set_user_config(): found an atom :) " +
                         "file = " + file)
        self.set_file = file

        if isinstance(add, list):
            add = ' '.join(add)
        if isinstance(remove, list):
            remove = ' '.join(remove)
        if ebuild:
            if ebuild[0] not in '=':
                ebuild = "=" + ebuild
        #debug.dprint("USER_CONFIGS: set_user_config(): add: " +
        #"%s,\n remove: %s " %(add,remove))
        if os.getuid == 0 or os.access(config_path, os.W_OK):
            add = add.split()
            remove = remove.split()
            debug.dprint("USER_CONFIGS: set_user_config(): add: " +
                         "%s,\n remove: %s " % (str(add), str(remove)))
            set_config.set_user_config(filename=file,
                                       name=name,
                                       ebuild=ebuild,
                                       comment=comment,
                                       username=privileges.user,
                                       add=add,
                                       remove=remove)
            self.set_config_callback()
        else:
            commandlist = [
                config.Prefs.globals.su, '"python',
                set_config.__file__ + ' -d -f ' + file
            ]
            if name != '':
                commandlist.append('-n %s' % name)
            if ebuild != '':
                commandlist.append('-e %s' % ebuild)
            comment = ''  # for now. TODO add comment input dialog
            if comment != '':
                commandlist.append('-c %s' % comment)
            commandlist.append('-u %s' % os.getenv("LOGNAME"))
            if add != '':
                items = add.split()
                for item in items:
                    commandlist.append('-a %s' % item)
            if remove != '':
                items = remove.split()
                for item in items:
                    commandlist.append('-r %s' % item)
            command = ' '.join(commandlist) + '"'
            debug.dprint(" * USER_CONFIGS: set_user_config(): command = %s" %
                         command)
            # add code to update_config()
            mycallback = self.set_config_callback  #portage_lib.reload_portage
            app = SimpleTerminal(command,
                                 False,
                                 dprint_output='SET_USER_CONFIG CHILD APP: ',
                                 callback=Dispatcher(mycallback))
            app._run()
        return True
Beispiel #10
0
def run_as_root(*args):
    global app, command, prefs
    app = SimpleTerminal(config.Prefs.globals.su + ' ' + command, False)
    app._run()