Mercurial > repos > rhohensinner > galaxy_irods_interface
diff main.py @ 2:0641ea2f75b1 draft
"planemo upload commit b2a00d9c24285fef0fb131d1832ecf4c337e5038-dirty"
author | rhohensinner |
---|---|
date | Fri, 02 Jul 2021 09:40:25 +0000 |
parents | 19c1cecdfdfd |
children | d2be2eb8350f |
line wrap: on
line diff
--- a/main.py Wed Jun 23 10:40:19 2021 +0000 +++ b/main.py Fri Jul 02 09:40:25 2021 +0000 @@ -4,6 +4,8 @@ # general imports import os, sys, json +import irods_upload + from shutil import copyfile from datetime import datetime @@ -63,27 +65,38 @@ iRODSCredentials["zone"] = params["irods_zone"] # create login window - make_login_window(params) + ## make_login_window(params) + iRODSCredentials["user"] = params["irods_user"] + iRODSCredentials["pw"] = params["irods_password"] + + host = iRODSCredentials["host"] + port = iRODSCredentials["port"] + user = iRODSCredentials["user"] + password = iRODSCredentials["pw"] + zone = iRODSCredentials["zone"] + + iRODSsession = get_iRODS_connection(host=host, port=port, user=user, password=password, zone=zone) + global session, session_success + try: + coll = iRODSsession.collections.get("/" + zone + "/" + "home" + "/" + user) + except Exception: + raise Exception("Invalid Login") + + if coll: + session = iRODSsession + session_success = True + + # check tool settings and start tool execution if session_success: # initialize download tool if params["tool_type"] == "down": - if params["selection_type"] == "explorer": - make_file_select_window() - else: - if (params["file_path"] != ""): #and ("/" in params["file_path"]): - selected_file = params["file_path"] - else: - raise Exception("Invalid File Path submitted!") - - if selection_success or params["selection_type"] == "path": - params["user"] = iRODSCredentials["pw"] - params["password"] = iRODSCredentials["user"] - # start download routine - handle_download_call(params) - else: - raise Exception("File Selection failed (No file selected)") + selected_file = params["file_path"] + params["user"] = iRODSCredentials["pw"] + params["password"] = iRODSCredentials["user"] + # start download routine + handle_download_call(params) # initialize upload tool elif params["tool_type"] == "up": @@ -261,7 +274,7 @@ break if log_img != "": break - print(log_img) + # print(log_img) window = Tk() LoginWindow(window) @@ -318,9 +331,9 @@ if params["irods_zone"] == "": res_string += "Zone empty!\n" res_bool = True - if params["selection_type"] == "path" and params["file_path"] == "": - res_string += "Missing file path!\n" - res_bool = True + ##if params["selection_type"] == "path" and params["file_path"] == "": + ## res_string += "Missing file path!\n" + ## res_bool = True except: raise Exception("Invalid/Missing Parameters") @@ -369,10 +382,13 @@ if reg_file != "": break + # print(file_list) + # print(os.getcwd()) + # handle download for all files in file_list - for file in file_list: + for f in file_list: - file_to_get = file + file_to_get = f # handle path and file name name_file_to_get = file_to_get.split("/")[-1] @@ -386,7 +402,12 @@ input_file = iRODS_file_object.open("r+") output_file = open(name_file_to_get, "wb") output_file.write(input_file.read()) - + #input_file.seek(0,0) + #print(input_file.read().decode("utf-8")) + #temp = open("/home/richard/test.txt", "w") + #input_file.seek(0,0) + #temp.write(input_file.read().decode("utf-8")) + input_file.close() output_file.close() @@ -424,10 +445,22 @@ copyfile(reg_file, params["galaxy_datatypes"]) # activate environment for new process call and call the python upload command either both with - sys.path.append(params["galaxy_root"] + "/lib") - os.system("python -c \'import sys;sys.path.append(\"" + params["galaxy_root"] + "/lib\")\'" + " python " + - python_command + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4) - + #sys.path.append(params["galaxy_root"] + "/lib") + #os.system("python -c \'import sys;sys.path.append(\"" + params["galaxy_root"] + "/lib\")\'" + "&& python3 " + + # python_command + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4) + + # get upload file + upload_file = "" + for dirpath, dirnames, filenames in os.walk(params["galaxy_root"]): + for fn in filenames: + if fn == "irods_upload.py": + upload_file = os.path.join(dirpath, fn) + if upload_file != "": + break + if upload_file != "": + break + + os.system("python " + upload_file + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4) # close connection session.cleanup() # -------------------------------------------------------------------------------------------------------------------- # @@ -448,6 +481,8 @@ path_to_file = params["up_file_path"] name_of_file = params["up_file"] + #print(path_to_file) + #print(name_of_file) coll_path = "/" + iRODSCredentials["zone"] + "/home/" + iRODSCredentials["user"] + "/galaxyupload" try: @@ -467,7 +502,10 @@ coll = session.collections.get(coll_path) except: coll = session.collections.create(coll_path) - + + if "/" in name_of_file: + name_of_file = name_of_file.split("/")[-1] + irods_file_name = time + "_" + name_of_file iRODS_file_object = session.data_objects.create(coll_path + "/" + irods_file_name) iRODS_file_object = session.data_objects.get(coll_path + "/" + irods_file_name) @@ -477,6 +515,7 @@ content = galaxy_file.read() irods_file.write(content) + print("Successfully uploaded: " + name_of_file + "\n as: " + irods_file_name) # TODO can't close session without writing process finished - but reading/writing happens async. # session.cleanup()