From 76975926a3b85014b226be1134ddc548a5c5a043 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Mon, 30 Sep 2024 14:03:49 +0800 Subject: [PATCH] add start check for obdiag work directory (#454) * check work dir before start * build rpm to check * remove no master build * add version check * Adjust the code position * fix start_check --- diag_cmd.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/diag_cmd.py b/diag_cmd.py index d1eeb4a..2d9bec5 100644 --- a/diag_cmd.py +++ b/diag_cmd.py @@ -16,7 +16,7 @@ """ from __future__ import absolute_import, division, print_function -from common.tool import Util +from common.tool import Util, StringUtils import os import sys @@ -30,6 +30,7 @@ from stdio import IO from common.version import get_obdiag_version from telemetry.telemetry import telemetry +from common.version import OBDIAG_VERSION # TODO when obdiag_version ≥ 3.0, the default value of err_stream will be changed to sys.stderr ROOT_IO = IO(1, error_stream=sys.stdout) @@ -383,6 +384,7 @@ def _mk_usage(self): return super(MajorCommand, self)._mk_usage() def do_command(self): + self.start_check() if not self.is_init: ROOT_IO.error('%s command not init' % self.prev_cmd) raise SystemExit('command not init') @@ -408,6 +410,17 @@ def do_command(self): def register_command(self, command): self.commands[command.name] = command + def start_check(self): + current_work_path = os.getcwd() + home_path = os.path.expanduser("~") + if '.' in OBDIAG_VERSION: + if current_work_path.startswith(home_path + "/.obdiag"): + if StringUtils.compare_versions_lower(OBDIAG_VERSION, "3.0.0"): + ROOT_IO.warn("Currently executing in obdiag home directory!") + else: + ROOT_IO.error("Cannot be executed in the obdiag working directory!") + ROOT_IO.exit(1) + class ObdiagGatherAllCommand(ObdiagOriginCommand):