def test_loadpackages(self): from ptah.config import api self.assertEqual( api.list_packages(('ptah',), excludes=('ptah',)), []) self.assertIn('ptah', api.list_packages()) self.assertEqual(api.list_packages(excludes=('ptah',)), [])
def update(self): ev = self.request.params.get('ev') all_events = config.registry.storage[directives.EVENT_ID] self.event = event = all_events.get(ev) if event is None: events = [] for n, ev in all_events.items(): if isinstance(n, basestring): events.append((ev.title, ev)) events.sort() self.events = [ev for _t, ev in events] else: pkgs = list_packages() evinst = event.instance seen = set() actions = [] for pkg in pkgs: for action in directives.scan(pkg, seen, exclude): if action.discriminator[0] == 'ptah.config:subscriber': required = action.args[2] if len(required) == 2 and required[1] == evinst: actions.append(action) elif required[0] == evinst: actions.append(action) self.actions = actions
def list_packages(self): if self.packages is None: self.packages = list_packages() self.packages.sort() return self.packages
def update(self): #ev = self.request.params.get('ev') self.route = route = None #directives.events.get(ev) if route is None: packages = list_packages() viewactions = [] seen = set() routes = {} for pkg in packages: actions = directives.scan(pkg, seen, exclude) for action in actions: d = action.discriminator[0] if d == 'ptah.view:route': name, pattern, factory = action.args[:3] routes[name] = (pattern, name, factory, []) elif d == 'ptah.view:view': factory = action.info.context if inspect.isclass(factory): isclass = True name = action.args[0] context = action.args[1] route = action.args[3] else: isclass = False factory = action.args[0] name = action.args[1] context = action.args[2] route = action.args[4] if route: viewactions.append( (route, name, context, factory, action)) sm = config.registry # add pyramid routes for route in sm.getUtility(IRoutesMapper).get_routes(): if route.name not in routes: routes[route.name] = ( route.pattern, route.name, route.factory, []) # attach views to routes for route, name, context, factory, action in viewactions: try: rdata = routes[route][3] except: # pragma: no cover continue rdata.append([getattr(factory, '__intr_path__', name), action.info.module.__name__, lineno(factory), factory, action.discriminator[-1]]) rdata.sort() routes = routes.values() routes.sort() self.routes = routes # views route_requests = [i for n, i in sm.getUtilitiesFor(IRouteRequest)] views = [] data = sm.adapters._adapters[3] for classifier, data in data.items(): if classifier in (IViewClassifier, IExceptionViewClassifier): for req, data2 in data.items(): if req in route_requests: continue for context, data3 in data2.items(): if isinstance(context, InterfaceClass): context = '%s.%s'%( context.__module__, context.__name__) else: context = context.__name__ for provides, adapters in data3.items(): for name, factory in adapters.items(): views.append( (context,name,classifier,req,factory)) views.sort() self.views = views