# Python imports import os import subprocess # Lib imports # Apoplication imports class CoherenceLauncherException(Exception): ... class Launcher: def open_file_locally(self, file): command = ["xdg-open", file] self.execute(command) def execute(self, command, start_dir=os.getenv("HOME"), use_shell=False): try: logger.debug(command) subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True) except CoherenceLauncherException as e: logger.error(f"Couldn't execute: {command}") logger.error(e) # TODO: Return std(out/in/err) handlers along with subprocess instead of sinking to null def execute_and_return_thread_handler(self, command, start_dir=os.getenv("HOME"), use_shell=False): try: DEVNULL = open(os.devnull, 'w') return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=False, stdout=DEVNULL, stderr=DEVNULL, close_fds=False) except CoherenceLauncherException as e: logger.error(f"Couldn't execute and return thread: {command}") logger.error(e) return None @threaded def app_chooser_exec(self, app_info, uris): app_info.launch_uris_async(uris)