def setup(self): _, self.pyon_db_file = mkstemp() self.pyon_db_url = "sqlite:///%s" % self.pyon_db_file self.pyon_db = PyonDB(self.pyon_db_url) self.pyon_data_object = PyonDataObject() self.pyon_container = MockPyonContainer() self.pyon = pyon.Pyon(self.pyon_db, self.pyon_container, data_object=self.pyon_data_object)
def __init__(self, **kwargs): for p in self.init_needed_keywords: if p not in kwargs.keys(): raise PIDanticUsageException( "The driver %s must have the parameter %s." % (self.driver_name, p)) for p in kwargs.keys(): if p not in self.init_needed_keywords and p not in self.init_optional_keywords: raise PIDanticUsageException( "The driver %s does not know the parameter %s." % (self.driver_name, p)) self._name = kwargs.get('name') self.container = kwargs.get('pyon_container') self._working_dir = kwargs.get('directory') self._log = kwargs.get('log') db_url = "sqlite:///%s/pyon.db" % (self._working_dir) self._db = PyonDB(db_url) pyon_instances = self._db.get_all_pyons() if len(pyon_instances) > 1: raise PIDanticUsageException( "The driver %s should have at most 1 pyon instance in its table." % (self.driver_name)) if not pyon_instances: self._pyon = Pyon(self._db, pyon_container=self.container, name=self._name, log=self._log, dirpath=self._working_dir) else: pyon_instance = pyon_instances.pop(0) if pyon_instance.name != self._name: raise PIDanticUsageException( "The requested pyon name %s is not in the db" % (self._name)) self._pyon = Pyon(self._db, data_object=pyon_instance, pyon_container=self.container) self.container.proc_manager.add_proc_state_changed_callback( self._pyon_process_state_change_callback)