comparison sat/tools/utils.py @ 2612:3e4e78de9cca

tools (date_utils): moved date_parse to common.date_utils, because it can be used in frontends
author Goffi <goffi@goffi.org>
date Thu, 21 Jun 2018 01:21:44 +0200
parents cb7bf936d8e8
children 56f94936df1e
comparison
equal deleted inserted replaced
2611:c180ca699e72 2612:3e4e78de9cca
23 import os.path 23 import os.path
24 from sat.core.constants import Const as C 24 from sat.core.constants import Const as C
25 from sat.core.log import getLogger 25 from sat.core.log import getLogger
26 log = getLogger(__name__) 26 log = getLogger(__name__)
27 import datetime 27 import datetime
28 from dateutil import parser as dateutil_parser
29 from twisted.python import procutils 28 from twisted.python import procutils
30 import subprocess 29 import subprocess
31 import calendar
32 import time 30 import time
33 import sys 31 import sys
34 import random 32 import random
35 import inspect 33 import inspect
36 import textwrap 34 import textwrap
88 """ 86 """
89 template_date = u"%Y-%m-%d" 87 template_date = u"%Y-%m-%d"
90 template_time = u"%H:%M:%SZ" 88 template_time = u"%H:%M:%SZ"
91 template = u"{}T{}".format(template_date, template_time) if with_time else template_date 89 template = u"{}T{}".format(template_date, template_time) if with_time else template_date
92 return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template) 90 return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template)
93
94 def date_parse(value):
95 """Parse a date and return corresponding unix timestamp
96
97 @param value(unicode): date to parse, in any format supported by dateutil.parser
98 @return (int): timestamp
99 """
100 return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple())
101 91
102 def generatePassword(vocabulary=None, size=20): 92 def generatePassword(vocabulary=None, size=20):
103 """Generate a password with random characters. 93 """Generate a password with random characters.
104 94
105 @param vocabulary(iterable): characters to use to create password 95 @param vocabulary(iterable): characters to use to create password