From 1f4f1c3e0b0808f6d51d3e08dbb5f863e1eeee09 Mon Sep 17 00:00:00 2001 From: luisodls Date: Fri, 6 Dec 2019 11:23:55 +0000 Subject: [PATCH] commenting (ready to remove) the handling of output from external programs --- src/dui/gui_utils.py | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/dui/gui_utils.py b/src/dui/gui_utils.py index 2d84e58d..e4fc3ce6 100644 --- a/src/dui/gui_utils.py +++ b/src/dui/gui_utils.py @@ -684,6 +684,65 @@ def __init__(self, parent=None): self.setWindowTitle("External Tool") self.my_process = None + + def run_my_proc(self, command, json_path, pickle_path): + """Run a process. + + Args: + command (str): The command to run + json_path (str): + Path to the JSON file to pass in as first argument + pickle_path (Sequence[Optional[str]]): + An additional path to a pickle to pass in as an argument. + Currently, all except the first argument is ignored. + """ + + # assert isinstance(json_path, basestring) + # # This function previously had strings as default parameters + # # but appears to only accept Indexable lists of strings. Make + # # sure we never try to use strings + # assert not isinstance(pickle_path, basestring) + # # Since we ignore everything after [0] assert they are None + # assert all(x is None for x in pickle_path[1:]) + # # Only one process running from each class + # assert self.my_process is None + + # Build the command + cmd_to_run = [find_executable(command), str(json_path)] + logger.debug("Resolving %s as %s", command, cmd_to_run[0]) + + first_pikl_path = pickle_path[0] + if first_pikl_path is not None: + cmd_to_run.append(str(first_pikl_path)) + + # Save the working directory + self.cwd_path = os.path.join(sys_arg.directory, "dui_files") + to_remove = ''' + self.check_for = check_for or [] + # Store metadata about the files if they exist, to check if they changed + self.check_file_status = {} + for check_file in self.check_for: + full_path = os.path.join(self.cwd_path, check_file) + if os.path.exists(full_path): + logger.debug("File %s exists - collecting metadata", full_path) + self.check_file_status[check_file] = os.stat(full_path) + ''' + + logger.debug("\n running Popen>>>\n " + " ".join(cmd_to_run) + "\n<<<") + self.my_process = subprocess.Popen(args=cmd_to_run, cwd=self.cwd_path) + logger.debug("Running PID {}".format(self.my_process.pid)) + + # Track the process status in a separate thread + self.thrd = ViewerThread(self.my_process) + self.thrd.finished.connect(self.child_closed) + self.thrd.start() + + # Show this dialog + self.exec_() + + + + to_remove = ''' self.check_for = [] def run_my_proc(self, command, json_path, pickle_path, check_for=None): @@ -743,29 +802,37 @@ def run_my_proc(self, command, json_path, pickle_path, check_for=None): # Show this dialog self.exec_() + ''' def kill_my_proc(self): """Kill the subprocess early""" logger.debug("self.kill_my_proc") kill_w_child(self.my_process.pid) self.my_process = None + to_remove = ''' self._check_for_output_files() + ''' self.done(0) def child_closed(self): """The child process has closed by itself""" logger.debug("after ...close()") self.my_process = None + to_remove = ''' self._check_for_output_files() + ''' # Just close ourself self.done(0) def closeEvent(self, event): """User has clicked 'close' window decorator on dialog box""" logger.debug("from << closeEvent (QDialog) >>") + to_remove = ''' self._check_for_output_files() + ''' self.kill_my_proc() + to_remove = ''' def _check_for_output_files(self): """Send out any signals about created or changed output files""" found_checks = [] @@ -796,11 +863,14 @@ def _check_for_output_files(self): if found_checks: self.outputFileFound.emit(found_checks) + ''' class OuterCaller(QWidget): + to_remove = ''' pass_parmam_lst = Signal(list) + ''' def __init__(self): super(OuterCaller, self).__init__() @@ -816,7 +886,9 @@ def __init__(self): v_box.addWidget(img_but) self.diag = ExternalProcDialog(parent=self.window()) + to_remove = ''' self.diag.outputFileFound.connect(self.check_for_phil) + ''' self.setLayout(v_box) # self.show() @@ -835,7 +907,8 @@ def run_img_dialg(self): self.diag.run_my_proc( "dials.image_viewer", json_path=self.my_json, - pickle_path=self.my_pick, + pickle_path=self.my_pick) + to_remove = ''' , check_for=["find_spots.phil", "mask.pickle"], ) @@ -856,6 +929,7 @@ def check_for_phil(self, output_files): self.pass_parmam_lst.emit(phil_parms) else: logger.debug("Not sure how to handle %s", filename) + ''' class CliOutView(QTextEdit):