repeat
copytree_no_metadata(src, dst, ignore)
¶
Copy directory contents, without permissions or extended attributes
Copying the GPFS ACLs can cause problems when creating new files in the directory, so we avoid that. shutil.copytree can skip copying file metadata, but not directory metadata: https://github.com/python/cpython/issues/89721
This is also simplified by removing options we're not using.
Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/xfel_calibrate/repeat.py
def copytree_no_metadata(src, dst, ignore):
"""Copy directory contents, without permissions or extended attributes
Copying the GPFS ACLs can cause problems when creating new files in
the directory, so we avoid that. shutil.copytree can skip copying file
metadata, but not directory metadata:
https://github.com/python/cpython/issues/89721
This is also simplified by removing options we're not using.
"""
with os.scandir(src) as itr:
entries = list(itr)
if ignore is not None:
ignored_names = ignore(os.fspath(src), [x.name for x in entries])
else:
ignored_names = set()
os.makedirs(dst)
errors = []
for srcentry in entries:
if srcentry.name in ignored_names:
continue
srcname = os.path.join(src, srcentry.name)
dstname = os.path.join(dst, srcentry.name)
try:
if srcentry.is_dir():
copytree_no_metadata(srcentry, dstname, ignore)
else:
# Will raise a SpecialFileError for unsupported file types
shutil.copyfile(srcentry, dstname)
# catch the Error from the recursive copytree so that we can
# continue with other files
except shutil.Error as err:
errors.extend(err.args[0])
except OSError as why:
errors.append((srcname, dstname, str(why)))
if errors:
raise shutil.Error(errors)
return dst
update_notebooks_params(working_dir, new_values)
¶
Modify parameters in copied notebooks
Source code in /usr/src/app/checkouts/readthedocs.org/user_builds/european-xfel-offline-calibration/envs/latest/lib/python3.8/site-packages/xfel_calibrate/repeat.py
def update_notebooks_params(working_dir: Path, new_values):
"""Modify parameters in copied notebooks"""
for nb_file in working_dir.glob('*.ipynb'):
nb = nbformat.read(nb_file, as_version=4)
params = extract_parameters(nb, lang='python')
params = parameter_values(params, **new_values)
new_nb = replace_definitions(nb, params, execute=False, lang='python')
nbformat.write(new_nb, nb_file)