Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This only implements changes, and implements them in a not-very-efficient and not-very-scalable way.
- Loading branch information
Showing
23 changed files
with
1,159 additions
and
51 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
import re | ||
|
||
class Endpoint(object): | ||
|
||
# set the pathPattern to the pattern that should trigger this endpoint | ||
pathPattern = None | ||
|
||
# the mq topic corresponding to this path, with %(..)s safely substituted | ||
# from the path kwargs; for more complex cases, override | ||
# getSubscriptionTopic. | ||
|
||
pathTopicTemplate = None | ||
|
||
def __init__(self, master): | ||
self.master = master | ||
|
||
def get(self, options, kwargs): | ||
raise NotImplementedError | ||
|
||
def control(self, action, args, kwargs): | ||
raise NotImplementedError | ||
|
||
def getSubscriptionTopic(self, options, kwargs): | ||
if self.pathTopicTemplate: | ||
if '%' not in self.pathTopicTemplate: | ||
return self.pathTopicTemplate | ||
safekwargs = SafeDict(kwargs) | ||
return self.pathTopicTemplate % safekwargs | ||
|
||
|
||
class SafeDict(object): | ||
# utility class to allow %-substitution with the results not containing | ||
# topic metacharacters (.*#) | ||
|
||
def __init__(self, dict): | ||
self.dict = dict | ||
|
||
metacharacters_re = re.compile('[.*#]') | ||
def __getitem__(self, k): | ||
return self.metacharacters_re.sub('_', self.dict[k]) | ||
|
||
|
||
class Link(object): | ||
|
||
__slots__ = [ 'path' ] | ||
|
||
# a link to another resource, specified as a path | ||
def __init__(self, path): | ||
self.path = path | ||
|
||
def __repr__(self): | ||
return "Link(%r)" % (self.path,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
from twisted.internet import defer | ||
from buildbot.data import base, exceptions | ||
from buildbot.util import datetime2epoch | ||
|
||
def _fixChange(change): | ||
# TODO: make these mods in the DB API | ||
if change: | ||
change = change.copy() | ||
del change['is_dir'] | ||
change['when_timestamp'] = datetime2epoch(change['when_timestamp']) | ||
change['link'] = base.Link(('change', str(change['changeid']))) | ||
return change | ||
|
||
|
||
class Change(base.Endpoint): | ||
|
||
pathPattern = ( 'change', 'i:changeid' ) | ||
|
||
def get(self, options, kwargs): | ||
d = self.master.db.changes.getChange(kwargs['changeid']) | ||
d.addCallback(_fixChange) | ||
return d | ||
|
||
|
||
class Changes(base.Endpoint): | ||
|
||
pathPattern = ( 'change', ) | ||
pathTopicTemplate = 'change.#' # TODO: test | ||
|
||
def get(self, options, kwargs): | ||
try: | ||
count = min(int(options.get('count', '50')), 50) | ||
except: | ||
return defer.fail( | ||
exceptions.InvalidOptionException('invalid count option')) | ||
d = self.master.db.changes.getRecentChanges(count) | ||
@d.addCallback | ||
def sort(changes): | ||
changes.sort(key=lambda chdict : chdict['changeid']) | ||
return map(_fixChange, changes) | ||
return d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
import inspect | ||
from twisted.application import service | ||
from buildbot.util import pathmatch | ||
from buildbot.data import update, exceptions, base | ||
|
||
class DataConnector(service.Service): | ||
|
||
def __init__(self, master): | ||
self.setName('data') | ||
self.master = master | ||
self.update = update.UpdateComponent(master) | ||
|
||
self.matcher = pathmatch.Matcher() | ||
self._setup() | ||
|
||
def _setup(self): | ||
def _scanModule(mod): | ||
for sym in dir(mod): | ||
obj = getattr(mod, sym) | ||
if inspect.isclass(obj) and issubclass(obj, base.Endpoint): | ||
self.matcher[obj.pathPattern] = obj(self.master) | ||
|
||
# scan all of the endpoint modules | ||
from buildbot.data import changes | ||
_scanModule(changes) | ||
|
||
def _lookup(self, path): | ||
try: | ||
return self.matcher[path] | ||
except KeyError: | ||
raise exceptions.InvalidPathError | ||
|
||
def get(self, options, path): | ||
endpoint, kwargs = self._lookup(path) | ||
return endpoint.get(options, kwargs) | ||
|
||
def startConsuming(self, callback, options, path): | ||
endpoint, kwargs = self._lookup(path) | ||
topic = endpoint.getSubscriptionTopic(options, kwargs) | ||
if not topic: | ||
raise exceptions.InvalidPathError | ||
# TODO: aggregate consumers of the same topics | ||
# TODO: double this up with get() somehow | ||
return self.master.mq.startConsuming(callback, topic) | ||
|
||
def control(self, action, args, path): | ||
endpoint, kwargs = self._lookup(path) | ||
return endpoint.control(action, args, kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
class DataException(Exception): | ||
pass | ||
|
||
class InvalidPathError(DataException): | ||
"A path argument was invalid or unknown" | ||
pass | ||
|
||
class InvalidOptionException(DataException): | ||
"An option was invalid" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
from twisted.application import service | ||
|
||
class UpdateComponent(service.Service): | ||
|
||
def __init__(self, master): | ||
self.setName('data.update') | ||
self.master = master | ||
|
||
# TODO.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
class FakeUpdateComponent(object): | ||
pass | ||
|
||
class FakeDataConnector(object): | ||
def __init__(self, master): | ||
self.master = master | ||
self.update = FakeUpdateComponent() | ||
self.update.master = master | ||
|
||
def get(self, options, path): | ||
pass | ||
|
||
def startConsuming(self, callback, options, path): | ||
return self.master.mq.startConsuming('x') # ugh.. | ||
|
||
def control(self, action, args, path): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.