Skip to content

Commit

Permalink
add start check for obdiag work directory (#454)
Browse files Browse the repository at this point in the history
* check work dir before start

* build rpm to check

* remove no master build

* add version check

* Adjust the code position

* fix start_check
  • Loading branch information
xiaodong-ji authored Sep 30, 2024
1 parent aab2968 commit 7697592
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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):

Expand Down

0 comments on commit 7697592

Please sign in to comment.