summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--portato/backend/__init__.py59
-rw-r--r--portato/gui/utils.py7
2 files changed, 34 insertions, 32 deletions
diff --git a/portato/backend/__init__.py b/portato/backend/__init__.py
index 8eae806..4f20a18 100644
--- a/portato/backend/__init__.py
+++ b/portato/backend/__init__.py
@@ -16,9 +16,6 @@ from ..helper import debug
from .system_interface import SystemInterface
from .exceptions import BlockedException, PackageNotFoundException, DependencyCalcError, InvalidSystemError
-SYSTEM = "portage" # the name of the current system
-_sys = None # the SystemInterface-instance
-
class _Package (object):
"""Wrapping class from which L{portato.backend.Package} inherits. This is used by the flags module to check
whether an object is a package. It cannot use the normal Package class as this results in cyclic dependencies."""
@@ -26,42 +23,48 @@ class _Package (object):
def __init__ (self):
raise TypeError, "Calling __init__ on portato.backend._Package objects is not allowed."
+def is_package(what):
+ return isinstance(what, _Package)
+
class SystemWrapper (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."""
+ __system = 'portage'
+ __wrapped_sys = None
+ __slots__ = ('__system', '__wrapped_sys', 'set_system', '__load')
+
def __getattribute__ (self, name):
"""Just pass all attribute accesses directly to _sys."""
- return getattr(_sys, name)
-def set_system (new_sys):
- """Sets the current system to a new one.
+ if name in SystemWrapper.__slots__:
+ return object.__getattribute__(self, name)
+
+ if SystemWrapper.__wrapped_sys is None:
+ SystemWrapper.__load()
- @param new_sys: the name of the system to take
- @type new_sys: string"""
+ return getattr(SystemWrapper.__wrapped_sys, name)
- global SYSTEM
- if new_sys != SYSTEM:
- SYSTEM = new_sys
- load_system()
+ @classmethod
+ def set_system (cls, system):
+ """Sets the current system to a new one.
-def load_system ():
- """Loads the current chosen system.
+ @param system: the name of the system to take
+ @type system: string"""
- @raises InvalidSystemError: if an inappropriate system is set"""
-
- global _sys
+ cls.__system = system
+ cls.__wrapped_sys = None
- if SYSTEM == "portage":
- debug("Setting Portage System")
- from .portage import PortageSystem
- _sys = PortageSystem ()
- else:
- raise InvalidSystemError, SYSTEM
+ @classmethod
+ def __load (cls):
+ """Loads the current chosen system.
-system = SystemWrapper()
+ @raises InvalidSystemError: if an inappropriate system is set"""
+ if cls.__system == "portage":
+ debug("Setting Portage System")
+ from .portage import PortageSystem
+ cls.__wrapped_sys = PortageSystem ()
+ else:
+ raise InvalidSystemError, cls.__system
-def is_package(what):
- return isinstance(what, _Package)
-
-load_system()
+system = SystemWrapper()
diff --git a/portato/gui/utils.py b/portato/gui/utils.py
index 8b88b23..47f6fb7 100644
--- a/portato/gui/utils.py
+++ b/portato/gui/utils.py
@@ -21,7 +21,7 @@ from threading import Thread
import gtk
# some backend things
-from ..backend import flags, set_system
+from ..backend import flags, system
from ..helper import debug, info
from ..log import set_log_level
from ..constants import APP, LOCALE_DIR
@@ -90,9 +90,8 @@ class Config (ConfigParser):
set_log_level(level)
def modify_system_config (self):
- """Sets the system config.
- @see: L{backend.set_system()}"""
- set_system(self.get("system"))
+ """Sets the system config."""
+ system.set_system(self.get("system"))
def modify_external_configs (self):
"""Convenience function setting all external configs."""
session.py?h=no_config&id=f9a4a36b341b1d866269f568e86cbf63b90b5f63&follow=1'> r609@Devoty: necoro | 2008-01-14 17:04:38 +0100Necoro9-394/+477 Allowed '-' and '_' in key names. Also use group names instead of their number. r610@Devoty: necoro | 2008-01-14 17:05:42 +0100 Disabled saving of the queues r611@Devoty: necoro | 2008-01-14 17:08:53 +0100 Added the possibility to permanently en-/disable plugins r612@Devoty: necoro | 2008-01-14 17:14:09 +0100 adjust changelog and translations r613@Devoty: necoro | 2008-01-14 17:40:53 +0100 Dropdown should be localized too 2008-01-14 r605@Devoty: necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129 Updated shm module to version 1.1.4 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 Improved 'update world'; really support new use defaults 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 Handle the new useflag format correctly 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 updated todo 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 Re-Introduced etc-proposals 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 Disabled catapult till it is really usable 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 Fixed desktop file 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108 Added scrollbars to update window