diff options
Diffstat (limited to 'portato')
-rw-r--r-- | portato/backend/__init__.py | 23 | ||||
-rw-r--r-- | portato/backend/exceptions.py | 6 | ||||
-rw-r--r-- | portato/backend/flags.py | 2 | ||||
-rw-r--r-- | portato/backend/package.py | 72 | ||||
-rw-r--r-- | portato/backend/portage/package.py | 20 | ||||
-rw-r--r-- | portato/backend/portage/system.py | 18 | ||||
-rw-r--r-- | portato/backend/system_interface.py | 2 | ||||
-rw-r--r-- | portato/gui/gtk/usetips.py | 4 | ||||
-rw-r--r-- | portato/gui/gtk/windows.py | 2 | ||||
-rw-r--r-- | portato/gui/gui_helper.py | 8 |
10 files changed, 115 insertions, 42 deletions
diff --git a/portato/backend/__init__.py b/portato/backend/__init__.py index 83ee1d6..c3de443 100644 --- a/portato/backend/__init__.py +++ b/portato/backend/__init__.py @@ -10,32 +10,47 @@ # # Written by René 'Necoro' Neumann <necoro@necoro.net> +from exceptions import * from system_interface import SystemInterface -SYSTEM = "portage" -_sys = None +SYSTEM = "portage" # the name of the current system +_sys = None # the SystemInterface-instance class SystemWrapper (object, SystemInterface): + """This is a wrapper to the different system interfaces, allowing the direct import via C{from portato.backend import system}. + With this wrapper a change of the system is propagated to all imports.""" + def __getattribute__ (self, name): + """Just pass all attribute accesses directly to _sys.""" global _sys return eval ("_sys.%s" % name) def set_system (new_sys): + """Sets the current system to a new one. + + @param new_sys: the name of the system to take + @type new_sys: string""" + global SYSTEM SYSTEM = new_sys load_system() def load_system (): + """Loads the current chosen system. + + @raises InvalidSystemError: if an inappropriate system is set""" + global _sys if SYSTEM == "portage": from portato.backend.portage import PortageSystem _sys = PortageSystem () + else: + raise InvalidSystemError, SYSTEM system = SystemWrapper() -from exceptions import * +# import package before loading the system as some systems may depend on it being in the namespace from package import Package load_system() - diff --git a/portato/backend/exceptions.py b/portato/backend/exceptions.py index a5cb2fb..42f9d44 100644 --- a/portato/backend/exceptions.py +++ b/portato/backend/exceptions.py @@ -3,7 +3,7 @@ # File: portato/backend/exceptions.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006 René 'Necoro' Neumann +# Copyright (C) 2006-2007 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -21,3 +21,7 @@ class PackageNotFoundException (Exception): class DependencyCalcError (Exception): """An error occured during dependency calculation.""" pass + +class InvalidSystemError (Exception): + """An invalid system is set.""" + pass diff --git a/portato/backend/flags.py b/portato/backend/flags.py index a7241ca..7f37766 100644 --- a/portato/backend/flags.py +++ b/portato/backend/flags.py @@ -574,7 +574,7 @@ def set_testing (pkg, enable): if not isinstance(pkg, package.Package): pkg = system.new_package(pkg) - arch = pkg.get_settings("ARCH") + arch = pkg.get_global_settings("ARCH") cpv = pkg.get_cpv() if not cpv in newTesting: newTesting[cpv] = [] diff --git a/portato/backend/package.py b/portato/backend/package.py index 6f8a727..ebe9e85 100644 --- a/portato/backend/package.py +++ b/portato/backend/package.py @@ -124,7 +124,7 @@ class Package: if self.is_installed() and flag in self.get_actual_use_flags(): # flags set during install return True - elif (not self.is_installed()) and flag in self.get_settings("USE").split() \ + elif (not self.is_installed()) and flag in self.get_global_settings("USE").split() \ and not flags.invert_use_flag(flag) in self.get_new_use_flags(): # flags that would be set return True @@ -135,7 +135,10 @@ class Package: return False def get_cpv(self): - """Returns full Category/Package-Version string""" + """Returns full Category/Package-Version string. + + @returns: the cpv + @rtype: string""" return self._cpv @@ -148,16 +151,26 @@ class Package: return self.get_category()+"/"+self.get_name() def get_slot_cp (self): + """Returns the current cp followed by a colon and the slot-number. + + @returns: cp:slot + @rtype: string""" - return ("%s:%s" % (self.get_cp(), self.get_env_var("SLOT"))) + return ("%s:%s" % (self.get_cp(), self.get_package_settings("SLOT"))) def get_name(self): - """Returns base name of package, no category nor version""" + """Returns base name of package, no category nor version. + + @returns: base-name + @rtype: string""" return self._scpv[1] def get_version(self): - """Returns version of package, with revision number""" + """Returns version of package, with (optional) revision number. + + @returns: version-rev + @rtype: string""" v = self._scpv[2] if self._scpv[3] != "r0": @@ -165,12 +178,19 @@ class Package: return v def get_category(self): - """Returns category of package""" + """Returns category of package. + + @returns: category + @rtype: string""" return self._scpv[0] def get_package_path(self): - """Returns the path to where the ChangeLog, Manifest, .ebuild files reside""" + """Returns the path to where the ChangeLog, Manifest, .ebuild files reside. + + @returns: path to the package files + @rtype: string""" + p = self.get_ebuild_path() sp = p.split("/") if len(sp): @@ -182,7 +202,7 @@ class Package: # def is_installed(self): - """Returns true if this package is installed (merged) + """Returns true if this package is installed (merged). @rtype: boolean""" raise NotImplementedError @@ -260,33 +280,51 @@ class Package: raise NotImplementedError - def get_settings(self, key): - """Returns the value of the given key for this package (useful - for package.* files).""" + def get_global_settings(self, key): + """Returns the value of a global setting, i.e. ARCH, USE, ROOT, DISTDIR etc. + + @param key: the setting to return + @type key: string + @returns: the value of this setting + @rtype: string""" raise NotImplementedError def get_ebuild_path(self): - """Returns the complete path to the .ebuild file""" + """Returns the complete path to the .ebuild file. + + @rtype: string""" raise NotImplementedError - def get_env_var(self, var, tree = None): - """Returns one of the predefined env vars DEPEND, RDEPEND, SRC_URI,....""" + def get_package_settings(self, var, tree = None): + """Returns a package specific setting, such as DESCRIPTION, SRC_URI, IUSE ... + + @param var: the setting to get + @type var: string + @param tree: an object defining whether to take the information from the installed package or from the ebuild + @type tree: unknown + + @returns: the value of the setting + @rtype: string""" raise NotImplementedError def get_use_flags(self): - + """Returns _all_ (not only the package-specific) useflags which were set at the installation time of the package. + + @returns: string holding all useflags + @rtype: string""" + raise NotImplementedError - def compare_version(self,other): + def compare_version(self, other): """Compares this package's version to another's CPV; returns -1, 0, 1""" raise NotImplementedError def matches (self, criterion): - """This checks, whether this package matches a specific verisioning criterion - e.g.: "<=net-im/foobar-1.2". + """This checks, whether this package matches a specific versioning criterion - e.g.: "<=net-im/foobar-1.2". @param criterion: the criterion to match against @type criterion: string diff --git a/portato/backend/portage/package.py b/portato/backend/portage/package.py index 74a5107..376a6f4 100644 --- a/portato/backend/portage/package.py +++ b/portato/backend/portage/package.py @@ -59,9 +59,9 @@ class PortagePackage (Package): return False def is_testing(self, use_keywords = False): - testArch = "~" + self.get_settings("ARCH") + testArch = "~" + self.get_global_settings("ARCH") if not use_keywords: # keywords are NOT taken into account - if testArch in self.get_env_var("KEYWORDS").split(): + if testArch in self.get_package_settings("KEYWORDS").split(): return True return False @@ -92,12 +92,12 @@ class PortagePackage (Package): else: tree = self._settings.porttree - return list(set(self.get_env_var("IUSE", tree = tree).split()).difference(self.forced_flags)) + return list(set(self.get_package_settings("IUSE", tree = tree).split()).difference(self.forced_flags)) def get_matched_dep_packages (self, depvar): # change the useflags, because we have internally changed some, but not made them visible for portage newUseFlags = self.get_new_use_flags() - actual = self.get_settings("USE").split() + actual = self.get_global_settings("USE").split() if newUseFlags: for u in newUseFlags: if u[0] == "-" and flags.invert_use_flag(u) in actual: @@ -107,7 +107,7 @@ class PortagePackage (Package): depstring = "" for d in depvar: - depstring += self.get_env_var(d)+" " + depstring += self.get_package_settings(d)+" " portage_dep._dep_check_strict = False deps = portage.dep_check(depstring, None, self._settings.settings, myuse = actual, trees = self._trees) @@ -134,7 +134,7 @@ class PortagePackage (Package): # change the useflags, because we have internally changed some, but not made them visible for portage newUseFlags = self.get_new_use_flags() - actual = self.get_settings("USE").split() + actual = self.get_global_settings("USE").split() if newUseFlags: for u in newUseFlags: if u[0] == "-" and flags.invert_use_flag(u) in actual: @@ -144,7 +144,7 @@ class PortagePackage (Package): depstring = "" for d in depvar: - depstring += self.get_env_var(d)+" " + depstring += self.get_package_settings(d)+" " # let portage do the main stuff ;) # pay attention to any changes here @@ -188,7 +188,7 @@ class PortagePackage (Package): return dep_pkgs - def get_settings(self, key): + def get_global_settings(self, key): self._settingslock.acquire() self._settings.settings.setcpv(self._cpv) v = self._settings.settings[key] @@ -198,7 +198,7 @@ class PortagePackage (Package): def get_ebuild_path(self): return self._settings.porttree.dbapi.findname(self._cpv) - def get_env_var(self, var, tree = None): + def get_package_settings(self, var, tree = None): if not tree: mytree = self._settings.vartree if not self.is_installed(): @@ -211,7 +211,7 @@ class PortagePackage (Package): def get_use_flags(self): if self.is_installed(): - return self.get_env_var("USE", tree = self._settings.vartree) + return self.get_package_settings("USE", tree = self._settings.vartree) else: return "" def compare_version(self,other): diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 1cfda62..53384dd 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -20,9 +20,10 @@ from portato.helper import debug, unique_array from portato.backend.system_interface import SystemInterface class PortageSystem (SystemInterface): + """This class provides access to the portage-system.""" def __init__ (self): - + """Constructor.""" self.settings = PortageSettings() portage.WORLD_FILE = self.settings.settings["ROOT"]+portage.WORLD_FILE @@ -138,6 +139,15 @@ class PortageSystem (SystemInterface): return self.geneticize_list(t) def __find_resolved_unresolved (self, list, check): + """Checks a given list and divides it into a "resolved" and an "unresolved" part. + + @param list: list of cpv's + @type list: string[] + @param check: function called to check whether an entry is ok + @type check: function(cpv) + + @returns: the divided list: (resolved, unresolved) + @rtype: (Package[], Package[])""" resolved = [] unresolved = [] for x in list: @@ -242,9 +252,9 @@ class PortageSystem (SystemInterface): if len(inst) > 1: myslots = set() for i in inst: # get the slots of the installed packages - myslots.add(i.get_env_var("SLOT")) + myslots.add(i.get_package_settings("SLOT")) - myslots.add(self.find_best_match(p).get_env_var("SLOT")) # add the slot of the best package in portage + myslots.add(self.find_best_match(p).get_package_settings("SLOT")) # add the slot of the best package in portage for slot in myslots: new_packages.append(\ self.find_best(\ @@ -297,7 +307,7 @@ class PortageSystem (SystemInterface): else: old = set(p.get_installed_use_flags()) - new = set(p.get_settings("USE").split()) + new = set(p.get_global_settings("USE").split()) if new_iuse.intersection(new) != old_iuse.intersection(old): tempDeep = True diff --git a/portato/backend/system_interface.py b/portato/backend/system_interface.py index eb81401..60acb91 100644 --- a/portato/backend/system_interface.py +++ b/portato/backend/system_interface.py @@ -174,7 +174,7 @@ class SystemInterface: @type newuse: boolean @param deep: Not only check world packages but also there dependencies. @type deep: boolean - @returns: a list containing of the tuple (new_package, old_package) + @returns: a list of the tuple (new_package, old_package) @rtype: (backend.Package, backend.Package)[]""" raise NotImplementedError diff --git a/portato/gui/gtk/usetips.py b/portato/gui/gtk/usetips.py index d59e397..75bb63f 100644 --- a/portato/gui/gtk/usetips.py +++ b/portato/gui/gtk/usetips.py @@ -66,11 +66,11 @@ class UseTips (TreeViewTooltips): string = "" if len(enabled) > 0: - string = "<b>+"+"\n+".join(enabled)+"</b>" + string = "<b>+%s</b>" % ("\n+".join(enabled),) if len(disabled) > 0: string = string + "\n" if len(disabled) > 0: - string = string+"<i>- " + "\n- ".join(disabled) + "</i>" + string = string+"<i>- %s</i>" % ("\n- ".join(disabled),) return string diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py index 7841e5e..d5ea943 100644 --- a/portato/gui/gtk/windows.py +++ b/portato/gui/gtk/windows.py @@ -388,7 +388,7 @@ class PackageTable: self.comboVB.pack_start(self.vCombo) # the label (must be here, because it depends on the combo box) - desc = self.actual_package().get_env_var("DESCRIPTION").replace("&","&") + desc = self.actual_package().get_package_settings("DESCRIPTION").replace("&","&") if not desc: desc = "<no description>" use_markup = False diff --git a/portato/gui/gui_helper.py b/portato/gui/gui_helper.py index cf03a57..79064b6 100644 --- a/portato/gui/gui_helper.py +++ b/portato/gui/gui_helper.py @@ -12,7 +12,7 @@ # some backend things from portato import backend -from portato.backend import flags, system +from portato.backend import flags, system, set_system from portato.helper import * # parser @@ -116,10 +116,16 @@ class Config: @see: L{helper.set_debug()}""" set_debug(self.get_boolean("debug_opt")) + def modify_system_config (self): + """Sets the system config. + @see: L{backend.set_system()}""" + set_system(self.get("system_opt")) + def modify_external_configs (self): """Convenience function setting all external configs.""" self.modify_debug_config() self.modify_flags_config() + self.modify_system_config() def set_local(self, cpv, name, val): """Sets some local config. |