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
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -21,14 +21,21 @@ class Command_time(Command):
        Command.__init__(self, cli, argv0)

    def __call__(self, argv):
        if len(argv) > 1:
        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))