summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-10-15 21:20:29 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-10-15 21:20:29 +0200
commit3d4e2da389013ebb61afbc4a6ec102697ff1cf5f (patch)
tree9d61b096f64fb3dff710cb82edae30e0a9778d1b
parent0a30d24e34493a2f56ba801facf4daba711d363e (diff)
downloadportato-3d4e2da389013ebb61afbc4a6ec102697ff1cf5f.tar.gz
portato-3d4e2da389013ebb61afbc4a6ec102697ff1cf5f.tar.bz2
portato-3d4e2da389013ebb61afbc4a6ec102697ff1cf5f.zip
Objectified all the functional stuff in backend.__init__.
Moved all the function in backend.__init__ into the SystemWrapper class. And also make loading the real system lazy. Reason: So I do not need to care about whether anything imports the system before the MainWindow is started.
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."""