diff options
Diffstat (limited to 'portato/backend')
-rw-r--r-- | portato/backend/flags.py | 67 | ||||
-rw-r--r-- | portato/backend/package.py | 18 | ||||
-rw-r--r-- | portato/backend/portage/system.py | 1 |
3 files changed, 51 insertions, 35 deletions
diff --git a/portato/backend/flags.py b/portato/backend/flags.py index f171356..b9fcae2 100644 --- a/portato/backend/flags.py +++ b/portato/backend/flags.py @@ -10,7 +10,7 @@ # # Written by René 'Necoro' Neumann <necoro@necoro.net> -from __future__ import absolute_import +from __future__ import absolute_import, with_statement import os import os.path @@ -250,12 +250,18 @@ def set_use_flag (pkg, flag): if added: del newUseFlags[-1] # we currently added it as an extra option - delete it added = True jumpOut = False - for t in [(file, line, invFlag, False),(file, line, flag, True)]: + for t in ((file, line, invFlag, False),(file, line, flag, True)): if t in newUseFlags[cpv]: newUseFlags[cpv].remove(t) jumpOut = True - break - if not jumpOut: newUseFlags[cpv].append((file, line, invFlag, True)) + # break # don't break as both cases can be valid (see below) + if not jumpOut: + newUseFlags[cpv].append((file, line, invFlag, True)) + + # we removed the inverted from package.use - but it is still enabled somewhere else + # so set it explicitly here + if invFlag in pkg.get_actual_use_flags(): + newUseFlags[cpv].append((file, line, flag, False)) break # we want to duplicate the flag --> ignore @@ -306,17 +312,17 @@ def get_new_use_flags (cpv): if is_package(cpv): cpv = cpv.get_cpv() - list2return = [] + list2return = set() try: for file, line, flag, remove in newUseFlags[cpv]: if remove: - list2return.append(invert_use_flag(flag)) + list2return.add("~"+invert_use_flag(flag)) else: - list2return.append(flag) + list2return.add(flag) except KeyError: pass - return list2return + return list(list2return) def write_use_flags (): """This writes our changed useflags into the file.""" @@ -342,9 +348,11 @@ def write_use_flags (): file_cache = {} # cache for having to read the file only once: name->[lines] for cpv in newUseFlags: flagsToAdd = [] # this is used for collecting the flags to be inserted in a _new_ line + + newUseFlags[cpv].sort(key = lambda x: x[3]) # now the flags are sorted in a manner, that removal comes after appending + for file, line, flag, delete in newUseFlags[cpv]: line = int(line) # it is saved as a string so far! - # add new line if line == -1: flagsToAdd.append(flag) @@ -352,31 +360,30 @@ def write_use_flags (): else: if not file in file_cache: # read file - f = open(file, "r") - lines = [] - i = 1 - while i < line: # stop at the given line - lines.append(f.readline()) - i += 1 - l = f.readline().split(" ") - - # delete or insert - if delete: - remove(flag,l) - else: - insert(flag,l) - lines.append(" ".join(l)) - - # read the rest - lines.extend(f.readlines()) - - file_cache[file] = lines - f.close() + with open(file, "r") as f: + lines = [] + i = 1 + while i < line: # stop at the given line + lines.append(f.readline()) + i += 1 + l = f.readline().split(" ") + + # delete or insert + if delete: + remove(flag,l) + else: + insert(flag,l) + lines.append(" ".join(l)) + + # read the rest + lines.extend(f.readlines()) + + file_cache[file] = lines else: # in cache l = file_cache[file][line-1].split(" ") if delete: - remove(flag,l) + remove(flag, l) else: insert(flag,l) file_cache[file][line-1] = " ".join(l) diff --git a/portato/backend/package.py b/portato/backend/package.py index 4f90765..16cee0e 100644 --- a/portato/backend/package.py +++ b/portato/backend/package.py @@ -12,6 +12,7 @@ from __future__ import absolute_import +from ..helper import debug from . import _Package, system, flags class Package (_Package): @@ -96,15 +97,22 @@ class Package (_Package): @rtype: string[]""" i_flags = self.get_global_settings("USE", installed = False).split() + m_flags = system.get_global_settings("USE").split() for f in self.get_new_use_flags(): + removed = False + + if f[0] == "~": + f = f[1:] + removed = True if f[0] == '-': - if flags.invert_use_flag(f) in i_flags: + if flags.invert_use_flag(f) in i_flags and not (removed and flags.invert_use_flag(f) in m_flags): i_flags.remove(flags.invert_use_flag(f)) - + elif f not in i_flags: - i_flags.append(f) - + if not (removed and flags.invert_use_flag(f) in m_flags): + i_flags.append(f) + return i_flags def set_use_flag (self, flag): @@ -130,7 +138,7 @@ class Package (_Package): @returns: USE_EXPAND-value on success @rtype: string or None""" - if not suggest is None: + if suggest is not None: if flag.startswith(suggest.lower()): return suggest diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 0997bed..a1ac90c 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -142,6 +142,7 @@ class PortageSystem (SystemInterface): return list_of_packages def get_global_settings (self, key): + self.settings.settings.reset() return self.settings.settings[key] def find_best (self, list, only_cpv = False): |