Beispiel #1
0
def set_make_conf(prefs,
                  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')
    """
    dprint("PKGCORE_LIB: 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)
    config_path = portage_const.USER_CONFIG_PATH
    if not os.access(portage_const.MAKE_CONF_FILE, os.W_OK):
        command = (''.join([
            prefs.globals.su, ' "python ', prefs.DATA_PATH,
            'set_config.py -d -f ', file
        ]))
        command = command + '-p ' + property + ' '
        if add != '':
            command = command + "-a '" + add + "' '"
        if remove != '':
            command = command + "-r '" + remove + "'"
        command = command + '"'
        dprint(" * PKGCORE_LIB: set_make_conf(); command = " + command)
        if not callback: callback = reload_portage
        app = SimpleTerminal(command,
                             False,
                             dprint_output='SET_MAKE_CONF CHILD APP: ',
                             callback=Dispatcher(callback))
        app._run()
    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.mysettings ?
    return True
Beispiel #2
0
def set_user_config(prefs, file, name='', ebuild='', add='', remove='', callback=None):
    """
    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.
    """
    dprint("PKGCORE_LIB: set_user_config()")
    command = ''
    maskfiles = ['package.mask', 'package.unmask']
    otherfiles = ['package.use', 'package.keywords']
    package_files = otherfiles + maskfiles
    if file not in package_files:
        dprint(" * PKGCORE_LIB: set_user_config(); unsupported config file '" + 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 = [prefs.globals.su, '"python', prefs.DATA_PATH + 'set_config.py -d -f %s' %file]
        if name != '':
            commandlist.append('-n '+ name)
        if ebuild != '':
            commandlist.append('-e ' + ebuild)
        if add != '':
            items = add.split()
            for item in items:
                commandlist.append('-a ' + item)
        if remove != '':
            items = remove.split()
            for item in items:
                commandlist.append('-r ' + item)
        command = ' '.join(commandlist) + '"'
        dprint(" * PKGCORE_LIB: set_user_config(); command = "+ 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 #3
0
 def get_system_list(self, emptytree=False):
     utils.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()
         utils.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
     utils.debug.dprint(
         "READERS: UpgradableListReader; new system pkg list %s" %
         str(self.categories["System"]))
Beispiel #4
0
class UpgradableListReader(CommonReader):
    """ Read available upgrades and store them in a tuple """
    def __init__(self, installed, upgrade_only, view_prefs):
        """ Initialize """
        CommonReader.__init__(self)
        self.installed_items = installed
        self.upgrade_only = upgrade_only
        #self.world = []
        self.view_prefs = view_prefs
        # 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", "User list", "World", "Dependencies"]
        self.cat_order = [
            "Tool Chain", "System", "User list1", "World", "Dependencies"
        ]
        self.categories = {
            "Tool Chain": None,
            "System": None,
            "World": "World",
            "User list1": None,
            "Dependencies": "Dependencies"
        }
        self.upgradables = {}
        self.pkg_count = {}
        for key in self.categories:
            self.upgradables[key] = {}
            self.pkg_count[key] = 0
        self.count = 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/[ ].*$//'"

    def run(self):
        """fill upgrade tree"""
        utils.debug.dprint(
            "READERS: UpgradableListReader(); process id = %d *******************"
            % os.getpid())
        self.get_system_list()
        #upgradeflag = self.upgrade_only and True or False
        # find upgradable packages
        for cat, packages in self.installed_items:
            for name, package in list(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 (not self.upgrade_only
                                       and upgradable == -1):
                    for key in self.cat_order:
                        if package.in_list(self.categories[key]):
                            self.upgradables[key][package.full_name] = package
                            self.pkg_count[key] += 1
                            break
        self.upgrade_total = 0
        for key in self.pkg_count:
            self.upgrade_total += self.pkg_count[key]
            if self.upgradables[key] == {}:
                pkg = backends.portage_lib.Package(_("None"))
                self.upgradables[key][_("None")] = pkg
        # set the thread as finished
        self.done = True
        return

    def get_system_list(self, emptytree=False):
        utils.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()
            utils.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
        utils.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(backends.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