Skip to content
Snippets Groups Projects
Commit 34e1cf38 authored by Matthieu Gonnet's avatar Matthieu Gonnet Committed by Seblu
Browse files

Clean exit in time command

The time command now catch the ccli exception and KeyboardInterrupt and
print the execution time before a clean exit.
parent 32e44ba6
No related branches found
No related tags found
No related merge requests found
......@@ -21,14 +21,21 @@ class Command_time(Command):
Command.__init__(self, cli, argv0)
def __call__(self, argv):
if len(argv) > 1:
# Substitute aliases
self.args = self.cli.aliases.substitute(argv[1:])
# Init time
t0 = systime.time()
if len(argv) < 2:
raise cmdBadArgument()
# Substitute aliases
self.args = self.cli.aliases.substitute(argv[1:])
# Init time
t0 = systime.time()
try:
# Execute command
self.cli.commands(self.args)
except KeyboardInterrupt:
raise
except cliException:
raise
finally:
t1 = systime.time()
# Get elapsed time
# Compute elapsed time
dt = int(t1 - t0)
print "Execution time: %s" % datetime.timedelta(seconds=dt)
self.printer.out("Execution time: %s" % datetime.timedelta(seconds=dt))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment