Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:raises OSError:
If the move failed due to an unknown system related error.
"""
dst = self._project.open_job(new_statepoint)
if dst == self:
return
fn_manifest = os.path.join(self._wd, self.FN_MANIFEST)
fn_manifest_backup = fn_manifest + '~'
try:
os.replace(fn_manifest, fn_manifest_backup)
try:
os.replace(self.workspace(), dst.workspace())
except OSError as error:
os.replace(fn_manifest_backup, fn_manifest) # rollback
if error.errno in (errno.ENOTEMPTY, errno.EACCES):
raise DestinationExistsError(dst)
else:
raise
else:
dst.init()
except OSError as error:
if error.errno == errno.ENOENT:
pass # job is not initialized
else:
raise
# Update this instance
self._statepoint._data = dst._statepoint._data
self._id = dst._id
self._wd = dst._wd
self._fn_doc = dst._fn_doc
self._document = None
self._data = None
def _copy_to_job_workspace(src, job, copytree):
dst = job.workspace()
try:
copytree(src, dst)
except (IOError, OSError) as error:
if error.errno in (errno.ENOTEMPTY, errno.EEXIST):
raise DestinationExistsError(job)
raise
else:
job._init()
return dst
:raises OSError:
If the move failed due to an unknown system related error.
"""
dst = self._project.open_job(new_statepoint)
if dst == self:
return
fn_manifest = os.path.join(self._wd, self.FN_MANIFEST)
fn_manifest_backup = fn_manifest + '~'
try:
os.rename(fn_manifest, fn_manifest_backup)
try:
os.rename(self.workspace(), dst.workspace())
except OSError as error:
os.rename(fn_manifest_backup, fn_manifest) # rollback
if error.errno == errno.ENOTEMPTY:
raise DestinationExistsError(dst)
else:
raise
else:
dst.init()
except OSError as error:
if error.errno == errno.ENOENT:
pass # job is not initialized
else:
raise
logger.info("Moved '{}' -> '{}'.".format(self, dst))
dst._statepoint = self._statepoint
self.__dict__.update(dst.__dict__)
dirs = {os.path.dirname(name) for name in names}
for name in sorted(dirs):
cont = False
for skip in skip_subdirs:
if name.startswith(skip):
cont = True
break
if cont:
continue
sp = schema_function(name)
if sp is not None:
job = project.open_job(sp)
if os.path.exists(job.workspace()):
raise DestinationExistsError(job)
mappings[name] = job
skip_subdirs.add(name)
# Check uniqueness
if len(set(mappings.values())) != len(mappings):
raise RuntimeError("The jobs identified with the given schema function are not unique!")
for path, job in mappings.items():
_names = [name for name in names if name.startswith(path)]
yield path, _CopyFromZipFileExecutor(zipfile, path, job, _names)
:raises RuntimeError:
If the job is not initialized or the destination is on a different
device.
:raises OSError:
When the move failed due unexpected file system issues.
"""
dst = project.open_job(self.statepoint())
_mkdir_p(project.workspace())
try:
os.replace(self.workspace(), dst.workspace())
except OSError as error:
if error.errno == errno.ENOENT:
raise RuntimeError(
"Cannot move job '{}', because it is not initialized!".format(self))
elif error.errno in (errno.EEXIST, errno.ENOTEMPTY, errno.EACCES):
raise DestinationExistsError(dst)
elif error.errno == errno.EXDEV:
raise RuntimeError(
"Cannot move jobs across different devices (file systems).")
else:
raise error
self.__dict__.update(dst.__dict__)
raise TypeError("The schema variable must be None, callable, or a string.")
mappings = dict()
skip_subdirs = set()
dirs = [member.name for member in tarfile.getmembers() if member.isdir()]
for name in sorted(dirs):
if os.path.dirname(name) in skip_subdirs: # skip all sub-dirs of identified dirs
skip_subdirs.add(name)
continue
sp = schema_function(name)
if sp is not None:
job = project.open_job(sp)
if os.path.exists(job.workspace()):
raise DestinationExistsError(job)
mappings[name] = job
skip_subdirs.add(name)
# Check uniqueness
if len(set(mappings.values())) != len(mappings):
raise StatepointParsingError(
"The jobs identified with the given schema function are not unique!")
tarfile.extractall(path=tmpdir)
for path, job in mappings.items():
src = os.path.join(tmpdir, path)
assert os.path.isdir(tmpdir)
assert os.path.isdir(src)
yield src, _CopyFromTarFileExecutor(src, job)