annotate irods_main.py @ 4:84f685c067ad draft default tip

"planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
author rhohensinner
date Wed, 04 Aug 2021 12:01:55 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
1 ___author___ = "Richard Hohensinner"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
2 ___created___ = "04.02.2021"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
3 ___last_modified___ = "20.05.2021"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
4
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
5 # general imports
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
6 import os, sys, json
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
7
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
8 from shutil import copyfile
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
9 from datetime import datetime
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
10 from irods_data import registry_content
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
11
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
12 # irods-client imports
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
13 from irods.session import iRODSSession
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
14 from irods.models import Collection, DataObject
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
15 from irods.query import SpecificQuery
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
16
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
17 # Tkinter imports
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
18 from tkinter import messagebox, Label, Button, Entry, Listbox, Tk, PhotoImage, Grid
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
19
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
20 # global variables
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
21 session = None
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
22 file_path_list = []
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
23 selected_file = ""
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
24 session_success = False
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
25 selection_success = False
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
26 iRODSCredentials = {"host": "", "port": "", "user": "", "pw": "", "zone": ""}
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
27 python_path = []
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
28
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
29 with open("reg.xml", "w") as xf:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
30 xf.write(registry_content)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
31 xf.close()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
32
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
33 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
34 # Main function of the iRODS tools
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
35 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
36 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
37 # JSON Object params (argv[1])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
38 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
39 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
40 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
41 def main():
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
42
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
43 # check input parameters
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
44 if len(sys.argv) == 2:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
45 params = json.loads(sys.argv[1])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
46 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
47 raise Exception("Invalid Parameters submitted!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
48
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
49 tool_type = params["tool_type"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
50
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
51 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
52 if params["tool_type"] != "up" and params["tool_type"] != "down":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
53 raise Exception("Invalid tool-type parameter submitted!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
54 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
55 raise Exception("No tool-type parameter submitted!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
56 is_download_call = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
57 if tool_type == "up":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
58 is_download_call = False
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
59
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
60 # check params for integrity
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
61 result_string, params_faulty = check_params(params)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
62
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
63 if params_faulty:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
64 raise Exception(result_string)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
65
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
66 global iRODSCredentials, session_success, selected_file, selection_success
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
67 iRODSCredentials["host"] = params["irods_host"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
68 iRODSCredentials["port"] = params["irods_port"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
69 iRODSCredentials["zone"] = params["irods_zone"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
70
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
71 # create login window
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
72 ## make_login_window(params)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
73 iRODSCredentials["user"] = params["irods_user"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
74 iRODSCredentials["pw"] = params["irods_password"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
75
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
76 host = iRODSCredentials["host"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
77 port = iRODSCredentials["port"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
78 user = iRODSCredentials["user"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
79 password = iRODSCredentials["pw"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
80 zone = iRODSCredentials["zone"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
81
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
82 iRODSsession = get_iRODS_connection(host=host, port=port, user=user, password=password, zone=zone)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
83 global session, session_success
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
84 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
85 coll = iRODSsession.collections.get("/" + zone + "/" + "home" + "/" + user)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
86 except Exception:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
87 raise Exception("Invalid Login")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
88
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
89 if coll:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
90 session = iRODSsession
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
91 session_success = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
92
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
93
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
94 # check tool settings and start tool execution
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
95 if session_success:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
96 # initialize download tool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
97 if params["tool_type"] == "down":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
98
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
99 selected_file = params["file_path"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
100 params["user"] = iRODSCredentials["pw"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
101 params["password"] = iRODSCredentials["user"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
102 # start download routine
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
103 handle_download_call(params)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
104
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
105 # initialize upload tool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
106 elif params["tool_type"] == "up":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
107
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
108 if session_success:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
109 params["user"] = iRODSCredentials["pw"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
110 params["password"] = iRODSCredentials["user"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
111 # start upload routine
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
112 handle_upload_call(params)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
113 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
114 raise Exception("Logging into iRODS failed")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
115 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
116 raise Exception("Logging into iRODS failed")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
117 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
118
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
119
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
120 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
121 # Login Window class for Tkinter
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
122 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
123 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
124 # Tk Window win
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
125 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
126 # (sets global variables iRODSCredentials, session and session_success)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
127 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
128 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
129 class LoginWindow:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
130 def __init__(self, win):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
131 self.window = win
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
132 self.lbl1 = Label(win, text='iRODS Username:')
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
133 self.lbl2 = Label(win, text='iRODS Password:')
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
134 self.t1 = Entry(bd=3)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
135 self.t2 = Entry(show="*")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
136 self.b1 = Button(win, text='Login', command=self.login)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
137
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
138 self.window.grid()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
139 Grid.rowconfigure(self.window, 0, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
140 Grid.rowconfigure(self.window, 1, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
141 Grid.rowconfigure(self.window, 2, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
142 Grid.rowconfigure(self.window, 3, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
143 Grid.rowconfigure(self.window, 4, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
144 Grid.columnconfigure(self.window, 0, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
145
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
146 self.lbl1.grid(row=0, column=0, padx="20", pady="1", sticky="w")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
147 self.t1.grid(row=1, column=0, padx="10", pady="1", sticky="nsew")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
148 self.lbl2.grid(row=2, column=0, padx="20", pady="1", sticky="w")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
149 self.t2.grid(row=3, column=0, padx="10", pady="1", sticky="nsew")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
150 self.b1.grid(row=4, column=0, padx="50", pady="10", sticky="nsew")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
151
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
152 def login(self):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
153 global iRODSCredentials
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
154 user = str(self.t1.get())
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
155 password = str(self.t2.get())
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
156 if user == "" or password == "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
157 self.window.iconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
158 messagebox.showerror("Error", "Username or Password empty!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
159 self.window.deiconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
160 return
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
161 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
162 iRODSCredentials["user"] = user
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
163 iRODSCredentials["pw"] = password
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
164
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
165 get_irods_session(self.window)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
166 if not session_success:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
167 return
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
168
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
169 self.window.destroy()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
170 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
171
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
172
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
173 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
174 # File Selection Window class for Tkinter
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
175 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
176 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
177 # Tk Window win
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
178 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
179 # (sets global variables selected_file and selection_success)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
180 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
181 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
182 class FileSelectWindow:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
183 def __init__(self, win):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
184 global session, iRODSCredentials
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
185 self.session = session
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
186 self.window = win
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
187 self.b1 = Button(win, text='Select', command=self.select)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
188 self.lb1 = Listbox(win)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
189
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
190 self.window.grid()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
191 Grid.rowconfigure(self.window, 0, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
192 Grid.rowconfigure(self.window, 1, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
193 Grid.columnconfigure(self.window, 0, weight=1)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
194
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
195 self.lb1.grid(row=0, column=0, padx="20", pady="1", sticky="nswe")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
196 self.b1.grid(row=1, column=0, padx="50", pady="1", sticky="ew")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
197
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
198 coll = session.collections.get("/" + iRODSCredentials["zone"] + "/" + "home" + "/" + iRODSCredentials["user"])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
199 file_list = []
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
200
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
201 self.get_files_from_collections(coll, file_list)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
202
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
203 for counter in range(len(file_list)):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
204 self.lb1.insert(counter, file_list[counter])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
205
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
206 def get_files_from_collections(self, coll, file_list):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
207 for obj in coll.data_objects:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
208 file_list.append(obj.path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
209
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
210 for col in coll.subcollections:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
211 self.get_files_from_collections(col, file_list)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
212
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
213 def select(self):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
214 global session, selected_file, selection_success
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
215 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
216 selection = self.lb1.get(self.lb1.curselection())
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
217 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
218 self.window.iconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
219 messagebox.showerror("Error", "No file selected!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
220 self.window.deiconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
221 return
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
222
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
223 selected_file = selection
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
224 selection_success = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
225 self.window.destroy()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
226 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
227
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
228
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
229 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
230 # Creates an iRODS session and sets the global session variable
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
231 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
232 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
233 # Tk Window window
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
234 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
235 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
236 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
237 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
238 def get_irods_session(window):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
239 global iRODSCredentials
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
240 host = iRODSCredentials["host"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
241 port = iRODSCredentials["port"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
242 user = iRODSCredentials["user"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
243 password = iRODSCredentials["pw"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
244 zone = iRODSCredentials["zone"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
245
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
246 iRODSsession = get_iRODS_connection(host=host, port=port, user=user, password=password, zone=zone)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
247 global session, session_success
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
248 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
249 coll = iRODSsession.collections.get("/" + zone + "/" + "home" + "/" + user)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
250 except Exception:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
251 window.iconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
252 messagebox.showerror("Error", "Invalid Authentification")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
253 window.deiconify()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
254 return
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
255
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
256 if coll:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
257 session = iRODSsession
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
258 session_success = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
259 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
260
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
261
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
262 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
263 # Helper function to initialize Login Window classes and Tk windows
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
264 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
265 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
266 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
267 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
268 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
269 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
270 def make_login_window(params):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
271 #get login icon
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
272 log_img = ""
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
273 for dirpath, dirnames, filenames in os.walk(params["galaxy_root"]):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
274 for fn in filenames:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
275 if fn == "irods_galaxy_login.png":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
276 log_img = os.path.join(dirpath, fn)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
277 if log_img != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
278 break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
279 if log_img != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
280 break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
281 # print(log_img)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
282
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
283 window = Tk()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
284 LoginWindow(window)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
285 window.title('iRODS Login')
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
286 window.geometry("450x225+10+10")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
287 window.minsize(450, 225)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
288 window.tk.call('wm', 'iconphoto', window._w, PhotoImage(file=log_img))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
289 # alternative options:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
290 # window.iconphoto(False, PhotoImage(file='/path/to/ico/icon.png'))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
291 # window.iconbitmap("/home/richard/git/galaxy_irods_tools/login.ico")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
292 window.mainloop()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
293 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
294
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
295
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
296 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
297 # Helper function to initialize File Selection Window classes and Tk windows
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
298 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
299 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
300 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
301 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
302 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
303 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
304 def make_file_select_window():
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
305 window = Tk()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
306 FileSelectWindow(window)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
307 window.title('iRODS File Select')
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
308 window.geometry("450x225+10+10")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
309 window.minsize(450, 225)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
310 window.mainloop()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
311 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
312
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
313
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
314 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
315 # Checks whether arguments are valid and returns true/false depending on params
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
316 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
317 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
318 # Dict params
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
319 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
320 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
321 # String res_string
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
322 # Bool res_bool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
323 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
324 def check_params(params):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
325 res_string = ""
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
326 res_bool = False
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
327
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
328 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
329 if params["irods_host"] == "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
330 res_string += "Host empty!\n"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
331 res_bool = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
332 if params["irods_port"] == "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
333 res_string += "Port empty!\n"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
334 res_bool = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
335 if params["irods_zone"] == "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
336 res_string += "Zone empty!\n"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
337 res_bool = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
338 ##if params["selection_type"] == "path" and params["file_path"] == "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
339 ## res_string += "Missing file path!\n"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
340 ## res_bool = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
341 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
342 raise Exception("Invalid/Missing Parameters")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
343
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
344 return res_string, res_bool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
345 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
346
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
347
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
348 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
349 # Function to handle iRODS download calls
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
350 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
351 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
352 # Dict params
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
353 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
354 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
355 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
356 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
357 def handle_download_call(params):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
358
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
359 global session, selected_file
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
360
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
361 # check if /ZONE/USER/...FILE... pattern is valid
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
362 if len(selected_file.split("/")) < 2:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
363 raise Exception("Path to file is not valid in iRODS")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
364
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
365 file_list = []
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
366
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
367 # check if file is a directory
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
368 if "." not in selected_file:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
369 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
370 coll = session.collections.get(selected_file)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
371 for file in coll.data_objects:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
372 file_list.append(file.path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
373 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
374 raise Exception("Invalid directory path specified!")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
375 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
376 file_list.append(selected_file)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
377
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
378 ## get registry file
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
379 #reg_file = ""
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
380 #for dirpath, dirnames, filenames in os.walk(params["galaxy_root"]):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
381 # for fn in filenames:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
382 # if fn == "irods_galaxy_registry.xml":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
383 # reg_file = os.path.join(dirpath, fn)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
384 # if reg_file != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
385 # break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
386 # if reg_file != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
387 # break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
388 reg_file = "reg.xml"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
389
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
390 # print(file_list)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
391 # print(os.getcwd())
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
392
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
393 # handle download for all files in file_list
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
394 for f in file_list:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
395
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
396 file_to_get = f
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
397
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
398 # handle path and file name
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
399 name_file_to_get = file_to_get.split("/")[-1]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
400 path_file_to_get = "/".join(file_to_get.split("/")[0:len(file_to_get.split("/")) - 1])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
401
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
402 # check iRODS filesystem
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
403 check_iRODS_destination(session, path_file_to_get, name_file_to_get)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
404
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
405 # get file object from iRODS
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
406 iRODS_file_object = session.data_objects.get(path_file_to_get + "/" + name_file_to_get)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
407 input_file = iRODS_file_object.open("r+")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
408 output_file = open(name_file_to_get, "wb")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
409 output_file.write(input_file.read())
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
410 #input_file.seek(0,0)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
411 #print(input_file.read().decode("utf-8"))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
412 #temp = open("/home/richard/test.txt", "w")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
413 #input_file.seek(0,0)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
414 #temp.write(input_file.read().decode("utf-8"))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
415
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
416 input_file.close()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
417 output_file.close()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
418
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
419 abs_file_path = os.path.abspath(name_file_to_get)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
420
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
421 file_type = str(name_file_to_get.split(".")[-1])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
422
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
423 file_content = {"uuid": None,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
424 "file_type": "auto",
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
425 "space_to_tab": False,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
426 "dbkey": "?",
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
427 "to_posix_lines": True,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
428 "ext": file_type,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
429 "path": abs_file_path,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
430 "in_place": True,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
431 "dataset_id": params["job_id"],
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
432 "type": "file",
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
433 "is_binary": False,
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
434 "link_data_only": "copy_files",
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
435 "name": name_file_to_get
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
436 }
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
437
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
438 with open("temporal.json", "w") as fileParams:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
439 fileParams.write(json.dumps(file_content))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
440 fileParams.close()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
441
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
442 # load file into Galaxy by using the integrated upload tool - Preparation
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
443 python_command = params["galaxy_root"] + "/tools/data_source/upload.py"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
444 arg1 = params["galaxy_root"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
445 arg2 = params["galaxy_datatypes"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
446 arg3 = os.path.abspath(fileParams.name)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
447 arg4 = params["job_id"] + ":" + params["out_dir"] + ":" + params["out_file"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
448 arg5 = params["galaxy_root"] + "/lib/galaxy"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
449
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
450 # copy sample registry.xml to working directory
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
451 copyfile(reg_file, params["galaxy_datatypes"])
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
452
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
453 # activate environment for new process call and call the python upload command either both with
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
454 #sys.path.append(params["galaxy_root"] + "/lib")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
455 #os.system("python -c \'import sys;sys.path.append(\"" + params["galaxy_root"] + "/lib\")\'" + "&& python3 " +
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
456 # python_command + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
457
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
458 # get upload file
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
459 upload_file = ""
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
460 for dirpath, dirnames, filenames in os.walk(params["galaxy_root"]):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
461 for fn in filenames:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
462 if fn == "irods_upload.py":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
463 upload_file = os.path.join(dirpath, fn)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
464 if upload_file != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
465 break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
466 if upload_file != "":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
467 break
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
468 sys.path.append(params["galaxy_root"] + "/lib")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
469 #sys.path.append(params["galaxy_root"] + "/tools/data_source")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
470 #sys.path.append(params["galaxy_root"] + "/.venv/lib/python3.8/site-packages")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
471 with open("python__path.txt", "w") as pp:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
472 pp.truncate(0)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
473 for item in sys.path:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
474 pp.write(item + ",")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
475
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
476 os.system(params["galaxy_root"] + "/.venv/bin/python " + upload_file + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
477 # close connection
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
478 session.cleanup()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
479 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
480
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
481
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
482 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
483 # Function to handle iRODS upload calls
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
484 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
485 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
486 # Dict params
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
487 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
488 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
489 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
490 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
491 def handle_upload_call(params):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
492
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
493 global session, iRODSCredentials
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
494
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
495 path_to_file = params["up_file_path"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
496 name_of_file = params["up_file"]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
497 #print(path_to_file)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
498 #print(name_of_file)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
499
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
500 coll_path = "/" + iRODSCredentials["zone"] + "/home/" + iRODSCredentials["user"] + "/galaxyupload"
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
501 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
502 coll = session.collections.get(coll_path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
503 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
504 coll = session.collections.create(coll_path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
505
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
506 now = datetime.now()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
507
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
508 # dd/mm/YY
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
509 day = now.strftime("%d%m%Y")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
510 time = now.strftime("%H%M%S")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
511
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
512 coll_path = coll_path + "/" + day
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
513
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
514 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
515 coll = session.collections.get(coll_path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
516 except:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
517 coll = session.collections.create(coll_path)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
518
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
519 if "/" in name_of_file:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
520 name_of_file = name_of_file.split("/")[-1]
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
521
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
522 irods_file_name = time + "_" + name_of_file
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
523 iRODS_file_object = session.data_objects.create(coll_path + "/" + irods_file_name)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
524 iRODS_file_object = session.data_objects.get(coll_path + "/" + irods_file_name)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
525
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
526 irods_file = iRODS_file_object.open("w")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
527 galaxy_file = open(path_to_file, "rb")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
528 content = galaxy_file.read()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
529 irods_file.write(content)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
530
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
531 print("Successfully uploaded: " + name_of_file + "\n as: " + irods_file_name)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
532 # TODO can't close session without writing process finished - but reading/writing happens async.
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
533 # session.cleanup()
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
534
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
535 pass
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
536 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
537
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
538
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
539 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
540 # Function to initialize an iRODS Session - will raise an Exception if timeout is longer than 2 seconds
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
541 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
542 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
543 # String host
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
544 # String port
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
545 # String user
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
546 # String password
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
547 # String zone
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
548 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
549 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
550 # iRODSSession-object session
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
551 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
552 def get_iRODS_connection(host, port, user, password, zone):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
553
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
554 # initialize timeout checker - fires after 2 secs
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
555 import signal
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
556 signal.signal(signal.SIGALRM, timeout_checker)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
557 signal.alarm(2)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
558
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
559 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
560 session = iRODSSession(host=host, port=port, user=user, password=password, zone=zone)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
561 except Exception:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
562 raise Exception("There was a timeout creating the iRODS session")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
563
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
564 # void/reset alarm
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
565 signal.alarm(0)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
566
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
567 return session
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
568 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
569
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
570
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
571 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
572 # Helper function to raise timeout exception when SIGALRM fires
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
573 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
574 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
575 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
576 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
577 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
578 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
579 def timeout_checker():
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
580
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
581 raise Exception("iRODS session timeout")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
582 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
583
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
584
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
585 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
586 # Function to check if file exists in iRODS
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
587 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
588 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
589 # String path
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
590 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
591 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
592 # Bool ret_bool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
593 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
594 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
595 def check_if_file_exists(path):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
596
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
597 if os.path.isfile(path):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
598 ret_bool = True
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
599 else:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
600 ret_bool = False
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
601
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
602 return ret_bool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
603 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
604
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
605
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
606 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
607 # Function to check iRODS destination
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
608 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
609 # IN:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
610 # iRODSSession-object session
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
611 # String path
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
612 # String name
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
613 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
614 # OUT:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
615 # Bool ret_bool
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
616 #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
617 ########################################################################################################################
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
618 def check_iRODS_destination(session, path, name):
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
619
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
620 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
621 session.collections.get(path.rstrip("/"))
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
622 except Exception:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
623 raise Exception("Collection doesn't exist in iRODS file system")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
624
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
625 try:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
626 session.data_objects.get(path.rstrip("/") + "/" + name)
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
627 except Exception:
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
628 raise Exception("File doesn't exist in iRODS file system")
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
629 # -------------------------------------------------------------------------------------------------------------------- #
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
630
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
631
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
632 if __name__ == "__main__":
84f685c067ad "planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
rhohensinner
parents:
diff changeset
633 main()