]> git.llucax.com Git - software/pymin.git/blobdiff - pymin/services/util.py
Merge branch 'master' of git.llucax.com.ar:/var/lib/git/software/pymin into procman
[software/pymin.git] / pymin / services / util.py
index 91d28c3213830bd5064d5c4705bd2a449088e831..cb97815e2b1bf9892bbf7b1803de06240859350f 100644 (file)
@@ -13,16 +13,16 @@ from pymin.dispatcher import Handler, handler, HandlerError, \
                                 CommandNotFoundError
 from pymin.seqtools import Sequence
 
                                 CommandNotFoundError
 from pymin.seqtools import Sequence
 
-DEBUG = False
-#DEBUG = True
+#DEBUG = False
+DEBUG = True
 
 
-__ALL__ = ('Error', 'ReturnNot0Error', 'ExecutionError', 'ItemError',
-            'ItemAlreadyExistsError', 'ItemNotFoundError', 'ContainerError',
-            'ContainerNotFoundError', 'call', 'get_network_devices',
-            'Persistent', 'Restorable', 'ConfigWriter', 'ServiceHandler',
-            'RestartHandler', 'ReloadHandler', 'InitdHandler', 'SubHandler',
-            'DictSubHandler', 'ListSubHandler', 'ComposedSubHandler',
-            'ListComposedSubHandler', 'DictComposedSubHandler', 'Device','Address')
+__ALL__ = ('Error', 'ExecutionError', 'ItemError', 'ItemAlreadyExistsError',
+           'ItemNotFoundError', 'ContainerError', 'ContainerNotFoundError',
+           'call', 'get_network_devices', 'Persistent', 'Restorable',
+           'ConfigWriter', 'ServiceHandler', 'RestartHandler',
+           'ReloadHandler', 'InitdHandler', 'SubHandler', 'DictSubHandler',
+           'ListSubHandler', 'ComposedSubHandler', 'ListComposedSubHandler',
+           'DictComposedSubHandler', 'Device','Address')
 
 class Error(HandlerError):
     r"""
 
 class Error(HandlerError):
     r"""
@@ -35,22 +35,6 @@ class Error(HandlerError):
     """
     pass
 
     """
     pass
 
-class ReturnNot0Error(Error):
-    r"""
-    ReturnNot0Error(return_value) -> ReturnNot0Error instance.
-
-    A command didn't returned the expected 0 return value.
-
-    return_value - Return value returned by the command.
-    """
-
-    def __init__(self, return_value):
-        r"Initialize the object. See class documentation for more info."
-        self.return_value = return_value
-
-    def __unicode__(self):
-        return 'The command returned %d' % self.return_value
-
 class ExecutionError(Error):
     r"""
     ExecutionError(command, error) -> ExecutionError instance.
 class ExecutionError(Error):
     r"""
     ExecutionError(command, error) -> ExecutionError instance.
@@ -171,10 +155,11 @@ class Device(Sequence):
         self.name = name
         self.mac = mac
         self.ppp = ppp
         self.name = name
         self.mac = mac
         self.ppp = ppp
+        self.active = True
         self.addrs = dict()
         self.routes = list()
     def as_tuple(self):
         self.addrs = dict()
         self.routes = list()
     def as_tuple(self):
-        return (self.name, self.mac, self.addrs)
+        return (self.name, self.mac, self.active, self.addrs)
 
 
 
 
 
 
@@ -216,9 +201,8 @@ def get_network_devices():
                 d[name].addrs[from_addr] = Address(from_addr,24, peer=to_addr)
             except IndexError:
                 pass
                 d[name].addrs[from_addr] = Address(from_addr,24, peer=to_addr)
             except IndexError:
                 pass
-            
     return d
     return d
-       
+
 def get_peers():
     p = subprocess.Popen(('ip', '-o', 'addr'), stdout=subprocess.PIPE,
                                                     close_fds=True)
 def get_peers():
     p = subprocess.Popen(('ip', '-o', 'addr'), stdout=subprocess.PIPE,
                                                     close_fds=True)
@@ -233,13 +217,11 @@ def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
         return
     try:
         print 'Executing command:', command
         return
     try:
         print 'Executing command:', command
-        r = subprocess.call(command, stdin=stdin, stdout=stdout, stderr=stderr,
-                                universal_newlines=universal_newlines,
-                                close_fds=close_fds, **kw)
+        r = subprocess.check_call(command, stdin=stdin, stdout=stdout,
+                    stderr=stderr, close_fds=close_fds,
+                    universal_newlines=universal_newlines, **kw)
     except Exception, e:
         raise ExecutionError(command, e)
     except Exception, e:
         raise ExecutionError(command, e)
-    if r is not 0:
-        raise ExecutionError(command, ReturnNot0Error(r))
 
 class Persistent:
     r"""Persistent([attrs[, dir[, ext]]]) -> Persistent.
 
 class Persistent:
     r"""Persistent([attrs[, dir[, ext]]]) -> Persistent.
@@ -643,10 +625,10 @@ class InitdHandler(ServiceHandler):
         p = subprocess.Popen(('pgrep', '-f', self._initd_name),
                                 stdout=subprocess.PIPE)
         pid = p.communicate()[0]
         p = subprocess.Popen(('pgrep', '-f', self._initd_name),
                                 stdout=subprocess.PIPE)
         pid = p.communicate()[0]
-        if p.wait() == 0 and len(pid) > 0:
-            c._service_running = True
+        if p.returncode == 0 and len(pid) > 0:
+            self._service_running = True
         else:
         else:
-            c._service_running = False
+            self._service_running = False
 
 class TransactionalHandler(Handler):
     r"""Handle command transactions providing a commit and rollback commands.
 
 class TransactionalHandler(Handler):
     r"""Handle command transactions providing a commit and rollback commands.