def handle_static(self, context, plugin, path): plugin_path = manager.resolve_path(plugin) if plugin_path is None: context.respond_not_found() return 'Not Found' path = os.path.join(plugin_path, 'content/static', path) return context.file(path)
def inflate(self, layout): if not layout in self.cache or ajenti.debug: #profile('Inflating %s' % layout) plugin, path = layout.split(':') try: file = open(os.path.join(manager.resolve_path(plugin), 'layout', path + '.xml'), 'r') except IOError, e: raise TemplateNotFoundError(e) self.cache[layout] = etree.parse(file)
def precache(self): from ajenti.ui import UI temp_ui = UI.new() for plugin in manager.get_order(): layout_dir = os.path.join(manager.resolve_path(plugin), 'layout') if os.path.exists(layout_dir): for layout in os.listdir(layout_dir): layout = '%s:%s' % (plugin, layout.split('.')[0]) logging.debug('Precaching layout %s' % layout) self.inflate(temp_ui, layout)
def inflate(self, ui, layout): if not layout in self.cache or ajenti.debug: plugin, path = layout.split(":") try: file = open(os.path.join(manager.resolve_path(plugin), "layout", path + ".xml"), "r") except IOError, e: raise TemplateNotFoundError(e) data = file.read() data = """<xml xmlns:bind="bind" xmlns:binder="binder">%s</xml>""" % data xml = etree.fromstring(data, parser=self.parser)[0] self.cache[layout] = self.inflate_rec(ui, xml)
def inflate(self, ui, layout): if not layout in self.cache or ajenti.debug: plugin, path = layout.split(':') try: file = open(os.path.join(manager.resolve_path(plugin), 'layout', path + '.xml'), 'r') except IOError, e: raise TemplateNotFoundError(e) data = file.read() data = """<xml xmlns:bind="bind" xmlns:binder="binder">%s</xml>""" % data xml = etree.fromstring(data, parser=self.parser)[0] self.cache[layout] = self.inflate_rec(ui, xml)
def inflate(self, layout): if not layout in self.cache or ajenti.debug: #profile('Inflating %s' % layout) plugin, path = layout.split(':') try: file = open(os.path.join(manager.resolve_path(plugin), 'layout', path + '.xml'), 'r') except IOError, e: raise TemplateNotFoundError(e) data = file.read() data = """<xml xmlns:bind="bind" xmlns:binder="binder">%s</xml>""" % data self.cache[layout] = etree.fromstring(data, parser=self.parser)[0]
def precache(self): from ajenti.ui import UI temp_ui = UI.new() for plugin in manager.get_order(): layout_dir = os.path.join(manager.resolve_path(plugin), "layout") if os.path.exists(layout_dir): for layout in os.listdir(layout_dir): layout_name = os.path.splitext(layout)[0] if layout_name: layout = "%s:%s" % (plugin, layout_name) logging.debug("Precaching layout %s" % layout) self.inflate(temp_ui, layout)
def inflate(self, ui, layout): if not layout in self.cache or ajenti.debug: plugin, path = layout.split(':') try: file = open(os.path.join(manager.resolve_path(plugin), 'layout', path + '.xml'), 'r') except IOError as e: raise TemplateNotFoundError(e) data = file.read() data = """<xml xmlns:bind="bind" xmlns:binder="binder">%s</xml>""" % data xml = etree.fromstring(data, parser=self.parser)[0] self.cache[layout] = self.inflate_rec(ui, xml) layout = self.cache[layout].clone(set_ui=ui, set_context=(ui or self).context) return layout
def scan(self): for plugin in manager.get_order(): pfiles = {} path = os.path.join(manager.resolve_path(plugin), 'content') if not os.path.exists(path): continue for (dp, dn, fn) in os.walk(path): for name in fn: for key in self.patterns: if re.match(self.patterns[key], name): pfiles.setdefault(key, []).append(os.path.join(dp, name)) for key in self.patterns: self.files.setdefault(key, []).extend(sorted(pfiles.setdefault(key, [])))