def _add_production(self): pr = NewProduction() info = pr.edit_traits() db = self.db with db.session_ctx(): while 1: if info.result: if db.get_irradiation_production(pr.name): if self.confirmation_dialog( 'Production Ratio "{}" already exists. Would you like to enter an new name?'): info = pr.edit_traits() continue else: if self.selected_production: pp = self.selected_production.clone_traits() else: pp = IrradiationProduction() db.add_irradiation_production(name=pr.name, last_modified=datetime.now()) pp.name = pr.name self.productions.append(pp) self.selected_production = next((pp for pp in self.productions if pp.name == pr.name), None) self.selected_production.editable = True break
def _load_productions(self): db = self.db with db.session_ctx(): ps = [] for pr in db.get_irradiation_productions(): p = IrradiationProduction(name=pr.name) p.create(pr) ps.append(p) self.productions = ps
def _load_reactors(self): p = os.path.join(paths.meta_root, 'reactors.json') reactors = {} if os.path.isfile(p): with open(p, 'r') as rfile: reactors = json.load(rfile) for k, v in reactors.items(): reactors[k] = IrradiationProduction(k, v) self.reactors = reactors self.reactor_names = list(reactors.keys())
def _load_productions(self, load_reactors=True): self.meta_repo.smart_pull() root = os.path.join(paths.meta_root, self.irradiation, 'productions') ps = {} keys = [] for p in os.listdir(root): if p.endswith('.json'): with open(os.path.join(root, p)) as rfile: obj = json.load(rfile) head, tail = os.path.splitext(p) ps[head] = IrradiationProduction(head, obj) keys.append(head) self.productions = ps self.production_names = keys if load_reactors: self._load_reactors()