Skip to content

Commit

Permalink
Ability to specify a timezone for a P4 server
Browse files Browse the repository at this point in the history
The Perforce server used with `P4Source` may be in a different time zone
than the Buildbot master, which would cause, for example, changes to be
displayed in the wrong place on the Waterfall display.

This change lets you specify a timezone for the server. Changelist times
will be converted from that timezone to the local timezone before being
added to the Buildbot master.
  • Loading branch information
ludovicchabant committed May 8, 2013
1 parent 47ef757 commit bea0988
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions master/buildbot/changes/p4poller.py
Expand Up @@ -18,7 +18,8 @@
# Many thanks to Dave Peticolas for contributing this module

import re
import time
import datetime
import dateutil
import os

from twisted.python import log
Expand All @@ -32,7 +33,7 @@ class P4PollerError(Exception):
exception type so that unit tests can detect and ignore it."""

def get_simple_split(branchfile):
"""Splits the branchfile argument and assuming branch is
"""Splits the branchfile argument and assuming branch is
the first path component in branchfile, will return
branch and file else None."""

Expand Down Expand Up @@ -66,7 +67,8 @@ def __init__(self, p4port=None, p4user=None, p4passwd=None,
p4base='//', p4bin='p4',
split_file=lambda branchfile: (None, branchfile),
pollInterval=60 * 10, histmax=None, pollinterval=-2,
encoding='utf8', project=None, name=None):
encoding='utf8', project=None, name=None,
server_tz=None):

# for backward compatibility; the parameter used to be spelled with 'i'
if pollinterval != -2:
Expand All @@ -85,6 +87,7 @@ def __init__(self, p4port=None, p4user=None, p4passwd=None,
self.split_file = split_file
self.encoding = encoding
self.project = project
self.server_tz = server_tz

def describe(self):
return "p4source %s %s" % (self.p4port, self.p4base)
Expand Down Expand Up @@ -157,7 +160,11 @@ def _poll(self):
if not m:
raise P4PollerError("Unexpected 'p4 describe -s' result: %r" % result)
who = m.group('who')
when = time.mktime(time.strptime(m.group('when'), self.datefmt))
when = datetime.datetime.strptime(m.group('when'), self.datefmt)
if self.server_tz:
# Convert from the server's timezone to the local timezone.
when = when.replace(tzinfo=self.server_tz)
when = when.astimezone(dateutil.tz.tzlocal())
comments = ''
while not lines[0].startswith('Affected files'):
comments += lines.pop(0) + '\n'
Expand Down Expand Up @@ -185,7 +192,7 @@ def _poll(self):
files=branch_files[branch],
comments=comments,
revision=str(num),
when_timestamp=util.epoch2datetime(when),
when_timestamp=when,
branch=branch,
project=self.project)

Expand Down

0 comments on commit bea0988

Please sign in to comment.