Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
corrupted = []
logger.info("Checking workspace for corruption...")
for job_id in self._find_job_ids():
try:
sp = self._get_statepoint(job_id)
if calc_id(sp) != job_id:
corrupted.append(job_id)
else:
self.open_job(sp).init()
except JobsCorruptedError as error:
corrupted.extend(error.job_ids)
if corrupted:
logger.error(
"At least one job appears to be corrupted. Call Project.repair() "
"to try to fix errors.")
raise JobsCorruptedError(corrupted)
try:
# Try to reinit the job (triggers state point manifest file check).
job.init()
except Exception as error:
logger.error(
"Error during initalization of job with "
"id '{}': '{}'.".format(job_id, error))
try: # Attempt to fix the job manifest file.
job.init(force=True)
except Exception as error2:
logger.critical(
"Unable to force init job with id "
"'{}': '{}'.".format(job_id, error2))
corrupted.append(job_id)
if corrupted:
raise JobsCorruptedError(corrupted)
def _check_manifest(self):
"Check whether the manifest file, if it exists, is correct."
fn_manifest = os.path.join(self._wd, self.FN_MANIFEST)
try:
with open(fn_manifest, 'rb') as file:
assert calc_id(json.loads(file.read().decode())) == self._id
except IOError as error:
if error.errno != errno.ENOENT:
raise error
except (AssertionError, ValueError):
raise JobsCorruptedError([self._id])
def _check_manifest(self):
"Check whether the manifest file, if it exists, is correct."
fn_manifest = os.path.join(self._wd, self.FN_MANIFEST)
try:
try:
with open(fn_manifest, 'rb') as file:
assert calc_id(json.loads(file.read().decode())) == self._id
except IOError as error:
if error.errno != errno.ENOENT:
raise error
except Exception as error:
logger.error(
"State point manifest file of job '{}' appears to be corrupted.".format(self._id))
raise JobsCorruptedError([self._id])
def _get_statepoint_from_workspace(self, jobid):
"Attempt to read the statepoint from the workspace."
fn_manifest = os.path.join(self._wd, jobid, self.Job.FN_MANIFEST)
try:
with open(fn_manifest, 'rb') as manifest:
return json.loads(manifest.read().decode())
except (IOError, ValueError) as error:
if os.path.isdir(os.path.join(self._wd, jobid)):
logger.error(
"Error while trying to access state "
"point manifest file of job '{}': '{}'.".format(jobid, error))
raise JobsCorruptedError([jobid])
raise KeyError(jobid)