Skip to content

Commit

Permalink
Link resource types in self.master.data.rtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Nov 5, 2012
1 parent cc120be commit 3ba8c77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion master/buildbot/data/connector.py
Expand Up @@ -24,6 +24,10 @@ class Updates(object):
# empty container object; see _scanModule, below
pass

class RTypes(object):
# empty container object; see _scanModule, below
pass


class Root(base.Endpoint):
pathPattern = ('',)
Expand Down Expand Up @@ -54,7 +58,7 @@ def _scanModule(self, mod, _noSetattr=False):
obj = getattr(mod, sym)
if inspect.isclass(obj) and issubclass(obj, base.ResourceType):
rtype = obj(self.master)
setattr(self, rtype.type, rtype)
setattr(self.rtypes, rtype.type, rtype)

# put its update methonds into our 'updates' attribute
for name in dir(rtype):
Expand All @@ -79,6 +83,7 @@ def _scanModule(self, mod, _noSetattr=False):

def _setup(self):
self.updates = Updates()
self.rtypes = RTypes()
self.matcher[Root.pathPattern] = Root(self.master)
for moduleName in self.submodules:
module = reflect.namedModule(moduleName)
Expand Down
3 changes: 1 addition & 2 deletions master/buildbot/test/unit/test_data_connector.py
Expand Up @@ -142,7 +142,7 @@ def test_scanModule(self):
[ ('tests', base.Link(('test',))) ])

# and that it added an attribute
self.assertIsInstance(self.data.test, TestResourceType)
self.assertIsInstance(self.data.rtypes.test, TestResourceType)

def test_lookup(self):
ep = self.patchFooPattern()
Expand Down Expand Up @@ -201,7 +201,6 @@ class TestEndpoint(base.Endpoint):
pathPatterns = [ ('test', 'i:testid', 'p1'), ('test', 'i:testid', 'p2') ]

class TestResourceType(base.ResourceType):
name = 'tests'
type = 'test'
endpoints = [ TestsEndpoint, TestEndpoint, TestsEndpointSubclass ]
keyFields = ( 'testid', )
Expand Down
8 changes: 5 additions & 3 deletions master/docs/developer/data.rst
Expand Up @@ -107,9 +107,11 @@ Within the buildmaster process, the root of the data API is available at `self.m
Depending on the path, it will return a single resource or a list of resources.
If a single resource is not specified, it returns ``None``.

The connector also has an attribute named for each resource type.
These attributes allow resource types to access one another for purposes of coordination.
They are *not* intended for external access -- all external access to the data API should be via the methods above or update methods.
.. py:attribute:: rtypes
This object has an attribute named for each resource type, named after the singular form (e.g., `self.master.data.builder`).
These attributes allow resource types to access one another for purposes of coordination.
They are *not* intended for external access -- all external access to the data API should be via the methods above or update methods.


Updates
Expand Down

0 comments on commit 3ba8c77

Please sign in to comment.