diff --git a/anisotropy/core/cli.py b/anisotropy/core/cli.py index 1faa2ed..7db3ff2 100644 --- a/anisotropy/core/cli.py +++ b/anisotropy/core/cli.py @@ -147,6 +147,12 @@ def compute(stage, nprocs, force, update, params, path): for param in params: args.update(param) + ### + logger.info("Writing pid ...") + + with open(os.path.join(path, "anisotropy.pid"), "w") as io: + io.write(str(os.getpid())) + ### model = Anisotropy() model.db = Database(env["db_name"], env["db_path"]) @@ -247,6 +253,33 @@ def compute(stage, nprocs, force, update, params, path): parallel(nprocs, queueargs, computeCase) +@anisotropy.command( + help = "Kill process by pid file" +) +@click.option( + "-P", "--path", "path", + default = os.getcwd(), + help = "Specify directory to use (instead of cwd)" +) +@click.argument("pidfile") +def kill(path, pidfile): + from anisotropy.salomepl.utils import SalomeManager + + try: + with open(os.path.join(path, pidfile), "r") as io: + pid = io.read() + + os.kill(int(pid), 9) + + except FileNotFoundError: + click.echo(f"Unknown file { pidfile }") + + except ProcessLookupError: + click.echo(f"Cannot find process with pid { pid }") + + # TODO: killall method kills all salome instances. Not a good way + SalomeManager().killall() + @anisotropy.command( help = "! Not a user command" ) diff --git a/anisotropy/core/main.py b/anisotropy/core/main.py index f4a7c09..20a11d8 100644 --- a/anisotropy/core/main.py +++ b/anisotropy/core/main.py @@ -257,7 +257,7 @@ class Anisotropy(object): *salomeargs, timeout = self.env["salome_timeout"], root = self.env["ROOT"], - logpath = os.path.join(casepath, "logs") + logpath = casepath ) diff --git a/anisotropy/salomepl/utils.py b/anisotropy/salomepl/utils.py index 321b36f..27d03d9 100644 --- a/anisotropy/salomepl/utils.py +++ b/anisotropy/salomepl/utils.py @@ -59,6 +59,10 @@ class SalomeManager(object): return self.runner(["salome", "kill", str(self.__port or port)]) + def killall(self): + return self.runner(["salome", "killall"]) + + def execute(self, scriptpath: str, *args, root: str = None, logpath: str = None, timeout: int = None, **kwargs): if not root: @@ -97,6 +101,8 @@ class SalomeManager(object): returncode = lastproc.returncode if logpath: + os.makedirs(logpath, exist_ok = True) + with open(os.path.join(logpath, "salome.log"), "wb") as io: io.write(out) io.write(err) diff --git a/setup.py b/setup.py index 1ffd437..42e2a19 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,10 @@ def main(): ], data_files = [ - ("share/doc/anisotropy", findall("docs")) + ("share/doc/anisotropy", findall("docs")), + ("share/doc/anisotropy/source", findall("docs/source")), + ("share/doc/anisotropy/source/static", findall("docs/source/static")), + ("share/doc/anisotropy/source/notes", findall("docs/source/notes")) ], package_data = {