use the enum module to represent states
[~helmut/onoff.git] / onoff / process.py
index 572cbd9..6d738c7 100644 (file)
@@ -2,7 +2,7 @@ import logging
 import os
 import signal
 
-from .common import ST_ACTIVE, ST_TRANSITION, OnoffDevice
+from .common import OnoffDevice, OnoffState
 from .gobject import spawn_child
 
 logger = logging.getLogger("onoff.process")
@@ -32,14 +32,14 @@ class OnoffProcess(OnoffDevice):
         OnoffDevice.__init__(self)
         self.command = command
         self.termsig = termsig
-        self.desired_state = 0 # bit mask of just ST_ACTIVE
+        self.desired_state = OnoffState.inactive
         self.pid = None
         self.killed = False
 
     @property
     def state(self):
         if self.killed:
-            return self.desired_state | ST_TRANSITION
+            return self.desired_state | OnoffState.transition
         return self.desired_state
 
     def start_process(self):
@@ -47,7 +47,7 @@ class OnoffProcess(OnoffDevice):
         logger.info("starting command %s", " ".join(self.command))
         self.pid = spawn_child(self.command, self.process_died)
         logger.debug("started as pid %d", self.pid)
-        assert self.desired_state == ST_ACTIVE
+        assert self.desired_state == OnoffState.active
         logger.debug("process started")
         self.changestate(self.state)
 
@@ -56,22 +56,22 @@ class OnoffProcess(OnoffDevice):
         self.pid = None
         self.killed = False
         logger.info("process %d died", pid)
-        if self.desired_state == ST_ACTIVE:
+        if self.desired_state == OnoffState.active:
             self.start_process()
         else:
             self.changestate(self.state)
 
     def activate(self):
-        if self.desired_state != ST_ACTIVE:
-            self.desired_state = ST_ACTIVE
+        if self.desired_state != OnoffState.active:
+            self.desired_state = OnoffState.active
             if self.pid is None:
                 self.start_process()
             else:
                 logger.debug("already activated. nothing to do")
 
     def deactivate(self):
-        if self.desired_state != 0:
-            self.desired_state = 0
+        if self.desired_state != OnoffState.inactive:
+            self.desired_state = OnoffState.inactive
             if self.pid is not None and not self.killed:
                 logger.info("killing process %d", self.pid)
                 os.kill(self.pid, self.termsig)