Skip to content

Commit 82f67fa

Browse files
author
Vladimir Kotal
authored
use __str__ of the Command class for logging consistently (#2999)
fixes #2991 Also fix transposition bug in commandsequence#run() logging
1 parent e19feb2 commit 82f67fa

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

opengrok-tools/src/main/python/opengrok_tools/utils/command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def close(self):
240240
self.logger.debug("working directory = {}".format(os.getcwd()))
241241
except PermissionError:
242242
pass
243-
self.logger.debug("command = {}".format(self.cmd))
243+
self.logger.debug("command = '{}'".format(self))
244244
my_args = {'stderr': stderr_dest,
245245
'stdout': output_thread}
246246
if self.env_vars:
@@ -286,7 +286,7 @@ def close(self):
286286
else:
287287
self.state = Command.FINISHED
288288
self.returncode = int(p.returncode)
289-
self.logger.debug("{} -> {}".format(self.cmd, self.getretcode()))
289+
self.logger.debug("'{}' -> {}".format(self, self.getretcode()))
290290
finally:
291291
if self.timeout != 0 and timeout_thread:
292292
with time_condition:
@@ -307,8 +307,8 @@ def close(self):
307307
self.err = stderr_thread.getoutput()
308308

309309
elapsed_time = time.time() - start_time
310-
self.logger.debug("Command {} took {} seconds".
311-
format(self.cmd, int(elapsed_time)))
310+
self.logger.debug("Command '{}' took {} seconds".
311+
format(self, int(elapsed_time)))
312312

313313
if orig_work_dir:
314314
try:

opengrok-tools/src/main/python/opengrok_tools/utils/commandsequence.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,10 @@ def __init__(self, base):
8383
self.logger = logging.getLogger(__name__)
8484
self.logger.setLevel(base.loglevel)
8585

86-
def run_command(self, command):
86+
def run_command(self, cmd):
8787
"""
8888
Execute a command and return its return code.
8989
"""
90-
command_args = command.get(COMMAND_PROPERTY)
91-
cmd = Command(command_args,
92-
env_vars=command.get("env"),
93-
resource_limits=command.get("limits"),
94-
args_subst={PROJECT_SUBST: self.name},
95-
args_append=[self.name], excl_subst=True)
9690
cmd.execute()
9791
self.retcodes[str(cmd)] = cmd.getretcode()
9892
self.outputs[str(cmd)] = cmd.getoutput()
@@ -119,6 +113,12 @@ def run(self):
119113
if is_web_uri(command.get(COMMAND_PROPERTY)[0]):
120114
call_rest_api(command, PROJECT_SUBST, self.name)
121115
else:
116+
command_args = command.get(COMMAND_PROPERTY)
117+
command = Command(command_args,
118+
env_vars=command.get("env"),
119+
resource_limits=command.get("limits"),
120+
args_subst={PROJECT_SUBST: self.name},
121+
args_append=[self.name], excl_subst=True)
122122
retcode = self.run_command(command)
123123

124124
# If a command exits with non-zero return code,
@@ -128,14 +128,14 @@ def run(self):
128128
if not self.driveon:
129129
self.logger.debug("command '{}' for project {} "
130130
"requested break".
131-
format(self.name, command))
131+
format(command, self.name))
132132
self.run_cleanup()
133133
else:
134134
self.logger.debug("command '{}' for project {} "
135135
"requested break however "
136136
"the 'driveon' option is set "
137137
"so driving on.".
138-
format(self.name, command))
138+
format(command, self.name))
139139
continue
140140
else:
141141
self.logger.error("command '{}' for project {} failed "
@@ -182,7 +182,7 @@ def check(self, ignore_errors):
182182
self.logger.debug("Output for project '{}':".format(self.name))
183183
for cmd in self.outputs.keys():
184184
if self.outputs[cmd] and len(self.outputs[cmd]) > 0:
185-
self.logger.debug("{}: {}".
185+
self.logger.debug("'{}': {}".
186186
format(cmd, self.outputs[cmd]))
187187

188188
if self.name in ignore_errors:

0 commit comments

Comments
 (0)