annotate main.py @ 1:19c1cecdfdfd draft

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