Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getFileHandle(self,inputfile):
try:
self._HDF5 = False
if HDF5SUPPORT:
if h5py.is_hdf5(inputfile):
self._HDF5 = True
try:
return HDF5Stack1D.HDF5Stack1D(self._filelist,
self.selection)
except:
raise
ffile = self.__tryEdf(inputfile)
if ffile is None:
ffile = self.__tryLucia(inputfile)
if ffile is None:
if inputfile[-3:] == "DAT":
ffile = self.__tryAifira(inputfile)
if (ffile is None):
del ffile
ffile = SpecFileLayer.SpecFileLayer()
ffile.SetSource(inputfile)
print(">filename:", filename)
print(">username:", username)
print(">password:", passwd)
print(">email:", email)
if args.replace:
print("replace is on")
# verify file exists and is writable
if not op.isfile(filename):
print("password file:", filename, " does not exist")
return -1
if not h5py.is_hdf5(filename):
print("invalid password file")
return -1
mode = 'r'
if args.replace or args.add:
mode = 'r+'
if not os.access(filename, os.W_OK):
print("password file is not writable")
return -1
f = h5py.File(filename, mode)
if 'user_type' not in f:
print("invalid password file")
return -1
return -1
if args.passwd:
passwd = args.passwd
if len(passwd) < 4:
print("password must be at least 4 characters long")
return -1
else:
passwd = generate_temp_password()
# verify file exists and is writable
if not op.isfile(filename):
print("password file:", filename, " does not exist")
return -1
if not h5py.is_hdf5(filename):
print("invalid password file")
return -1
if not os.access(filename, os.W_OK):
print("password file is not writable")
return -1
f = h5py.File(filename, 'r+')
if 'user_type' not in f:
print("invalid password file")
return -1
user_type = f['user_type']
now = int(time.time())
def read(self, filename, load_lonlat=True):
"""Read product in hdf format from *filename*
"""
LOG.debug("Filename: %s" % filename)
is_temp = False
if not h5py.is_hdf5(filename):
# Try see if it is bzipped:
import bz2
bz2file = bz2.BZ2File(filename)
import tempfile
tmpfilename = tempfile.mktemp()
try:
ofpt = open(tmpfilename, 'wb')
ofpt.write(bz2file.read())
ofpt.close()
is_temp = True
except IOError:
import traceback
traceback.print_exc()
raise IOError("Failed to read the file %s" % filename)
filename = tmpfilename
def open_file(file_name):
if h5.is_hdf5(file_name):
f = h5.File(file_name, "r")
return(f)
else:
help()
def dump_mcscf(mc, chkfile=None, key='mcscf',
e_tot=None, mo_coeff=None, ncore=None, ncas=None,
mo_occ=None, mo_energy=None, e_cas=None, ci_vector=None,
casdm1=None, overwrite_mol=True):
'''Save CASCI/CASSCF calculation results or intermediates in chkfile.
'''
if chkfile is None: chkfile = mc.chkfile
if ncore is None: ncore = mc.ncore
if ncas is None: ncas = mc.ncas
if e_tot is None: e_tot = mc.e_tot
if e_cas is None: e_cas = mc.e_cas
if mo_coeff is None: mo_coeff = mc.mo_coeff
#if ci_vector is None: ci_vector = mc.ci
if h5py.is_hdf5(chkfile):
fh5 = h5py.File(chkfile)
if key in fh5:
del(fh5[key])
else:
fh5 = h5py.File(chkfile, 'w')
if 'mol' not in fh5:
fh5['mol'] = mc.mol.dumps()
elif overwrite_mol:
del(fh5['mol'])
fh5['mol'] = mc.mol.dumps()
fh5[key+'/mo_coeff'] = mo_coeff
def store(subkey, val):
if val is not None:
detected_input_format = common.TF_HUB_MODEL
elif os.path.isdir(input_path):
if (any(fname.lower().endswith('saved_model.pb')
for fname in os.listdir(input_path))):
detected_input_format = detect_saved_model(input_path)
else:
for fname in os.listdir(input_path):
fname = fname.lower()
if fname.endswith('model.json'):
filename = os.path.join(input_path, fname)
if get_tfjs_model_type(filename) == common.TFJS_LAYERS_MODEL_FORMAT:
input_path = os.path.join(input_path, fname)
detected_input_format = common.TFJS_LAYERS_MODEL
break
elif os.path.isfile(input_path):
if h5py.is_hdf5(input_path):
detected_input_format = common.KERAS_MODEL
elif input_path.endswith('saved_model.pb'):
input_path = os.path.dirname(input_path)
detected_input_format = detect_saved_model(input_path)
elif (input_path.endswith('model.json') and
get_tfjs_model_type(input_path) == common.TFJS_LAYERS_MODEL_FORMAT):
detected_input_format = common.TFJS_LAYERS_MODEL
return detected_input_format, input_path