# HG changeset patch # User osimons # Date 1248473910 0 # Node ID 87de4513bfddc696b254d4cb96685881ba253fe6 # Parent d8eb5f72337190a27f381e87d523649ac856731e 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85. diff --git a/bitten/queue.py b/bitten/queue.py --- a/bitten/queue.py +++ b/bitten/queue.py @@ -19,12 +19,13 @@ platforms. """ -from datetime import datetime from itertools import ifilter import logging import re import time +from trac.util.datefmt import to_timestamp + from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep __docformat__ = 'restructuredtext en' @@ -234,10 +235,7 @@ 'revision [%s] on %s', config.name, rev, platform.name) - rev_time = repos.get_changeset(rev).date - if isinstance(rev_time, datetime): # Trac>=0.11 - from trac.util.datefmt import to_timestamp - rev_time = to_timestamp(rev_time) + rev_time = to_timestamp(repos.get_changeset(rev).date) age = int(time.time()) - rev_time if self.stabilize_wait and age < self.stabilize_wait: self.log.info('Delaying build of revision %s until %s ' diff --git a/bitten/tests/master.py b/bitten/tests/master.py --- a/bitten/tests/master.py +++ b/bitten/tests/master.py @@ -18,6 +18,7 @@ from trac.db import DatabaseManager from trac.perm import PermissionCache, PermissionSystem from trac.test import EnvironmentStub, Mock +from trac.util.datefmt import to_datetime, utc from trac.web.api import HTTPBadRequest, HTTPMethodNotAllowed, HTTPNotFound, \ HTTPForbidden, RequestDone from trac.web.href import Href @@ -67,7 +68,7 @@ ('somepath', 121, 'edit'), ('somepath', 120, 'edit')] ), - get_changeset=lambda rev: Mock(date=42), + get_changeset=lambda rev: Mock(date=to_datetime(42, utc)), normalize_path=lambda path: path, rev_older_than=lambda rev1, rev2: rev1 < rev2 ) diff --git a/bitten/tests/queue.py b/bitten/tests/queue.py --- a/bitten/tests/queue.py +++ b/bitten/tests/queue.py @@ -16,6 +16,7 @@ from trac.db import DatabaseManager from trac.test import EnvironmentStub, Mock +from trac.util.datefmt import to_datetime, utc from bitten.model import BuildConfig, TargetPlatform, Build, schema from bitten.queue import BuildQueue, collect_changes @@ -192,7 +193,7 @@ def test_populate_not_build_all(self): self.env.get_repository = lambda authname=None: Mock( - get_changeset=lambda rev: Mock(date=rev * 1000), + get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)), get_node=lambda path, rev=None: Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), @@ -223,7 +224,7 @@ def test_populate_build_all(self): self.env.get_repository = lambda authname=None: Mock( - get_changeset=lambda rev: Mock(date=rev * 1000), + get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)), get_node=lambda path, rev=None: Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), diff --git a/bitten/web_ui.py b/bitten/web_ui.py --- a/bitten/web_ui.py +++ b/bitten/web_ui.py @@ -10,7 +10,6 @@ """Implementation of the Bitten web interface.""" -from datetime import datetime import posixpath import re from StringIO import StringIO @@ -21,6 +20,7 @@ from trac.timeline import ITimelineEventProvider from trac.util import escape, pretty_timedelta, format_datetime, shorten_line, \ Markup +from trac.util.datefmt import to_timestamp, to_datetime, utc from trac.util.html import html from trac.web import IRequestHandler, IRequestFilter, HTTPNotFound from trac.web.chrome import INavigationContributor, ITemplateProvider, \ @@ -292,8 +292,8 @@ build_data['steps'].append({ 'name': step.name, 'description': step.description, - 'duration': datetime.fromtimestamp(step.stopped) - \ - datetime.fromtimestamp(step.started), + 'duration': to_datetime(step.stopped, utc) - \ + to_datetime(step.started, utc), 'failed': not step.successful, 'errors': step.errors, 'href': build_data['href'] + '#step_' + step.name @@ -409,8 +409,8 @@ build_data['steps'].append({ 'name': step.name, 'description': step.description, - 'duration': datetime.fromtimestamp(step.stopped) - \ - datetime.fromtimestamp(step.started), + 'duration': to_datetime(step.stopped, utc) - \ + to_datetime(step.started, utc), 'failed': not step.successful, 'errors': step.errors, 'href': build_data['href'] + '#step_' + step.name @@ -528,10 +528,8 @@ if 'build' not in filters: return - if isinstance(start, datetime): # Trac>=0.11 - from trac.util.datefmt import to_timestamp - start = to_timestamp(start) - stop = to_timestamp(stop) + start = to_timestamp(start) + stop = to_timestamp(stop) add_stylesheet(req, 'bitten/bitten.css')