-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathiinit.py
More file actions
executable file
·48 lines (37 loc) · 1.37 KB
/
iinit.py
File metadata and controls
executable file
·48 lines (37 loc) · 1.37 KB
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
48
#!/usr/bin/env python
# This script creates the client environment to authenticate natively
# as the 'rods' admin on the Docker node running the Python client tests.
# Thus, we don't need irods-icommands to be installed on that node.
from irods.password_obfuscation import encode
import json
import os
import sys
from os import chmod
from os.path import expanduser,exists,join
from getopt import getopt
home_env_path = expanduser('~/.irods')
env_file_path = join(home_env_path,'irods_environment.json')
auth_file_path = join(home_env_path,'.irodsA')
def do_iinit(host, port, user, zone, password):
if not exists(home_env_path):
os.makedirs(home_env_path)
else:
raise RuntimeError('~/.irods already exists')
with open(env_file_path,'w') as env_file:
json.dump ( { "irods_host": host,
"irods_port": int(port),
"irods_user_name": user,
"irods_zone_name": zone }, env_file, indent=4)
with open(auth_file_path,'w') as auth_file:
auth_file.write(encode(password))
chmod (auth_file_path,0o600)
def get_kv_pairs_from_cmdline(*args):
arglist = list(args)
while arglist:
k = arglist.pop(0)
v = arglist.pop(0)
yield k,v
if __name__ == '__main__':
args = sys.argv[1:]
dct = {k:v for k,v in get_kv_pairs_from_cmdline(*args)}
do_iinit(**dct)