From 8f804cf9fa88d913dcb6286cc5f736eff91834d0 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 29 Jun 2015 16:55:56 -0400 Subject: [PATCH] python 2.6 compatible total_seconds --- awx/main/management/commands/workload_generator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/awx/main/management/commands/workload_generator.py b/awx/main/management/commands/workload_generator.py index c2b4b56714..addac4ffb7 100644 --- a/awx/main/management/commands/workload_generator.py +++ b/awx/main/management/commands/workload_generator.py @@ -102,6 +102,12 @@ EXPERIMENT_DEFAULT = { ] } +# damn you python 2.6 +def timedelta_total_seconds(timedelta): + return ( + timedelta.microseconds + 0.0 + + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6 + class Experiment(object): def __init__(self, exp, fact_fixtures, raw_db, mongoengine_db): self.db = raw_db @@ -115,7 +121,7 @@ class Experiment(object): self.fact_fixtures = fact_fixtures self.host_count = exp['hosts'] self.scans_total = int(exp['scan']['duration'] / exp['scan']['period']) # round down - self.scan_end = int((datetime.datetime(2015,1,1) - datetime.datetime(1970,1,1)).total_seconds() / 60) + self.scan_end = int(timedelta_total_seconds((datetime.datetime(2015,1,1) - datetime.datetime(1970,1,1))) / 60) self.scan_start = self.scan_end - exp['scan']['duration'] self.scan_period = exp['scan']['period'] self.modules = exp['modules'] @@ -192,7 +198,7 @@ class Experiment(object): time_end = now() print("") print("Finished at: %s" % time_end) - print("Total runtime: %s seconds" % (time_end - time_start).total_seconds()) + print("Total runtime: %s seconds" % timedelta_total_seconds(time_end - time_start)) class Command(BaseCommand): option_list = BaseCommand.option_list + (