From f66aba5653bdaea1263f524f8b9820ee3bdc013d Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Tue, 10 Dec 2024 21:16:01 +0100 Subject: [PATCH 1/5] use correct executable names --- src/qlever/commands/start.py | 10 ++++++---- src/qlever/commands/status.py | 14 ++++++++++---- src/qlever/commands/stop.py | 9 ++++++--- src/qlever/util.py | 7 +++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/qlever/commands/start.py b/src/qlever/commands/start.py index 4b6ae8f6..46a4f82c 100644 --- a/src/qlever/commands/start.py +++ b/src/qlever/commands/start.py @@ -10,7 +10,7 @@ from qlever.commands.warmup import WarmupCommand from qlever.containerize import Containerize from qlever.log import log -from qlever.util import is_qlever_server_alive, run_command +from qlever.util import is_qlever_server_alive, run_command, name_from_path class StartCommand(QleverCommand): @@ -58,19 +58,21 @@ def additional_arguments(self, subparser) -> None: help="Do not execute the warmup command") def execute(self, args) -> bool: + server_binary = name_from_path(args.server_binary) + # Kill existing server with the same name if so desired. # # TODO: This is currently disabled because I never used it once over # the past weeks and it is not clear to me what the use case is. if False: # or args.kill_existing_with_same_name: - args.cmdline_regex = f"^ServerMain.* -i {args.name}" + args.cmdline_regex = f"^{server_binary}.* -i {args.name}" args.no_containers = True StopCommand().execute(args) log.info("") # Kill existing server on the same port if so desired. if args.kill_existing_with_same_port: - args.cmdline_regex = f"^ServerMain.* -p {args.port}" + args.cmdline_regex = f"^{server_binary}.* -p {args.port}" args.no_containers = True if not StopCommand().execute(args): log.error("Stopping the existing server failed") @@ -141,7 +143,7 @@ def execute(self, args) -> bool: "--kill-existing-with-same-port`") # Show output of status command. - args.cmdline_regex = f"^ServerMain.* -p *{port}" + args.cmdline_regex = f"^{server_binary}.* -p *{port}" log.info("") StatusCommand().execute(args) diff --git a/src/qlever/commands/status.py b/src/qlever/commands/status.py index a8efed54..7bce1f5e 100644 --- a/src/qlever/commands/status.py +++ b/src/qlever/commands/status.py @@ -3,7 +3,7 @@ import psutil from qlever.command import QleverCommand -from qlever.util import show_process_info +from qlever.util import show_process_info, name_from_path class StatusCommand(QleverCommand): @@ -21,7 +21,7 @@ def should_have_qleverfile(self) -> bool: return False def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: - return {} + return {"server": ["server_binary"], "index": ["index_binary"]} def additional_arguments(self, subparser) -> None: subparser.add_argument("--cmdline-regex", @@ -30,9 +30,15 @@ def additional_arguments(self, subparser) -> None: "line matches this regex") def execute(self, args) -> bool: + server_binary = name_from_path(args.server_binary) + index_binary = name_from_path(args.index_binary) + cmdline_regex = (args.cmdline_regex + .replace("ServerMain", server_binary) + .replace("IndexBuilderMain", index_binary)) + # Show action description. self.show(f"Show all processes on this machine where " - f"the command line matches {args.cmdline_regex}" + f"the command line matches {cmdline_regex}" f" using Python's psutil library", only_show=args.show) if args.show: return True @@ -41,7 +47,7 @@ def execute(self, args) -> bool: num_processes_found = 0 for proc in psutil.process_iter(): show_heading = num_processes_found == 0 - process_shown = show_process_info(proc, args.cmdline_regex, + process_shown = show_process_info(proc, cmdline_regex, show_heading=show_heading) if process_shown: num_processes_found += 1 diff --git a/src/qlever/commands/stop.py b/src/qlever/commands/stop.py index 82225304..273534f4 100644 --- a/src/qlever/commands/stop.py +++ b/src/qlever/commands/stop.py @@ -8,7 +8,7 @@ from qlever.commands.status import StatusCommand from qlever.containerize import Containerize from qlever.log import log -from qlever.util import show_process_info +from qlever.util import show_process_info, name_from_path class StopCommand(QleverCommand): @@ -27,7 +27,7 @@ def should_have_qleverfile(self) -> bool: def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: return {"data": ["name"], - "server": ["port"], + "server": ["server_binary", "port"], "runtime": ["server_container"]} def additional_arguments(self, subparser) -> None: @@ -41,8 +41,11 @@ def additional_arguments(self, subparser) -> None: "native processes") def execute(self, args) -> bool: + server_binary = name_from_path(args.server_binary) + # Show action description. cmdline_regex = args.cmdline_regex.replace("%%NAME%%", args.name) + cmdline_regex = cmdline_regex.replace("ServerMain", server_binary) description = f"Checking for processes matching \"{cmdline_regex}\"" if not args.no_containers: description += (f" and for Docker container with name " @@ -95,7 +98,7 @@ def execute(self, args) -> bool: message = "No matching process found" if args.no_containers else \ "No matching process or container found" log.error(message) - args.cmdline_regex = "^ServerMain.* -i [^ ]*" + args.cmdline_regex = f"^{server_binary}.* -i [^ ]*" log.info("") StatusCommand().execute(args) return True diff --git a/src/qlever/util.py b/src/qlever/util.py index d79a9413..74040c31 100644 --- a/src/qlever/util.py +++ b/src/qlever/util.py @@ -225,3 +225,10 @@ def format_size(bytes, suffix="B"): if bytes < factor: return f"{bytes:.2f} {unit}{suffix}" bytes /= factor + +def name_from_path(path: str) -> str: + """ + Helper function that returns the name of the file from its path. + E.g. /qlever/ServerMain -> ServerMain + """ + return Path(path).name \ No newline at end of file From b2af49a08d521d2e76eb5dc744174492cf082821 Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Tue, 10 Dec 2024 21:41:43 +0100 Subject: [PATCH 2/5] Add missing qleverfile arguments to commands The additional arguments are required because now requires both the server and index binary. --- src/qlever/commands/start.py | 1 + src/qlever/commands/stop.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qlever/commands/start.py b/src/qlever/commands/start.py index 46a4f82c..4059bec3 100644 --- a/src/qlever/commands/start.py +++ b/src/qlever/commands/start.py @@ -37,6 +37,7 @@ def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: "timeout", "only_pso_and_pos_permutations", "use_patterns", "use_text_index", "warmup_cmd"], + "index": ["index_binary"], "runtime": ["system", "image", "server_container"]} def additional_arguments(self, subparser) -> None: diff --git a/src/qlever/commands/stop.py b/src/qlever/commands/stop.py index 273534f4..dedd06a7 100644 --- a/src/qlever/commands/stop.py +++ b/src/qlever/commands/stop.py @@ -28,7 +28,8 @@ def should_have_qleverfile(self) -> bool: def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: return {"data": ["name"], "server": ["server_binary", "port"], - "runtime": ["server_container"]} + "runtime": ["server_container"], + "index": ["index_binary"]} def additional_arguments(self, subparser) -> None: subparser.add_argument("--cmdline-regex", From 6748235437ac624b03fe5f5dcc0e5805b702ddc6 Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Tue, 10 Dec 2024 21:44:24 +0100 Subject: [PATCH 3/5] Add missing final linebreak --- src/qlever/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qlever/util.py b/src/qlever/util.py index 74040c31..c92ab4b1 100644 --- a/src/qlever/util.py +++ b/src/qlever/util.py @@ -231,4 +231,5 @@ def name_from_path(path: str) -> str: Helper function that returns the name of the file from its path. E.g. /qlever/ServerMain -> ServerMain """ - return Path(path).name \ No newline at end of file + return Path(path).name + From cb8e599c0e18d7c9f1a559a14c81d74ed6001955 Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Tue, 17 Dec 2024 15:03:10 +0100 Subject: [PATCH 4/5] stripping the path doesn't go well with some regexes --- src/qlever/commands/start.py | 10 ++++------ src/qlever/commands/status.py | 19 ++++++++++++------- src/qlever/commands/stop.py | 10 ++++------ src/qlever/util.py | 8 -------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/qlever/commands/start.py b/src/qlever/commands/start.py index 4059bec3..c1613347 100644 --- a/src/qlever/commands/start.py +++ b/src/qlever/commands/start.py @@ -10,7 +10,7 @@ from qlever.commands.warmup import WarmupCommand from qlever.containerize import Containerize from qlever.log import log -from qlever.util import is_qlever_server_alive, run_command, name_from_path +from qlever.util import is_qlever_server_alive, run_command class StartCommand(QleverCommand): @@ -59,21 +59,19 @@ def additional_arguments(self, subparser) -> None: help="Do not execute the warmup command") def execute(self, args) -> bool: - server_binary = name_from_path(args.server_binary) - # Kill existing server with the same name if so desired. # # TODO: This is currently disabled because I never used it once over # the past weeks and it is not clear to me what the use case is. if False: # or args.kill_existing_with_same_name: - args.cmdline_regex = f"^{server_binary}.* -i {args.name}" + args.cmdline_regex = f"^{args.server_binary}.* -i {args.name}" args.no_containers = True StopCommand().execute(args) log.info("") # Kill existing server on the same port if so desired. if args.kill_existing_with_same_port: - args.cmdline_regex = f"^{server_binary}.* -p {args.port}" + args.cmdline_regex = f"^{args.server_binary}.* -p {args.port}" args.no_containers = True if not StopCommand().execute(args): log.error("Stopping the existing server failed") @@ -144,7 +142,7 @@ def execute(self, args) -> bool: "--kill-existing-with-same-port`") # Show output of status command. - args.cmdline_regex = f"^{server_binary}.* -p *{port}" + args.cmdline_regex = f"^{args.server_binary}.* -p *{port}" log.info("") StatusCommand().execute(args) diff --git a/src/qlever/commands/status.py b/src/qlever/commands/status.py index 7bce1f5e..cd0475a3 100644 --- a/src/qlever/commands/status.py +++ b/src/qlever/commands/status.py @@ -3,7 +3,7 @@ import psutil from qlever.command import QleverCommand -from qlever.util import show_process_info, name_from_path +from qlever.util import show_process_info class StatusCommand(QleverCommand): @@ -25,16 +25,21 @@ def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: def additional_arguments(self, subparser) -> None: subparser.add_argument("--cmdline-regex", - default="^(ServerMain|IndexBuilderMain)", + default="^(%%SERVER_BINARY%%|%%INDEX_BINARY%%)", help="Show only processes where the command " "line matches this regex") def execute(self, args) -> bool: - server_binary = name_from_path(args.server_binary) - index_binary = name_from_path(args.index_binary) - cmdline_regex = (args.cmdline_regex - .replace("ServerMain", server_binary) - .replace("IndexBuilderMain", index_binary)) + cmdline_regex = args.cmdline_regex + # Other commands call status with a custom `cmdline_regex` that contains + # less or no variables. Doing the replacement on-demand has the benefit + # that only the variables that are actually used have to be provided by + # the calling command. For example: the `cmdline_regex` used by start + # has no variables and requiring the index binary for it would be strange. + if "%%SERVER_BINARY%%" in cmdline_regex: + cmdline_regex = cmdline_regex.replace("%%SERVER_BINARY%%", args.server_binary) + if "%%INDEX_BINARY%%" in cmdline_regex: + cmdline_regex = cmdline_regex.replace("%%INDEX_BINARY%%", args.index_binary) # Show action description. self.show(f"Show all processes on this machine where " diff --git a/src/qlever/commands/stop.py b/src/qlever/commands/stop.py index dedd06a7..f5e5abfa 100644 --- a/src/qlever/commands/stop.py +++ b/src/qlever/commands/stop.py @@ -8,7 +8,7 @@ from qlever.commands.status import StatusCommand from qlever.containerize import Containerize from qlever.log import log -from qlever.util import show_process_info, name_from_path +from qlever.util import show_process_info class StopCommand(QleverCommand): @@ -33,7 +33,7 @@ def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: def additional_arguments(self, subparser) -> None: subparser.add_argument("--cmdline-regex", - default="ServerMain.* -i [^ ]*%%NAME%%", + default="%%SERVER_BINARY%%.* -i [^ ]*%%NAME%%", help="Show only processes where the command " "line matches this regex") subparser.add_argument("--no-containers", action="store_true", @@ -42,11 +42,9 @@ def additional_arguments(self, subparser) -> None: "native processes") def execute(self, args) -> bool: - server_binary = name_from_path(args.server_binary) - # Show action description. cmdline_regex = args.cmdline_regex.replace("%%NAME%%", args.name) - cmdline_regex = cmdline_regex.replace("ServerMain", server_binary) + cmdline_regex = cmdline_regex.replace("%%SERVER_BINARY%%", args.server_binary) description = f"Checking for processes matching \"{cmdline_regex}\"" if not args.no_containers: description += (f" and for Docker container with name " @@ -99,7 +97,7 @@ def execute(self, args) -> bool: message = "No matching process found" if args.no_containers else \ "No matching process or container found" log.error(message) - args.cmdline_regex = f"^{server_binary}.* -i [^ ]*" + args.cmdline_regex = f"^{args.server_binary}.* -i [^ ]*" log.info("") StatusCommand().execute(args) return True diff --git a/src/qlever/util.py b/src/qlever/util.py index c92ab4b1..d79a9413 100644 --- a/src/qlever/util.py +++ b/src/qlever/util.py @@ -225,11 +225,3 @@ def format_size(bytes, suffix="B"): if bytes < factor: return f"{bytes:.2f} {unit}{suffix}" bytes /= factor - -def name_from_path(path: str) -> str: - """ - Helper function that returns the name of the file from its path. - E.g. /qlever/ServerMain -> ServerMain - """ - return Path(path).name - From 9d3fed74124640f38720ac0bf36009b6cff0ad98 Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Tue, 17 Dec 2024 15:05:12 +0100 Subject: [PATCH 5/5] remove unused command arguments that snuck through rebase --- src/qlever/commands/start.py | 1 - src/qlever/commands/stop.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/qlever/commands/start.py b/src/qlever/commands/start.py index c1613347..57c58900 100644 --- a/src/qlever/commands/start.py +++ b/src/qlever/commands/start.py @@ -37,7 +37,6 @@ def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: "timeout", "only_pso_and_pos_permutations", "use_patterns", "use_text_index", "warmup_cmd"], - "index": ["index_binary"], "runtime": ["system", "image", "server_container"]} def additional_arguments(self, subparser) -> None: diff --git a/src/qlever/commands/stop.py b/src/qlever/commands/stop.py index f5e5abfa..811321d8 100644 --- a/src/qlever/commands/stop.py +++ b/src/qlever/commands/stop.py @@ -28,8 +28,7 @@ def should_have_qleverfile(self) -> bool: def relevant_qleverfile_arguments(self) -> dict[str: list[str]]: return {"data": ["name"], "server": ["server_binary", "port"], - "runtime": ["server_container"], - "index": ["index_binary"]} + "runtime": ["server_container"]} def additional_arguments(self, subparser) -> None: subparser.add_argument("--cmdline-regex",