Skip to content

Commit

Permalink
commenting (ready to remove) the handling of output from external pro…
Browse files Browse the repository at this point in the history
…grams
  • Loading branch information
luisodls committed Dec 6, 2019
1 parent dd7e632 commit 1f4f1c3
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/dui/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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__()
Expand All @@ -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()

Expand All @@ -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"],
)
Expand All @@ -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):
Expand Down

0 comments on commit 1f4f1c3

Please sign in to comment.