def main(): parser = argparse.ArgumentParser( usage='%(prog)s [-h] <json_file> <h5_file>') parser.add_argument('in_filename', nargs='+', help='JSon file to be converted to h5') parser.add_argument('out_filename', nargs='+', help='name of HDF5 output file') args = parser.parse_args() # create logger log = logging.getLogger("h5serv") # log.setLevel(logging.WARN) log.setLevel(logging.INFO) # add log handler handler = logging.FileHandler('./jsontoh5.log') # add handler to logger log.addHandler(handler) text = open(args.in_filename[0]).read() # parse the json file h5json = json.loads(text) if "root" not in h5json: raise Exception("no root key in input file") root_uuid = h5json["root"] filename = args.out_filename[0] # create the file, will raise IOError if there's a problem Hdf5db.createHDF5File(filename) with Hdf5db(filename, root_uuid=root_uuid, update_timestamps=False, app_logger=log) as db: h5writer = Writeh5(db, h5json) h5writer.writeFile() # open with h5py and remove the _db_ group # Note: this will delete any anonymous (un-linked) objects f = h5py.File(filename, 'a') if "__db__" in f: del f["__db__"] f.close() print("done!")
def main(): parser = argparse.ArgumentParser(usage='%(prog)s [-h] <json_file> <h5_file>') parser.add_argument('in_filename', nargs='+', help='JSon file to be converted to h5') parser.add_argument('out_filename', nargs='+', help='name of HDF5 output file') args = parser.parse_args() # create logger log = logging.getLogger("h5serv") # log.setLevel(logging.WARN) log.setLevel(logging.INFO) # add log handler handler = logging.FileHandler('./jsontoh5.log') # add handler to logger log.addHandler(handler) text = open(args.in_filename[0]).read() # parse the json file h5json = json.loads(text) if "root" not in h5json: raise Exception("no root key in input file") root_uuid = h5json["root"] filename = args.out_filename[0] # create the file, will raise IOError if there's a problem Hdf5db.createHDF5File(filename) with Hdf5db(filename, root_uuid=root_uuid, update_timestamps=False, app_logger=log) as db: h5writer = Writeh5(db, h5json) h5writer.writeFile() # open with h5py and remove the _db_ group # Note: this will delete any anonymous (un-linked) objects f = h5py.File(filename, 'a') if "__db__" in f: del f["__db__"] f.close() print("done!")
def main(): nargs = len(sys.argv) dumper = Dumph5() dumper.verbose = False dumper.endpoint = None dumper.port = 7253 dumper.noDsetData = False dumper.noAttrData = False endpoint_option = "-endpoint=" port_option = "-port=" option_count = 0 for arg in sys.argv: if arg.startswith(endpoint_option): endpoint = arg[len(endpoint_option):] if endpoint.startswith("http"): dumper.endpoint = endpoint else: dumper.endpoint = "http://" + endpoint option_count += 1 elif arg.startswith(port_option): port = arg[len(port_option):] dumper.port = int(port) option_count += 1 elif arg == "-v": dumper.verbose = True if nargs - option_count <= 2: printUsage() domain = sys.argv[nargs-2] filename = sys.argv[nargs-1] print "domain:", domain print "filename:", filename dumper.domain = domain domain_json = dumper.makeRequest("/") if "root" not in domain_json: raise Exception("no root key in domain response") root_uuid = domain_json["root"] # create the file, will raise IOError if there's a problem Hdf5db.createHDF5File(filename) with Hdf5db(filename, root_uuid=root_uuid) as db: dumper.writeFile(db) # open with h5py and remove the _db_ group # Note: this will delete any anonymous (un-linked) objects f = h5py.File(filename, 'a') del f["__db__"] f.close() print "done!"
def main(): nargs = len(sys.argv) dumper = Dumph5() dumper.verbose = False dumper.endpoint = None dumper.port = 7253 dumper.noDsetData = False dumper.noAttrData = False endpoint_option = "-endpoint=" port_option = "-port=" option_count = 0 for arg in sys.argv: if arg.startswith(endpoint_option): endpoint = arg[len(endpoint_option):] if endpoint.startswith("http"): dumper.endpoint = endpoint else: dumper.endpoint = "http://" + endpoint option_count += 1 elif arg.startswith(port_option): port = arg[len(port_option):] dumper.port = int(port) option_count += 1 elif arg == "-v": dumper.verbose = True if nargs - option_count <= 2: printUsage() domain = sys.argv[nargs - 2] filename = sys.argv[nargs - 1] print "domain:", domain print "filename:", filename dumper.domain = domain domain_json = dumper.makeRequest("/") if "root" not in domain_json: raise Exception("no root key in domain response") root_uuid = domain_json["root"] # create the file, will raise IOError if there's a problem Hdf5db.createHDF5File(filename) with Hdf5db(filename, root_uuid=root_uuid) as db: dumper.writeFile(db) # open with h5py and remove the _db_ group # Note: this will delete any anonymous (un-linked) objects f = h5py.File(filename, 'a') del f["__db__"] f.close() print "done!"