From d2afc0fdd2655ea1581d8a66a5b05b678352202d Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Fri, 11 Oct 2024 20:23:26 +0200 Subject: [PATCH] fixed errors --- core/screen.py | 4 ++-- core/stack.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/screen.py b/core/screen.py index 1dc2eb3..ec15919 100644 --- a/core/screen.py +++ b/core/screen.py @@ -36,7 +36,7 @@ class Screen: os.system(f'screen -S {self.pid} -X stuff {command}{end}') -def create(name, shell=os.environ['SHELL'], logfile=None, title=None) -> Screen: +def create(name, shell=os.environ['SHELL'], logfile=None, title=None, kill_on_exit=False) -> Screen: command = ["screen", "-DmS", name, '-s', shell] if logfile: command.append('-Logfile') @@ -46,7 +46,7 @@ def create(name, shell=os.environ['SHELL'], logfile=None, title=None) -> Screen: command.append(title) process = subprocess.Popen(command) while not process.pid: pass - return Screen(process.pid) + return Screen(process.pid, kill_on_exit) def kill(pid): diff --git a/core/stack.py b/core/stack.py index 55d7e5b..f281771 100644 --- a/core/stack.py +++ b/core/stack.py @@ -96,7 +96,7 @@ class Stack: logger.info(f"Updating {self.name}") symlinks = utils.find_symlink_in_folder(self.path) - self.git_pull(folder) + self.git_pull(self.path / folder) self._update() utils.create_symlinks(symlinks) @@ -142,7 +142,10 @@ class Stack: proc.wait(timeout=5) except (psutil.NoSuchProcess, psutil.TimeoutExpired): logger.warning(f"{self.name} did not terminate gracefully, forcing kill") - psutil.Process(self.pid).kill() + try: + psutil.Process(self.pid).kill() + except psutil.NoSuchProcess: + pass self.remove_pid_file() else: logger.warning(f"{self.name} is not running") @@ -229,7 +232,7 @@ class Stack: # process = subprocess.Popen(full_cmd, shell=True, preexec_fn=os.setpgrp, # stdout=config.open_file(f"{self.id}-stdout"), # stderr=config.open_file(f"{self.id}-stderr")) - self.screen_session = screen.create(name=self.id) + self.screen_session = screen.create(name=self.id, kill_on_exit=True) self.screen_session.send(f"'{full_cmd} && screen -wipe'") self.write_pid(self.screen_session.pid) return @@ -250,9 +253,9 @@ class Stack: logger.info(f"Cloning {url}") self.bash(f"git clone {f'-b {branch}' if branch else ''} {url} {dest or ''}") - def git_pull(self, repo_folder: str, force: bool = False) -> None: + def git_pull(self, repo_folder: Path, force: bool = False) -> None: """Pull changes from a git repository.""" - self.bash(f"git reset --hard HEAD {'&& git clean -f -d' if force else ''} && git pull", Path(repo_folder)) + self.bash(f"git reset --hard HEAD {'&& git clean -f -d' if force else ''} && git pull", repo_folder) def install_from_prebuilt(self, name): for prebuilt in utils.get_prebuilts():