Public Member Functions | |
| def | __init__ |
| def | WriteFamily |
| def | GetType |
| def | __repr__ |
| def | GetTask |
| def | ListModels |
| def | ListTasks |
| def | GetSchemaVersion |
| def | AddTask |
Private Member Functions | |
| def | _DoMemberIO |
| def | __ReloadChildren |
| def | _SetSchemaVersion |
Private Attributes | |
| __schemaVersion | |
| __taskManagers | |
| __taskManagersModels | |
Top level object from which to create, list and destroy Tasks. This class inherits from GBSObject and adds the following user callable methods
Definition at line 9 of file GBSManager.py.
| def python::GBSManager::GBSManager::__init__ | ( | self, | ||
| name, | ||||
| parent, | ||||
| model, | ||||
| model_args | ||||
| ) |
Definition at line 21 of file GBSManager.py.
00021 : 00022 self.__schemaVersion = 0 # Incremented each time the schema changes (See schema_migrator.py) 00023 self.__taskManagers = {} # Volatile: Hash name -> Task 00024 self.__taskManagersModels = {} # Volatile: Hash name -> Task models 00025 00026 GBSObject.__init__(self,name,parent,model) 00027 00028 self.MakeChildDirectory() 00029 self.__ReloadChildren() 00030 00031 # Migrate schema 00032 migrate(self) 00033 00034 def _DoMemberIO(self,ioh):
| def python::GBSManager::GBSManager::_DoMemberIO | ( | self, | ||
| ioh | ||||
| ) | [private] |
Definition at line 35 of file GBSManager.py.
00035 : 00036 self.__schemaVersion = ioh("+Schema Version","i",self.__schemaVersion) 00037 GBSObject._DoMemberIO(self,ioh) 00038 def WriteFamily(self):
| def python::GBSManager::GBSManager::WriteFamily | ( | self | ) |
Definition at line 39 of file GBSManager.py.
00039 : 00040 self.Write() 00041 for task_name,task in self.__taskManagers.iteritems():task.WriteFamily() 00042 def GetType(self): return "GBSManager"
| def python::GBSManager::GBSManager::GetType | ( | self | ) |
| def python::GBSManager::GBSManager::__repr__ | ( | self | ) |
Definition at line 45 of file GBSManager.py.
00045 : 00046 return GBSObject.__repr__(self) + "\n"\ 00047 + "Schema version " + str(self.__schemaVersion) + "\n"\ 00048 + "Managing " + str(len(self.__taskManagers)) + " Tasks" 00049 00050 ###### User Callable Methods (Getters then Setters) ######
| def python::GBSManager::GBSManager::GetTask | ( | self, | ||
| name | ||||
| ) |
Retrieve existing Task e.g. task = manager.GetTask("Fred")Definition at line 53 of file GBSManager.py.
00053 : 00054 00055 """Retrieve existing Task e.g. task = manager.GetTask("Fred")""" 00056 00057 if not self.__taskManagers.has_key(name): 00058 print "Sorry, there is no Task named " + str(name) 00059 return None 00060 else : return self.__taskManagers[name] 00061 def ListModels(self):
| def python::GBSManager::GBSManager::ListModels | ( | self | ) |
List all available models
Definition at line 62 of file GBSManager.py.
00062 : 00063 00064 """List all available models""" 00065 00066 print "The following models are available:-\n" 00067 reg = GetModelRegistry().GetRegistry() 00068 for m_name,m in reg.iteritems(): 00069 print "Model: " + m_name 00070 print "*"*(len(m_name)+7) + "\n" 00071 print "Title:" + m.GetTitle() + "\nDescription:" 00072 print m.GetDescription() 00073 def ListTasks(self):
| def python::GBSManager::GBSManager::ListTasks | ( | self | ) |
List all existing Tasks
Definition at line 74 of file GBSManager.py.
00074 : 00075 00076 """List all existing Tasks""" 00077 00078 print "The following tasks are setup up:-\n" 00079 first = 1 00080 for task_name,task in self.__taskManagers.iteritems(): 00081 if first: 00082 print task.AsString("Heading") + "\n" 00083 first = 0 00084 print task.AsString("Brief") 00085 def GetSchemaVersion(self):
| def python::GBSManager::GBSManager::GetSchemaVersion | ( | self | ) |
Return current schema version number.
Definition at line 86 of file GBSManager.py.
00086 : 00087 00088 """Return current schema version number.""" 00089 00090 return self.__schemaVersion 00091 def AddTask(self,task_name,model_name="default"):
| def python::GBSManager::GBSManager::AddTask | ( | self, | ||
| task_name, | ||||
model_name = "default" | ||||
| ) |
Create a new Task called task_name using model model_name e.g. task = manager.AddTask("Joe","default")Definition at line 92 of file GBSManager.py.
00092 : 00093 00094 """Create a new Task called task_name using model model_name e.g. task = manager.AddTask("Joe","default")""" 00095 00096 # Check that the name is legal and not already in use. 00097 if re.search(r"[^a-zA-Z0-9_\-]",task_name): 00098 print "Sorry, '" + str(task_name) + "' is an illegal task name (characters other than alphanumeric, '_' and '-')" 00099 return 00100 if self.__taskManagers.has_key(task_name): 00101 print "Sorry, there already is a Task named " + str(task_name) 00102 return None 00103 00104 # Check the model is valid 00105 model_name_valid = 0 00106 reg = GetModelRegistry().GetRegistry() 00107 for m_name,m in reg.iteritems(): 00108 if model_name == m_name: model_name_valid = 1 00109 if not model_name_valid: 00110 print "Sorry %s is not a valid model, the following are available:-" % model_name 00111 for m_name,m in reg.iteritems(): 00112 print " " + m_name.ljust(15) + m.GetTitle() 00113 return None 00114 tm = GetModelRegistry().CreateObject(model_name,"Task",task_name,self) 00115 self.__taskManagers[task_name] = tm 00116 self.__taskManagersModels[task_name] = model_name 00117 return tm 00118 ###### Private Methods (not user callable) ######
| def python::GBSManager::GBSManager::__ReloadChildren | ( | self | ) | [private] |
Reload child Tasks from disk. Loop over all *.state files, read their model name and then recreate.
Definition at line 121 of file GBSManager.py.
00121 : 00122 00123 """Reload child Tasks from disk. 00124 00125 Loop over all *.state files, read their model name and then recreate.""" 00126 00127 import os, re 00128 00129 child_dir = self.GetStoreLocation("child_dir") 00130 child_state_files = os.listdir(child_dir) 00131 for child_state_file in child_state_files: 00132 00133 # Only look at *.state files 00134 child_state_file_spec = child_dir + "/" + child_state_file 00135 if not os.path.isfile(child_state_file_spec): continue 00136 mo = re.search(r"^(.*)\.state$",child_state_file) 00137 if not mo: continue 00138 child_name = mo.group(1) 00139 00140 # Have to sneak a look at the child's state file to get the model. 00141 # This is the one case where the parent's model may not be the same 00142 # as the child's; Manager is always the "default" model 00143 child_model = "" 00144 f = open(child_state_file_spec) 00145 for line in f: 00146 mo = re.search(r"Model Name:\s*(\S+)",line) 00147 if mo: child_model = mo.group(1) 00148 f.close() 00149 00150 if not child_model: 00151 Log(logger.ERROR,"GBSManager: Cannot find model for Task in " + str(child_state_file_spec)) 00152 continue 00153 self.AddTask(child_name,child_model) 00154 def _SetSchemaVersion(self,ver):
| def python::GBSManager::GBSManager::_SetSchemaVersion | ( | self, | ||
| ver | ||||
| ) | [private] |
Set current schema version number.
Definition at line 155 of file GBSManager.py.
00155 : 00156 00157 """Set current schema version number.""" 00158 00159 self.__schemaVersion = ver 00160 self.Write() self.Write()
Definition at line 22 of file GBSManager.py.
Definition at line 23 of file GBSManager.py.
Definition at line 24 of file GBSManager.py.
1.5.4