-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyfile.py
47 lines (42 loc) · 1.9 KB
/
copyfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import re
import shutil
from agavehelpers import resilient_files_pems
def copyfile(r, posix_src, posix_dest, agave_dest=None):
# Create POSIX directory path at destination
do_validate = not r.local
try:
dest_parent = os.path.dirname(posix_dest)
os.makedirs(dest_parent, exist_ok=True)
except Exception as exc:
r.on_failure('Mkdir {} failed.'.format(dest_parent), exc)
# Do POSIX copy with forced overwrite
try:
shutil.copy(posix_src, posix_dest)
except Exception as exc:
r.on_failure('Copy from {} failed.'.format(posix_src), exc)
if agave_dest is not None:
# Do Agave permission grants on the copied file
for grant in r.settings.destination.grants:
r.logger.debug('Grant {} to {} on {}'.format(
grant.pem, grant.username, agave_dest))
if r.local is False:
try:
resilient_files_pems(r.client, agave_dest, grant.username,
grant.pem, grant.recursive)
except Exception:
r.logger.warning('Grant failed for {}'.format(agave_dest))
# # Do Agave permission grants on created parent directories
# if created_path is not None:
# agave_path_list = get_agave_parents(
# created_path, r.settings.destination.posix_path,
# r.settings.destination.bucket)
# r.logger.debug('Do grants for {}'.format(agave_path_list))
# if r.local is False:
# for ag_uri in agave_path_list:
# for grant in r.settings.destination.grants:
# try:
# resilient_files_pems(r.client, ag_uri, grant.username,
# grant.pem, grant.recursive)
# except Exception:
# r.logger.warning('Grant failed for {}'.format(ag_uri))