def __getitem__(self, key): """Called by self[key]""" v = self._tables[key] # Return v if v is table else parse the files, construct table and store it. if not isinstance(v, TableMetadata): return v new_table = OfficialDojoTable.from_djson_file(v.djson_path) new_table.dojo_name = key self._tables[key] = new_table return new_table
def from_file(cls, filepath): """ Initalize the object from a file in json format. """ with open(filepath, "rt") as fh: d = json.load(fh) new = cls(**d) #new["xc"] = new["xc"] #print("keys", new.keys()) # Construct the full table of pseudos # Translate djson_path into path insides pseudos djpath = as_dojo_path(new["djson_path"]) new.table = OfficialDojoTable.from_djson_file(djpath) return new
def djson_validate(options): """Validate djson file.""" table = OfficialDojoTable.from_djson_file(options.djson_path) if options.verbose > 1: print(table) md5dict = {p.basename: p.md5 for p in table} errors = table.dojo_find_errors(md5dict, require_hints=False) if errors: cprint("dojo_find_errors returned %s errors" % len(errors), "red") if not options.verbose: print("Use --verbose to show errors") else: for i, e in enumerate(errors): print("[%s]" % i, e) return len(errors)
def gbrv_gendb(options): """Generate the GBRV output database from a djson file..""" # Build table from djson_path djson_path = os.path.abspath(options.djson_path) table = OfficialDojoTable.from_djson_file(djson_path) if options.verbose > 1: print(table) # Init database and dump it db = GbrvOutdb.new_from_table(table, djson_path) if os.path.exists(db.path): cprint( "File %s already exists. New file won't be created. Remove it and try again" % db.path, "red") return 1 db.json_write() cprint("Written new database %s" % os.path.relpath(db.path), "green") return 0