-
Notifications
You must be signed in to change notification settings - Fork 0
/
irods2bisque_lmu.py
executable file
·119 lines (102 loc) · 4.34 KB
/
irods2bisque_lmu.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
import base64
import getpass
import logging
from optparse import OptionParser
from bisque import BisqueConnection
import imeta
import iquest
import iutils
IRODS_DEFAULT_HOST='irods://ida.csc.fi'
BISQUE_DEFAULT_HOST='https://lmu-bisque1.biocenter.helsinki.fi'
logger = logging.getLogger(__name__)
usage = """%prog [options] irods_data
Register files from an irods repository with a bisque server.
See %prog -h for options.
"""
def main():
irods_host = IRODS_DEFAULT_HOST
bisque_host = BISQUE_DEFAULT_HOST
parser = OptionParser(usage=usage)
parser.add_option('-l', '--list', action="store_true", default=False,
help="list contents of irods url and exit")
parser.add_option('-n', '--dryrun', action="store_true", default=False,
help="print actions but do not execute.. sets verbose")
parser.add_option('-i', '--irods_host', help="e.g. irods://ida.csc.fi")
parser.add_option('-b', '--bisque_host', help="e.g. https://bisquevm-1.it.helsinki.fi")
parser.add_option('-v', '--verbose', action="store_true", default=False, help="be verbose")
options, args = parser.parse_args()
if len(args)>0:
irods_data = args.pop(0)
else:
parser.error("No irods data given.")
# set log level
if options.verbose:
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
elif options.dryrun:
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
else:
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.CRITICAL)
# check server URLs
if options.irods_host:
irods_host = options.irods_host
if not irods_host or not irods_host.startswith('irods://'):
parser.error ('must include a valid iRODS url i.e. %s' % IRODS_DEFAULT_HOST)
if options.bisque_host:
bisque_host = options.bisque_host
if not bisque_host or not (bisque_host.startswith('http://') or bisque_host.startswith('https://') ):
parser.error ("Invalid Bisque host URL '%s'.\nPlease specify valid HTTP URL i.e. '%s'." % (bisque_host, BISQUE_DEFAULT_HOST))
if bisque_host.startswith('http://') :
logging.warning("Using plain HTTP, passwords will be sent unencrypted.")
DATA_IS_COLLECTION = False
DATA_IS_SINGLE_OBJECT = False
# check if user specified a collection or a single dataobject
DATA_IS_COLLECTION = iquest.collection_exists(irods_data)
if not DATA_IS_COLLECTION:
DATA_IS_SINGLE_OBJECT = iquest.dataobject_exists(irods_data)
# check if the collection or data exists
if not DATA_IS_COLLECTION and not DATA_IS_SINGLE_OBJECT:
# user probably didn't give full path starting from /ZONE/home/...
# try in the current irods directory
irods_data_orig = irods_data
iutils.icd2ipwd()
root = iutils.ipwd()
irods_data = root + "/" + irods_data
DATA_IS_COLLECTION = iquest.collection_exists(irods_data)
if not DATA_IS_COLLECTION:
DATA_IS_SINGLE_OBJECT = iquest.dataobject_exists(irods_data)
if not DATA_IS_COLLECTION and not DATA_IS_SINGLE_OBJECT:
parser.error("File or collection '" + irods_data_orig + "' not found in " + irods_host + ".")
if DATA_IS_COLLECTION:
entries = iquest.list_dataobjects_recursive(irods_data)
else:
entries = []
entries.append(irods_data)
if options.list:
for e in entries:
print e
return
# ask user for bisque username/password
print
print "Please login to Bisque with your University AD username and password."
bisque_user = getpass.getuser()
print "Username:", bisque_user
bisque_password = getpass.getpass()
if not bisque_user or not bisque_password:
parser.error('Username/password needs to be provided for uploads.')
bisque = BisqueConnection(bisque_host, bisque_user, bisque_password)
for irods_file in entries:
bisque.register_irods_file(irods_host, irods_file, options.dryrun)
import cProfile, pstats, StringIO
if __name__ == "__main__":
pr = cProfile.Profile()
pr.enable()
# ... do something ...
main()
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print s.getvalue()
#main()