summaryrefslogtreecommitdiffstats
path: root/dashboard/backend/dovetail/utils/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard/backend/dovetail/utils/util.py')
-rwxr-xr-xdashboard/backend/dovetail/utils/util.py71
1 files changed, 0 insertions, 71 deletions
diff --git a/dashboard/backend/dovetail/utils/util.py b/dashboard/backend/dovetail/utils/util.py
deleted file mode 100755
index bfd257d7..00000000
--- a/dashboard/backend/dovetail/utils/util.py
+++ /dev/null
@@ -1,71 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-import datetime
-import re
-import sys
-
-
-def format_datetime(date_time):
- """Generate string from datetime object."""
- return date_time.strftime("%Y-%m-%d %H:%M:%S")
-
-
-def parse_time_interval(time_interval_str):
- """parse string of time interval to time interval.
-
- supported time interval unit: ['d', 'w', 'h', 'm', 's']
- Examples:
- time_interval_str: '3d 2h' time interval to 3 days and 2 hours.
- """
- if not time_interval_str:
- return 0
-
- time_interval_tuple = [
- time_interval_element
- for time_interval_element in time_interval_str.split(' ')
- if time_interval_element
- ]
- time_interval_dict = {}
- time_interval_unit_mapping = {
- 'd': 'days',
- 'w': 'weeks',
- 'h': 'hours',
- 'm': 'minutes',
- 's': 'seconds'
- }
- for time_interval_element in time_interval_tuple:
- mat = re.match(r'^([+-]?\d+)(w|d|h|m|s).*', time_interval_element)
- if not mat:
- continue
-
- time_interval_value = int(mat.group(1))
- time_interval_unit = time_interval_unit_mapping[mat.group(2)]
- time_interval_dict[time_interval_unit] = (
- time_interval_dict.get(time_interval_unit, 0) + time_interval_value
- )
-
- time_interval = datetime.timedelta(**time_interval_dict)
- if sys.version_info[0:2] > (2, 6):
- return time_interval.total_seconds()
- else:
- return (
- time_interval.microseconds + (
- time_interval.seconds + time_interval.days * 24 * 3600
- ) * 1e6
- ) / 1e6
-
-
-def pretty_print(*contents):
- """pretty print contents."""
- if len(contents) == 0:
- print ""
- else:
- print "\n".join(content for content in contents)