class DbPBS(pbs_db_interface): def __init__(self, filename=None): self.pbs = OpenPBS(deploy=True) self.open() def open(self, filename=None): if filename is not None: self.filename = filename else: self.filename = path_expand(self.pbs.database_filename()) path = os.path.dirname(self.filename) Shell.mkdir(path) self.load() def clear(self): for id in self.db: del self.db[id] self.save() def load(self): """load the cloudmesh_job""" print('loading', self.filename) # remove db ending so that shelve automatically adds it self.filename = self.filename.replace(".db", "") self.db = shelve.open(self.filename, writeback=True) def save(self): self.db.sync() def get(self, id): return self.db[id] def status(self, id): return self.get(id)["job_state"] def set(self, id, value): self.db[id] = value self.save() def keys(self): self.data().keys() def delete(self, id): del self.db[id] def close(self): self.db.close() def update(self, host=None, user=True): if host is None: print("host is none is not supported yet") raise print("QSTAT") r = dict(self.pbs.qstat(host, user=user, format='dict')) pprint(r) if r is not {}: for jobid in r: self.db[jobid] = r[jobid] self.save() else: print("no jobs found after query") print("update completed") def info(self): print("Filename:", self.filename) def list(self, attributes=None, output="table"): if self.db is None or len(self.db) == 0: print("No jobs found") return None columns = attributes if columns is None: columns = ["cm_jobid", "cm_host", "cm_user", "Job_Name", "job_state", "exit_status"] # prepare the dict d = {} for jobid in self.db: content = {} for attribute in columns: try: content[attribute] = self.db[jobid][attribute] except: content[attribute] = "None" d[jobid] = content # print the dict if output in ["csv", "table", "dict", "yaml"]: return dict_printer(d, order=columns, output=output) return None def qsub(self, name, host, script, template=None, kind="dict"): r = self.pbs.qsub(name, host, script, template=template, kind=kind) pprint(r) return dict(r)