Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sys.exit(-1)
if cfg["hs_endpoint"] is None:
logging.error('No endpoint given, try -h for help\n')
sys.exit(1)
logging.info("endpoint: {}".format(cfg["hs_endpoint"]))
try:
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
# get a handle to input file
try:
fin = h5pyd.File(src_domain, mode='r', endpoint=endpoint, username=username, password=password, bucket=bucket)
except IOError as ioe:
logging.error("Error opening file {}: {}".format(src_domain, ioe))
sys.exit(1)
# create the output domain
try:
fout = h5pyd.File(des_domain, 'x', endpoint=endpoint, username=username, password=password, bucket=bucket)
except IOError as ioe:
if ioe.errno == 403:
logging.error("No write access to domain: {}".format(des_domain))
else:
logging.error("Error creating file {}: {}".format(des_domain, ioe))
sys.exit(1)
perm_name = perm_abvr[x]
perm[perm_name] = True
for x in remove_list:
if x not in perm_abvr:
print("Permission flag: {} is not valid - must be one of 'crudep;".format(x))
sys.exit(1)
perm_name = perm_abvr[x]
perm[perm_name] = False
logging.info("perm:", perm)
# open the domain or folder
try:
if domain[-1] == '/':
f = h5pyd.Folder(domain, mode=mode, endpoint=cfg["hs_endpoint"], username=cfg["hs_username"], password=cfg["hs_password"], bucket=cfg["hs_bucket"])
else:
f = h5pyd.File(domain, mode=mode, endpoint=cfg["hs_endpoint"], username=cfg["hs_username"], password=cfg["hs_password"], bucket=cfg["hs_bucket"])
except IOError as ioe:
if ioe.errno in (404, 410):
print("domain not found")
sys.exit(1)
elif ioe.errno in (401, 403):
print("access is not authorized")
sys.exit(1)
else:
print("Unexpected error:", ioe)
sys.exit(1)
# update/add ACL if permission flags have been set
if perm:
default_acl = {'updateACL': False,
'delete': False,
'create': False,
try:
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
# get a handle to input file
try:
fin = h5pyd.File(src_domain, mode='r', endpoint=endpoint, username=username, password=password, bucket=bucket)
except IOError as ioe:
logging.error("Error opening file {}: {}".format(src_domain, ioe))
sys.exit(1)
# create the output domain
try:
fout = h5pyd.File(des_domain, 'x', endpoint=endpoint, username=username, password=password, bucket=bucket)
except IOError as ioe:
if ioe.errno == 403:
logging.error("No write access to domain: {}".format(des_domain))
else:
logging.error("Error creating file {}: {}".format(des_domain, ioe))
sys.exit(1)
# do the actual load
load_file(fin, fout, verbose=verbose, nodata=nodata, deflate=deflate)
msg = "File {} uploaded to domain: {}".format(src_domain, des_domain)
logging.info(msg)
if verbose:
print(msg)
cube_side = int(sys.argv[1])
filename = "cube_" + str(cube_side) + "_" + str(cube_side) + "_" + str(cube_side)
if len(sys.argv) > 2:
if sys.argv[2] == "-z":
filename += "_gz"
filename += ".h5pyd_test.hdfgroup.org"
print("filename:", filename)
f = h5pyd.File(filename, "r", username=USER_NAME, password=USER_PASSWD, endpoint=ENDPOINT)
print("name:", f.name)
print("uuid:", f.id.uuid)
print("get dataset")
dset = f['dset']
print("name:", dset.name)
print("uuid:", dset.id.uuid)
print("shape:", dset.shape)
print("dset.type:", dset.dtype)
print("dset.maxshape:", dset.maxshape)
print("reading data...")
def load_file(filename, domain, endpoint=None, username=None, password=None):
try:
logging.info("input file: {}".format(filename))
finfd = h5py.File(filename, "r")
logging.info("output domain: {}".format(domain))
foutfd = h5pyd.File(domain, "w", endpoint=endpoint, username=username, password=password)
def object_create_helper(name, obj):
if isinstance(obj, h5py.Dataset):
create_dataset(foutfd, obj)
elif isinstance(obj, h5py.Group):
create_group(foutfd, obj)
elif isinstance(obj, h5py.Datatype):
create_datatype(foutfd, obj)
else:
logging.error("no handler for object class: {}".format(type(obj)))
# build a rough map of the file using the internal function above
finfd.visititems(object_create_helper)
# Fully flush the h5pyd handle. The core of the source hdf5 file
# has been created on the hsds service up to now.
def createFile(domain):
#print("createFile", domain)
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
owner = None
if "hs_owner" in cfg:
owner=cfg["hs_owner"]
fh = h5py.File(domain, mode='x', endpoint=endpoint, username=username, password=password, bucket=bucket, owner=owner)
return fh
def getFile(domain):
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
fh = h5py.File(domain, mode='r', endpoint=endpoint, username=username,
password=password, bucket=bucket, use_cache=True)
return fh
print("visit:", name)
return None
def find_g1_2(name):
print("visit:", name)
if name.endswith("g1.2"):
return True # stop iteration
def visit_item_obj(name, obj):
print("visit:", name, obj.id.id)
return None
print("version:", h5py.version.version)
f = h5py.File("tall.data.hdfgroup.org", "r", endpoint="https://data.hdfgroup.org:7258")
# print("filename,", f.filename)
print("name:", f.name)
print("id:", f.id.id)
g2 = f['g2']
print("g2 uuid:", g2.id.id)
print("g2 name:", g2.name)
print("g2 num elements:", len(g2))
print("g2: iter..")
for x in g2:
print(x)
print("xyz in g2", ('xyz' in g2))
print("dset2.1 in g2", ('dset2.1' in g2))
def getFile(domain):
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
#print("getFile", domain)
fh = h5py.File(domain, mode='r', endpoint=endpoint, username=username, password=password, bucket=bucket)
return fh
def createFile(domain, linked_domain=None):
#print("createFile", domain)
username = cfg["hs_username"]
password = cfg["hs_password"]
endpoint = cfg["hs_endpoint"]
bucket = cfg["hs_bucket"]
owner = None
if "hs_owner" in cfg:
owner=cfg["hs_owner"]
fh = h5pyd.File(domain, mode='x', endpoint=endpoint, username=username, password=password, bucket=bucket, owner=owner, linked_domain=linked_domain)
return fh