X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/296d853cc95fd5bef262248cfe21b507abd26a4f..9c49587e49c381c87776243081d2128650ba1715:/pymin/services/util.py?ds=sidebyside diff --git a/pymin/services/util.py b/pymin/services/util.py index 81b2767..e5aa202 100644 --- a/pymin/services/util.py +++ b/pymin/services/util.py @@ -11,8 +11,8 @@ except ImportError: from pymin.dispatcher import Handler, handler, HandlerError -#DEBUG = False -DEBUG = True +DEBUG = False +#DEBUG = True __ALL__ = ('ServiceHandler', 'InitdHandler', 'Persistent', 'ConfigWriter', 'Error', 'ReturnNot0Error', 'ExecutionError', 'call') @@ -26,13 +26,7 @@ class Error(HandlerError): message - A descriptive error message. """ - - def __init__(self, message): - r"Initialize the object. See class documentation for more info." - self.message = message - - def __str__(self): - return self.message + pass class ReturnNot0Error(Error): r""" @@ -47,7 +41,7 @@ class ReturnNot0Error(Error): r"Initialize the object. See class documentation for more info." self.return_value = return_value - def __str__(self): + def __unicode__(self): return 'The command returned %d' % self.return_value class ExecutionError(Error): @@ -66,7 +60,7 @@ class ExecutionError(Error): self.command = command self.error = error - def __str__(self): + def __unicode__(self): command = self.command if not isinstance(self.command, basestring): command = ' '.join(command) @@ -221,13 +215,22 @@ class Restorable(Persistent): r"_restore() -> bool :: Restore persistent data or create a default." try: self._load() + # TODO tener en cuenta servicios que hay que levantar y los que no + if hasattr(self, 'commit'): # TODO deberia ser reload y/o algo para comandos + self.commit() return True except IOError: for (k, v) in self._restorable_defaults.items(): setattr(self, k, v) + # TODO tener en cuenta servicios que hay que levantar y los que no + if hasattr(self, 'commit'): + self.commit() + return False self._dump() if hasattr(self, '_write_config'): self._write_config() + if hasattr(self, 'reload'): + self.reload() return False class ConfigWriter: @@ -467,7 +470,7 @@ class TransactionalHandler(Handler): self._dump() if hasattr(self, '_write_config'): self._write_config() - if hasattr(self, '_reload'): + if hasattr(self, 'reload'): self.reload() @handler(u'Discard all the uncommited changes.')