Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def join(self, timeout=None):
super(PropagatingThread, self).join()
if self.exc:
raise misc.errors.PlenopticamError(self.exc, cfg=self.cfg, sta=self.sta)
return self.ret
sta = sta if sta is not None else PlenopticamStatus()
# file name and file path handling
if fp is not None and splitext(fp)[-1] != '.json':
fn = splitext(basename(fp))[0]+'.json'
fp = join(splitext(fp)[0], fn)
# load calibration data from json file
if exists(fp):
try:
with open(fp, 'r') as f:
json_dict = json.load(f)
except json.decoder.JSONDecodeError:
remove(fp)
sta.status_msg('Calibration JSON File may be corrupted. Attempt to delete file %s' % fp, opt=True)
raise PlenopticamError('Calibration JSON File may be corrupted. Attempt to delete file %s' % fp)
else:
json_dict = None
if splitext(fp)[-1].lower() in ('.lfp', 'lfr', '.raw'):
sta.status_msg('Provided file %s does not exist' % fp, opt=True)
return json_dict
self.calibs = {}
self.lfpimg = {}
self._file_name = 'cfg.json'
self._dir_path = dirname(abspath(__file__)) # for pip installed versions
if not isdir(self._dir_path) and isdir(join(abspath('.'), 'cfg')):
self._dir_path = join(abspath('.'), 'cfg') # for py2app contents
try:
self.read_params()
# test if config parameters present
if not self.params.keys():
raise PlenopticamError('Config file could not be loaded')
# number of values in loaded config is supposed to equal config constants specified in the tool
if not len(self.params.keys()) == len(PARAMS_KEYS):
raise PlenopticamError('Config file corrupted')
except PlenopticamError:
self.default_values()
self.save_params()
def __init__(self, *args, **kwargs):
super(PlenopticamError, self).__init__(*args)
self.cfg = kwargs['cfg'] if 'cfg' in kwargs else None
self.sta = kwargs['sta'] if 'sta' in kwargs else PlenopticamStatus()
self.args = args
try:
self.write_log()
except PermissionError as e:
self.sta.status_msg(msg=e, opt=True)
raise e
self.sta.status_msg('Error! See log file in %s.' % os.path.join(os.pardir, os.path.basename(fp), fn))
# write error to log file
with open(os.path.join(fp, fn), 'a') as f:
f.writelines(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
f.writelines('\nOpen issue at %s and paste below traceback.\n\n' % self.URL_ISSUE)
f.writelines(self.args.__str__())
f.writelines('\n\n\n')
class LfpTypeError(PlenopticamError):
def __init__(self, *args, **kwargs):
super(LfpTypeError, self).__init__(*args, **kwargs)
class LfpAttributeError(PlenopticamError):
def __init__(self, *args, **kwargs):
super(LfpAttributeError, self).__init__(*args, **kwargs)
self.lfpimg = {}
self._file_name = 'cfg.json'
self._dir_path = dirname(abspath(__file__)) # for pip installed versions
if not isdir(self._dir_path) and isdir(join(abspath('.'), 'cfg')):
self._dir_path = join(abspath('.'), 'cfg') # for py2app contents
try:
self.read_params()
# test if config parameters present
if not self.params.keys():
raise PlenopticamError('Config file could not be loaded')
# number of values in loaded config is supposed to equal config constants specified in the tool
if not len(self.params.keys()) == len(PARAMS_KEYS):
raise PlenopticamError('Config file corrupted')
except PlenopticamError:
self.default_values()
self.save_params()
# export folder path
fp = self.cfg.exp_path if hasattr(self.cfg, 'exp_path') else os.getcwd()
# send status to user while referring to log file
self.sta.status_msg('Error! See log file in %s.' % os.path.join(os.pardir, os.path.basename(fp), fn))
# write error to log file
with open(os.path.join(fp, fn), 'a') as f:
f.writelines(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
f.writelines('\nOpen issue at %s and paste below traceback.\n\n' % self.URL_ISSUE)
f.writelines(self.args.__str__())
f.writelines('\n\n\n')
class LfpTypeError(PlenopticamError):
def __init__(self, *args, **kwargs):
super(LfpTypeError, self).__init__(*args, **kwargs)
class LfpAttributeError(PlenopticamError):
def __init__(self, *args, **kwargs):
super(LfpAttributeError, self).__init__(*args, **kwargs)
if self._lfp_path.lower().endswith(SUPP_FILE_EXT):
try:
self.decode_lytro_file()
except FileNotFoundError:
# print status
self.sta.status_msg('{0} not found'.format(os.path.basename(self._lfp_path)), self.cfg.params[self.cfg.opt_prnt])
self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])
self.sta.error = True
except Exception as e:
# unrecognized LFP file type
if not self._json_dict:
raise LfpTypeError(e, cfg=self.cfg)
else:
raise PlenopticamError(e, cfg=self.cfg, sta=self.sta)
else:
try:
# read and decode generic image file type
self._lfp_img = misc.load_img_file(self._lfp_path)
# inverse sRGB conversion
self._lfp_img = GammaConverter().srgb_conv(self._lfp_img, inverse=True)
except TypeError:
self.sta.status_msg('File type not recognized')
self.sta.error = True
return False
try:
# try to load json file (if present)
json_dict = self.cfg.load_json(self._lfp_path)
self.cfg.lfpimg = LfpDecoder.filter_lfp_json(json_dict, self.cfg.lfp_img)
except: