summaryrefslogtreecommitdiffstats
path: root/pysystemmgr
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-06-29 21:55:47 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-10 22:34:50 -0400
commit4de4264355ceb0b7db953da0f472b1a4be8d6e4c (patch)
treedd5bbb232b6e99f0b05381c75908fbefa2a22657 /pysystemmgr
parent2aa53088eff13bfb50ffdf73e7a377b74ddf5fa9 (diff)
downloadtalos-skeleton-4de4264355ceb0b7db953da0f472b1a4be8d6e4c.tar.gz
talos-skeleton-4de4264355ceb0b7db953da0f472b1a4be8d6e4c.zip
system_manager: Add try_next_state function
Add a re-usable try_next_state function. A handful of idiomatic python improvements. Change-Id: I435aaaeb5760a677f8fd292f396cdbdae1195674 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'pysystemmgr')
-rw-r--r--pysystemmgr/system_manager.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/pysystemmgr/system_manager.py b/pysystemmgr/system_manager.py
index 93ba603..8bcb239 100644
--- a/pysystemmgr/system_manager.py
+++ b/pysystemmgr/system_manager.py
@@ -60,6 +60,16 @@ class SystemManager(DbusProperties,DbusObjectManager):
print "SystemManager Init Done"
+ def try_next_state(self):
+ current_state = self.Get(DBUS_NAME,"current_state")
+ if current_state not in System.EXIT_STATE_DEPEND:
+ return
+
+ if all(System.EXIT_STATE_DEPEND[current_state].values()):
+ print "All required objects started for "+current_state
+ self.gotoNextState()
+
+
def SystemStateHandler(self,state_name):
## clearing object started flags
current_state = self.Get(DBUS_NAME,"current_state")
@@ -190,22 +200,15 @@ class SystemManager(DbusProperties,DbusObjectManager):
if (self.bus_name_lookup[obj_path] == bus_name):
return
self.bus_name_lookup[obj_path] = bus_name
- print "New object: "+obj_path+" ("+bus_name+")"
- try:
- if (System.EXIT_STATE_DEPEND[current_state].has_key(obj_path) == True):
- System.EXIT_STATE_DEPEND[current_state][obj_path] = 1
- ## check if all required objects are started to move to next state
- state = 1
- for obj_path in System.EXIT_STATE_DEPEND[current_state]:
- if (System.EXIT_STATE_DEPEND[current_state][obj_path] == 0):
- state = 0
- ## all required objects have started so go to next state
- if (state == 1):
- print "All required objects started for "+current_state
- self.gotoNextState()
- except:
- pass
-
+ if current_state not in System.EXIT_STATE_DEPEND:
+ return
+
+ if obj_path in System.EXIT_STATE_DEPEND[current_state]:
+ print "New object: "+obj_path+" ("+bus_name+")"
+ System.EXIT_STATE_DEPEND[current_state][obj_path] = 1
+ ## check if all required objects are
+ # started to move to next state
+ self.try_next_state()
@dbus.service.method(DBUS_NAME,
in_signature='s', out_signature='sis')
OpenPOWER on IntegriCloud