-
Notifications
You must be signed in to change notification settings - Fork 0
/
irods_upload.py
47 lines (34 loc) · 1.47 KB
/
irods_upload.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
from gooey import Gooey, GooeyParser
from irods.session import iRODSSession
@Gooey(dump_build_config=False, program_name="IRODS Uploader")
def main():
desc = "Upload a file to IRODS Data Store"
file_help_msg = "Name of the file you want to process"
my_cool_parser = GooeyParser(description=desc)
my_cool_parser.add_argument("UserName", type=str,
help='Your CyVerse username')
my_cool_parser.add_argument(
"FileChooser", help=file_help_msg, widget="FileChooser")
args = my_cool_parser.parse_args()
# Do stuff with parsed parameters
full_local_path = args.FileChooser
just_file_name = args.FileChooser.split('/')[-1:][0]
username = args.UserName
upload_file(username=username,
local_path=full_local_path,
remote_name=just_file_name)
def upload_file(username, local_path, remote_name):
print(
f'Uploading "{local_path}" to "/iplant/home/{username}/{remote_name}"')
try:
env_file = os.environ['IRODS_ENVIRONMENT_FILE']
except KeyError:
env_file = os.path.expanduser('~/.irods/irods_environment.json')
with iRODSSession(irods_env_file=env_file) as session:
remote_path = f'/iplant/home/{username}/{remote_name}'
session.data_objects.put(local_path, remote_path)
placed_object = session.data_objects.get(remote_path)
print(f'placed_object.id: {placed_object.id}')
if __name__ == '__main__':
main()