--- a/candolint/utils.py Sun Jul 17 05:10:35 2016 +0800
+++ b/candolint/utils.py Sun Jul 17 05:23:08 2016 +0800
from __future__ import absolute_import
+from datetime import datetime
from os.path import abspath, dirname, join
return abspath(join(dirname(dirname(__file__)), *parts))
+ return datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')
+def parse_timestamp(value):
+ return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00')
--- a/checker.py Sun Jul 17 05:10:35 2016 +0800
+++ b/checker.py Sun Jul 17 05:23:08 2016 +0800
from argparse import ArgumentParser, FileType
-from datetime import datetime
from fnmatch import fnmatchcase
from shutil import rmtree
from subprocess import check_call, check_output, CalledProcessError
-from candolint.utils import rel
+from candolint.utils import rel, timestamp
def run_ignore_codes(fn, args, codes):
- return datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00')
def read_linter_config(name, path=rel('linters')):
fd = open(os.path.join(path, '{}.yml'.format(name)))
- print('# C&O job started: {}'.format(now()))
+ print('# C&O job started: {}'.format(timestamp()))
tmp = mkdtemp(prefix='candolint.')
if not execute(tmp, config):
print('# C&O task: cleanup')
- print('# C&O job finished: {}'.format(now()))
+ print('# C&O job finished: {}'.format(timestamp()))
print('# C&O job failed (exception not caught)')
- print('# C&O job finished: {}'.format(now()))
+ print('# C&O job finished: {}'.format(timestamp()))
--- a/incoming.py Sun Jul 17 05:10:35 2016 +0800
+++ b/incoming.py Sun Jul 17 05:23:08 2016 +0800
from argparse import ArgumentParser, FileType
-from datetime import datetime
from urlparse import urlparse
from tornado.escape import json_encode
from candolint.models import database, Project, Change, Check
-from candolint.utils import rel
-def parse_timestamp(value):
- return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S+00:00')
+from candolint.utils import parse_timestamp, rel
def parse_project_url(url):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_utils.py Sun Jul 17 05:23:08 2016 +0800
+from datetime import datetime
+from candolint.utils import parse_timestamp, timestamp
+def test_timestamp_and_parse():
+ result = parse_timestamp(timestamp())
+ assert isinstance(result, datetime)
+ assert result.utcoffset() is None