diff options
Diffstat (limited to '')
-rw-r--r-- | geneticone/backend/flags.py | 125 | ||||
-rw-r--r-- | geneticone/backend/package.py | 33 | ||||
-rw-r--r-- | geneticone/backend/portage_helper.py | 5 | ||||
-rw-r--r-- | geneticone/gui/gui_helper.py | 27 | ||||
-rw-r--r-- | geneticone/gui/windows.py | 24 |
5 files changed, 135 insertions, 79 deletions
diff --git a/geneticone/backend/flags.py b/geneticone/backend/flags.py index 3065fbe..1251bfd 100644 --- a/geneticone/backend/flags.py +++ b/geneticone/backend/flags.py @@ -22,6 +22,7 @@ from portage_util import unique_array CONFIG = { "usefile" : "geneticone", + "maskfile" : "geneticone", "usePerVersion" : True } @@ -85,6 +86,14 @@ def set_config (cfg): for i in CONFIG: CONFIG[i] = cfg[i] +def generate_path (cpv, exp): + + cat, pkg, ver, rev = split_package_name(cpv) + + if exp.find("$(") != -1: + exp = exp.replace("$(cat)",cat).replace("$(pkg)",pkg).replace("$(cat-1)",cat.split("-")[0]).replace("$(cat-2)",cat.split("-")[1]) + return exp + ### USE FLAG PART ### USE_PATH = os.path.join(portage.USER_CONFIG_PATH,"package.use") USE_PATH_IS_DIR = os.path.isdir(USE_PATH) @@ -168,7 +177,7 @@ def set_use_flag (pkg, flag): if not added: path = USE_PATH if USE_PATH_IS_DIR: - path = os.path.join(USE_PATH,CONFIG["usefile"]) + path = os.path.join(USE_PATH,generate_path(cpv, CONFIG["usefile"])) try: newUseFlags[cpv].remove((path, -1, invFlag, False)) @@ -310,7 +319,7 @@ UNMASK_PATH_IS_DIR = os.path.isdir(UNMASK_PATH) new_masked = {} new_unmasked = {} -def set_masked (pkg): +def set_masked (pkg, masked = True): global new_masked, newunmasked if not isinstance(pkg, package.Package): pkg = package.Package(pkg) @@ -321,84 +330,80 @@ def set_masked (pkg): new_unmasked[cpv] = [] if not cpv in new_masked: new_masked[cpv] = [] - - nu = new_unmasked[cpv][:] - for file, line in nu: - if line == "-1": - new_unmasked[cpv].remove(file, line) - nm = new_masked[cpv][:] - for file, line in nm: + if masked: + link_neq = new_masked + link_eq = new_unmasked + path = UNMASK_PATH + else: + link_neq = new_unmasked + link_eq = new_masked + path = MASK_PATH + + copy = link_eq[cpv] + for file, line in copy: + if line == "-1": + link_eq[cpv].remove((file, line)) + + copy = link_neq[cpv][:] + for file, line in copy: if line != "-1": - new_masked[cpv].remove(file, line) + link_neq[cpv].remove(file, line) - if pkg.is_masked(): + if masked == pkg.is_masked(): return - unmasked = get_data(pkg, UNMASK_PATH) - debug("data (unmasked): "+str(unmasked)) + data = get_data(pkg, path) + debug("data: "+str(link_eq)) done = False - for file, line, crit, flags in unmasked: + for file, line, crit, flags in data: if pkg.matches(crit): - new_unmasked[cpv].append((file, line)) + link_eq[cpv].append((file, line)) done = True if done: return - if MASK_PATH_IS_DIR: - file = os.path.join(MASK_PATH, "geneticone") + if masked: + is_dir = MASK_PATH_IS_DIR + path = MASK_PATH else: - file = MASK_PATH - - new_masked[cpv].append((file, "-1")) - new_masked[cpv] = unique_array(new_masked[cpv]) - debug("new_masked: "+str(new_masked)) + is_dir = UNMASK_PATH_IS_DIR + path = UNMASK_PATH -def set_unmasked (pkg): - global new_masked, new_unmasked - if not isinstance(pkg, package.Package): - pkg = package.Package(pkg) + if is_dir: + file = os.path.join(path, generate_path(cpv, CONFIG["usefile"])) + else: + file = path - cpv = pkg.get_cpv() + link_neq[cpv].append((file, "-1")) + link_neq[cpv] = unique_array(link_neq[cpv]) + debug("new_(un)masked: "+str(link_neq)) - if not cpv in new_unmasked: - new_unmasked[cpv] = [] - if not cpv in new_masked: - new_masked[cpv] = [] - - nu = new_unmasked[cpv][:] - for file, line in nu: - if line != "-1": - new_unmasked[cpv].remove(file, line) +def remove_new_masked (cpv): + if isinstance(cpv, package.Package): + cpv = cpv.get_cpv() - nm = new_masked[cpv][:] - for file, line in nm: - if line == "-1": - new_masked[cpv].remove(file, line) - - if not pkg.is_masked(): - return - - masked = get_data(pkg, MASK_PATH) - debug("data (masked): "+str(masked)) - done = False - for file, line, crit, fl in masked: - if pkg.matches(crit): - new_masked[cpv].append((file, line)) - done = True + try: + del new_masked[cpv] + except KeyError: + pass - if done: return + try: + del new_unmasked[cpv] + except KeyError: + pass - if UNMASK_PATH_IS_DIR: - file = os.path.join(UNMASK_PATH, "geneticone") - else: - file = UNMASK_PATH +def new_masking_status (cpv): + if isinstance(cpv, package.Package): + cpv = cpv.get_cpv() - new_unmasked[cpv].append((file, "-1")) - new_unmasked[cpv] = unique_array(new_unmasked[cpv]) - debug("new_unmasked: "+str(new_unmasked)) + if cpv in new_masked and new_masked[cpv]: + return "masked" + elif cpv in new_unmasked and new_unmasked[cpv]: + return "unmasked" + else: return None -def write_masked_unmasked (): +def write_masked (): global new_unmasked, new_masked file_cache = {} diff --git a/geneticone/backend/package.py b/geneticone/backend/package.py index 20e65fd..fec346d 100644 --- a/geneticone/backend/package.py +++ b/geneticone/backend/package.py @@ -50,6 +50,29 @@ class Package (gentoolkit.Package): pkgmask = pkgmask + 2 return pkgmask + def is_masked (self): + """Returns True if either masked by package.mask or by profile. + @returns: mask-status + @rtype: boolean""" + # XXX: Better solution than string comparison? + status = flags.new_masking_status(self.get_cpv()) + if status != None: + if status == "masked": return True + elif status == "unmasked": return False + else: + debug("BUG in flags.new_masking_status. It returns "+status) + else: + status = portage.getmaskingstatus(self._cpv, settings = gentoolkit.settings) + if "profile" in status or "package.mask" in status: + return True + return False + + def set_masked (self, masking = False): + flags.set_masked(self, masked = masking) + + def remove_new_masked (self): + flags.remove_new_masked(self.get_cpv()) + def get_all_use_flags (self): """Returns a list of _all_ useflags for this package, i.e. all useflags you can set for this package. @@ -165,16 +188,6 @@ class Package (gentoolkit.Package): @rtype: string""" return self.get_category()+"/"+self.get_name() - def is_masked (self): - """Returns True if either masked by package.mask or by profile. - @returns: mask-status - @rtype: boolean""" - # XXX: Better solution than string comparison? - status = portage.getmaskingstatus(self._cpv) - if "profile" in status or "package.mask" in status: - return True - return False - def matches (self, criterion): """This checks, whether this package matches a specific verisioning criterion - e.g.: "<=net-im/foobar-1.2". @param criterion: the criterion to match against diff --git a/geneticone/backend/portage_helper.py b/geneticone/backend/portage_helper.py index 5703875..aae7c19 100644 --- a/geneticone/backend/portage_helper.py +++ b/geneticone/backend/portage_helper.py @@ -11,6 +11,7 @@ import re import os +import copy import gentoolkit import portage @@ -136,6 +137,10 @@ def sort_package_list(pkglist): """Sorts a package list in the same manner portage does.""" return gentoolkit.sort_package_list(pkglist) +def reload_settings (): + # XXX: what the hack are we doing here Oo + gentoolkit.settings = portage.config(config_incrementals = copy.deepcopy(gentoolkit.settings.incrementals)) + use_descs = {} local_use_descs = {} def get_use_desc (flag, package = None): diff --git a/geneticone/gui/gui_helper.py b/geneticone/gui/gui_helper.py index 32dd56f..b5683d2 100644 --- a/geneticone/gui/gui_helper.py +++ b/geneticone/gui/gui_helper.py @@ -25,7 +25,8 @@ class Config: const = { "main_sec" : "Main", "usePerVersion_opt" : "usePerVersion", - "useFile_opt" : "usefile" + "useFile_opt" : "usefile", + "maskFile_opt" : "maskfile" } def __init__ (self, cfgFile): @@ -47,7 +48,10 @@ class Config: return self._cfg.getboolean(section, name) def modify_flags_config (self): - flagCfg = {"usefile": self.get(self.const["useFile_opt"]), "usePerVersion" : self.get_boolean(self.const["usePerVersion_opt"])} + flagCfg = { + "usefile": self.get(self.const["useFile_opt"]), + "usePerVersion" : self.get_boolean(self.const["usePerVersion_opt"]), + "maskfile" : self.get(self.const["maskFile_opt"])} flags.set_config(flagCfg) def set(self, name, val, section=const["main_sec"]): @@ -143,7 +147,17 @@ class EmergeQueue: if cpv in self.deps: return # in list already else: - deps = backend.find_packages("="+cpv)[0].get_dep_packages() + if flags.new_masking_status(cpv) == "unmasked": + masked = True + else: + masked = False + pkg = backend.find_packages("="+cpv, masked = masked) + if pkg: + pkg = pkg[0] + else: + raise backend.PackageNotFoundException(cpv) + + deps = pkg.get_dep_packages() self.deps.update({cpv : deps}) subIt = self.tree.append(it, [cpv]) @@ -162,7 +176,6 @@ class EmergeQueue: self.remove_children(subIt) raise e - def append (self, cpv, unmerge = False, update = False): """Appends a cpv either to the merge queue or to the unmerge-queue. Also updates the tree-view. @@ -178,7 +191,11 @@ class EmergeQueue: if not unmerge: try: # insert dependencies - pkg = backend.find_packages("="+cpv) + if flags.new_masking_status(cpv) == "unmasked": + masked = True + else: + masked = False + pkg = backend.find_packages("="+cpv, masked = masked) if pkg: pkg = pkg[0] else: diff --git a/geneticone/gui/windows.py b/geneticone/gui/windows.py index 1238a5e..9bdc771 100644 --- a/geneticone/gui/windows.py +++ b/geneticone/gui/windows.py @@ -9,8 +9,6 @@ # # Written by Necoro d.M. <necoro@necoro.net> -# our backend stuff - VERSION = "0.3.4" CONFIG_LOCATION = "/etc/geneticone/geneticone.cfg" MENU_EMERGE = 1 @@ -22,6 +20,7 @@ pygtk.require("2.0") import gtk import gobject +#our backend stuff from geneticone.helper import * from geneticone import backend from geneticone.backend import flags @@ -126,6 +125,7 @@ class PreferenceWindow (AbstractDialog): def __init__ (self, parent, cfg): AbstractDialog.__init__(self, parent, "Preferences") + self.window.set_resizable(True) self.cfg = cfg @@ -137,7 +137,8 @@ class PreferenceWindow (AbstractDialog): box.pack_start(self.perVersionCb, True, True) hBox = gtk.HBox() - label = gtk.Label("File name to use if package.use is a directory:") + label = gtk.Label("File name to use if package.use is a directory:\n<small><b>$(cat)</b> = category\n<b>$(pkg)</b> = package-name\n<b>$(cat-1)</b>/<b>$(cat-2)</b> = first/second part of the category</small>") + label.set_use_markup(True) self.editUsefile = gtk.Entry() self.editUsefile.set_text(cfg.get(cfg.const["useFile_opt"])) hBox.pack_start(label, False) @@ -218,7 +219,7 @@ class PackageWindow (AbstractDialog): checkHB.pack_start(self.installedCheck, True, False) self.maskedCheck = gtk.CheckButton() - self.maskedCheck.connect("button-press-event", self.cb_button_pressed) + self.maskedCheck.connect("toggled", self.cb_masked_toggled) self.maskedCheck.set_label("Masked") checkHB.pack_start(self.maskedCheck, True, False) @@ -366,6 +367,7 @@ class PackageWindow (AbstractDialog): def cb_cancel_clicked (self, button, data = None): if self.delOnClose: self.actual_package().remove_new_use_flags() + self.actual_package().remove_new_masked() elif self.flagChanged: if self.queue: self.queue.append(self.actual_package().get_cpv(), update = True) @@ -397,6 +399,13 @@ class PackageWindow (AbstractDialog): self.window.destroy() return True + def cb_masked_toggled (self, button): + status = button.get_active() + debug("status: ",status) + self.actual_package().set_masked(status) + self.flagChanged = True + return True + def cb_use_flag_toggled (self, cell, path, store, data = None): store[path][0] = not store[path][0] prefix = "" @@ -652,6 +661,13 @@ class MainWindow: hintMB.run() hintMB.destroy() flags.write_use_flags() + if len(flags.new_masked)>0 or len(flags.new_unmasked)>0: + hintMB = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, + "You have changed masking keywords. Genetic/One will write these changes into the appropriate files. Please backup them if you think it is necessairy.") + hintMB.run() + hintMB.destroy() + flags.write_masked() + backend.reload_settings() self.queue.emerge(force=True) elif button == self.unmergeBtn or button == MENU_UNEMERGE: self.queue.unmerge(force=True) |