2016-08-31 14:31:45 +02:00
|
|
|
"""Subversion interface."""
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
import attr
|
|
|
|
import blinker
|
|
|
|
import svn.remote
|
|
|
|
|
|
|
|
from . import attrs_extra
|
|
|
|
|
|
|
|
task_logged = blinker.NamedSignal('task_logged')
|
|
|
|
task_marker_re = re.compile(r'\[(?P<task_id>T\d+)\]')
|
|
|
|
|
|
|
|
|
|
|
|
def obtain(server_location):
|
|
|
|
"""Returns a Connection object for the given server location."""
|
|
|
|
|
|
|
|
return svn.remote.RemoteClient(server_location)
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class CommitLogObserver(object):
|
|
|
|
svn_client = attr.ib(validator=attr.validators.instance_of(svn.remote.RemoteClient))
|
|
|
|
last_seen_revision = attr.ib(default=0, validator=attr.validators.instance_of(int))
|
|
|
|
_log = attrs_extra.log('%s.CommitLogObserver' % __name__)
|
|
|
|
|
|
|
|
def fetch_and_observe(self):
|
|
|
|
"""Obtains task IDs from SVN logs."""
|
|
|
|
|
|
|
|
self._log.debug('%s: fetch_and_observe()', self)
|
|
|
|
|
|
|
|
svn_log = self.svn_client.log_default(
|
2016-08-31 15:59:27 +02:00
|
|
|
revision_from=self.last_seen_revision + 1)
|
2016-08-31 14:31:45 +02:00
|
|
|
|
|
|
|
for log_entry in svn_log:
|
|
|
|
self._log.debug('- %r', log_entry)
|
|
|
|
|
|
|
|
# assumption: revisions are always logged in strictly increasing order.
|
|
|
|
self.last_seen_revision = log_entry.revision
|
|
|
|
|
|
|
|
# Parse the commit log to see if there are any task markers.
|
|
|
|
lines = log_entry.msg.split('\n', 1)
|
|
|
|
first_line = lines[0]
|
|
|
|
for match in task_marker_re.finditer(first_line):
|
|
|
|
task_id = match.group('task_id')
|
|
|
|
|
|
|
|
task_logged.send(self,
|
|
|
|
task_id=task_id,
|
|
|
|
log_entry=log_entry)
|