Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
wayyoungboy committed Aug 7, 2024
1 parent 7c1e546 commit a74175a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ def do_command(self):
if self.has_trace:
ROOT_IO.print('Trace ID: %s' % self.trace_id)
ROOT_IO.print('If you want to view detailed obdiag logs, please run: {0} display-trace {1}'.format(obdiag_bin, self.trace_id))
return ret or ObdiagResult(code=ObdiagResult.SERVER_ERROR_CODE, data={"err_info": "The return value of the command is not ObdiagResult. Please contact thebase community."})

ROOT_IO.just_json(ret or ObdiagResult(code=ObdiagResult.SERVER_ERROR_CODE, data={"err_info": "The return value of the command is not ObdiagResult. Please contact thebase community."}))
except NotImplementedError:
ROOT_IO.exception('command \'%s\' is not implemented' % self.prev_cmd)
except SystemExit:
Expand Down
7 changes: 7 additions & 0 deletions stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class MsgLevel(object):
DEBUG = 10
VERBOSE = DEBUG
NOTSET = 0
JUST_JSON = 60


class IO(object):
Expand Down Expand Up @@ -721,6 +722,9 @@ def _print(self, msg_lv, msg, *args, **kwargs):
kwargs['file'] = self.get_cur_out_obj()
if self.print_type != "just_json":
kwargs['file'] and print(self._format(print_msg, *args), **kwargs)
else:
if msg_lv>=MsgLevel.JUST_JSON:
print(json.dumps(msg))
del kwargs['file']
self.log(msg_lv, msg, *args, **kwargs)

Expand Down Expand Up @@ -750,6 +754,9 @@ def _log(self, levelno, msg, *args, **kwargs):
def print(self, msg, *args, **kwargs):
self._print(MsgLevel.INFO, msg, *args, **kwargs)

def just_json(self, msg, *args, **kwargs):
self._print(MsgLevel.JUST_JSON, msg, *args, **kwargs)

def warn(self, msg, *args, **kwargs):
self._print(MsgLevel.WARN, msg, prev_msg=self.WARNING_PREV.format(self.isatty()), *args, **kwargs)

Expand Down

0 comments on commit a74175a

Please sign in to comment.