|
| 1 | +import os |
| 2 | +import glob |
| 3 | +import zipfile |
| 4 | +from PyQt5.QtWidgets import QMessageBox |
| 5 | + |
| 6 | +try: |
| 7 | + from galaxy_ie_helpers import put |
| 8 | +except: |
| 9 | + pass |
| 10 | + |
| 11 | +#----------------------------------------------------------------- |
| 12 | +# Helper functions for Galaxy |
| 13 | +def save_project_galaxy(self): |
| 14 | + fname = "my_model.zip" |
| 15 | + file_str = "config/*.csv" |
| 16 | + file_str = os.path.join(os.getcwd(), file_str) |
| 17 | + print('-------- save_project_galaxy(): zip up all ',file_str) |
| 18 | + |
| 19 | + msgBox = QMessageBox() |
| 20 | + msgBox.setText(f"This will start a job that bundles your current model's config file, its cells and substrates ICs, and its rules, and creates and copies '{fname}' to the Galaxy History. You can download it from there once it completes.") |
| 21 | + msgBox.setIcon(QMessageBox.Information) |
| 22 | + msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
| 23 | + returnValue = msgBox.exec() |
| 24 | + if returnValue == QMessageBox.Cancel: |
| 25 | + return |
| 26 | + |
| 27 | + try: |
| 28 | + with zipfile.ZipFile(fname, 'w') as myzip: |
| 29 | + # myzip.write(self.current_xml_file) |
| 30 | + myzip.write(self.current_xml_file, os.path.basename(self.current_xml_file)) |
| 31 | + for f in glob.glob(file_str): |
| 32 | + myzip.write(f, os.path.basename(f)) # 2nd arg avoids full filename |
| 33 | + # csv_files = glob.glob(file_str) |
| 34 | + # print("csv_files = ",csv_files) |
| 35 | + # for f in glob.glob(file_str): |
| 36 | + # myzip.write(f, os.path.basename(f)) # 2nd arg avoids full filename |
| 37 | + put(fname) |
| 38 | + # print("dummy put...") |
| 39 | + except: |
| 40 | + self.show_error_message(f"Error: put({fname})") |
| 41 | + return |
| 42 | + |
| 43 | + |
| 44 | +def load_project_galaxy_history(self): |
| 45 | + from galaxy_history import LoadProjectWindow |
| 46 | + self.project_historyUI = LoadProjectWindow() |
| 47 | + self.project_historyUI.xml_creator = self |
| 48 | + # hack to bring to foreground |
| 49 | + self.project_historyUI.hide() |
| 50 | + self.project_historyUI.show() |
| 51 | + |
| 52 | +def get_galaxy_history(self): |
| 53 | + from galaxy_history import GalaxyHistoryWindow |
| 54 | + self.galaxy_historyUI = GalaxyHistoryWindow(self) |
| 55 | + # hack to bring to foreground |
| 56 | + self.galaxy_historyUI.hide() |
| 57 | + self.galaxy_historyUI.show() |
| 58 | + |
| 59 | +def download_config_galaxy(self): |
| 60 | + # put("config/PhysiCell_settings.xml") |
| 61 | + # put( args.filepath, file_type=args.filetype, history_id=args.history_id ) |
| 62 | + # fname = "/opt/pcstudio/config/PhysiCell_settings.xml" |
| 63 | + fname = self.current_xml_file |
| 64 | + msgBox = QMessageBox() |
| 65 | + msgBox.setText("This will start a job that copies your current model's config file to the Galaxy History. You can download it from there once it completes.") |
| 66 | + msgBox.setIcon(QMessageBox.Information) |
| 67 | + msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
| 68 | + returnValue = msgBox.exec() |
| 69 | + if returnValue == QMessageBox.Cancel: |
| 70 | + return |
| 71 | + try: |
| 72 | + put(fname) |
| 73 | + # print("dummy put...") |
| 74 | + except: |
| 75 | + self.show_error_message(f"Error: put({fname})") |
| 76 | + return |
| 77 | + |
| 78 | +def download_zipped_csv_galaxy(self): |
| 79 | + # fname = "/opt/pcstudio/all_csv.zip" |
| 80 | + msgBox = QMessageBox() |
| 81 | + msgBox.setText("This will start a job that copies a zip file of all output/*.csv to the Galaxy History. You can download it from there once it completes.") |
| 82 | + msgBox.setIcon(QMessageBox.Information) |
| 83 | + msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
| 84 | + returnValue = msgBox.exec() |
| 85 | + if returnValue == QMessageBox.Cancel: |
| 86 | + return |
| 87 | + fname = "all_csv.zip" |
| 88 | + print("download_zipped_csv_galaxy(): cwd= ",os.getcwd()) |
| 89 | + try: |
| 90 | + # file_str = "/opt/pcstudio/output/*.csv" |
| 91 | + file_str = "output/*.csv" |
| 92 | + file_str = os.path.join(os.getcwd(), file_str) |
| 93 | + print('-------- download_zipped_csv_galaxy(): zip up all ',file_str) |
| 94 | + # fname = "/opt/pcstudio/output/all_csv.zip" |
| 95 | + with zipfile.ZipFile(fname, 'w') as myzip: |
| 96 | + # csv_files = glob.glob(file_str) |
| 97 | + # print("csv_files = ",csv_files) |
| 98 | + for f in glob.glob(file_str): |
| 99 | + myzip.write(f, os.path.basename(f)) # 2nd arg avoids full filename |
| 100 | + except: |
| 101 | + self.show_error_message(f"Error zipping all output/*.csv") |
| 102 | + return |
| 103 | + |
| 104 | + try: |
| 105 | + put(fname) |
| 106 | + # print("dummy put...") |
| 107 | + except: |
| 108 | + self.show_error_message(f"Error: put({fname})") |
| 109 | + |
| 110 | +def download_all_zipped_galaxy(self): |
| 111 | + # fname = "/opt/pcstudio/all_output.zip" |
| 112 | + msgBox = QMessageBox() |
| 113 | + msgBox.setText("This will start a job that copies a zip file of all output/* to the Galaxy History. You can download it from there once it completes. If you have a lot of output files from your simulation, it may take a while to complete, but it runs in the background and will not affect your ability to continue using the Studio.") |
| 114 | + msgBox.setIcon(QMessageBox.Information) |
| 115 | + msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
| 116 | + returnValue = msgBox.exec() |
| 117 | + if returnValue == QMessageBox.Cancel: |
| 118 | + return |
| 119 | + |
| 120 | + fname = "all_output.zip" |
| 121 | + print("download_all_zipped_galaxy(): cwd= ",os.getcwd()) |
| 122 | + try: |
| 123 | + # file_str = "/opt/pcstudio/output/*.csv" |
| 124 | + file_str = "output/*" |
| 125 | + file_str = os.path.join(os.getcwd(), file_str) |
| 126 | + print('-------- download_all_zipped_galaxy(): zip up all ',file_str) |
| 127 | + # fname = "/opt/pcstudio/output/all_csv.zip" |
| 128 | + with zipfile.ZipFile(fname, 'w') as myzip: |
| 129 | + # all_files = glob.glob(file_str) |
| 130 | + # print("all_files = ",all_files) |
| 131 | + for f in glob.glob(file_str): |
| 132 | + myzip.write(f, os.path.basename(f)) # 2nd arg avoids full filename |
| 133 | + except: |
| 134 | + self.show_error_message(f"Error zipping all output/*") |
| 135 | + return |
| 136 | + |
| 137 | + try: |
| 138 | + put(fname) |
| 139 | + # print("dummy put") |
| 140 | + except: |
| 141 | + self.show_error_message(f"Error: put({fname})") |
0 commit comments