def getResourceList(self, resourceDirs, path, ext=None,pkg=None):
     """Find a resource in the current ``_resources`` folder or in parent folders one
     
     :param resourceDirs: TODO
     :param path: TODO
     :param ext: TODO"""
     result = []
     if ext == 'css' or ext == 'js':
         locations = resourceDirs[:]
         locations.reverse()
     else:
         locations = resourceDirs
     if ext and not path.endswith('.%s' % ext): path = '%s.%s' % (path, ext)
     if '*' in path:
         searchpath=os.path.split(path.split('*')[0])[0]
         use_glob=True
     else:
         searchpath=path
         use_glob=False
     for dpath in locations:
         fpath = os.path.join(dpath, searchpath)
         if os.path.exists(fpath):
             if use_glob:
                 result.extend(glob.glob(os.path.join(dpath,path)))
             else:
                 result.append(fpath)
     return uniquify(result)
Beispiel #2
0
 def getResourceList(self, resourceDirs, path, ext=None,pkg=None):
     """Find a resource in the current ``_resources`` folder or in parent folders one
     
     :param resourceDirs: TODO
     :param path: TODO
     :param ext: TODO"""
     result = []
     if ext == 'css' or ext == 'js':
         locations = resourceDirs[:]
         locations.reverse()
     else:
         locations = resourceDirs
     if ext and not path.endswith('.%s' % ext): path = '%s.%s' % (path, ext)
     if '*' in path:
         searchpath=os.path.split(path.split('*')[0])[0]
         use_glob=True
     else:
         searchpath=path
         use_glob=False
     for dpath in locations:
         fpath = os.path.join(dpath, searchpath)
         if os.path.exists(fpath):
             if use_glob:
                 result.extend(glob.glob(os.path.join(dpath,path)))
             else:
                 result.append(fpath)
     return uniquify(result)
Beispiel #3
0
 def getRepositoryBag(self):
     repositories = Bag()
     for path in uniquify(self.site.gnrapp.config['packages'].digest('#a.path')):
         has_git = False
         while path and not has_git:
             path = os.path.split(path)[0]
             has_git = os.path.exists(os.path.join(path,'.git'))
             if has_git and not path in repositories:
                 changes = self.getGitRepositoriesChanges(path)
                 repositories[path] = Bag(path=path,name=os.path.split(path)[1],
                             to_pull="""<a href='#' onclick="genro.publish('git_pull',{repository:'%s'})">Pull %i</a>""" %(path,changes['to_pull']) if changes['to_pull'] else ' ',
                             to_push = """<a href='#' onclick="genro.publish('git_push',{repository:'%s'})">Push %i</a>""" %(path,changes['to_push']) if changes['to_push'] else ' ',
                             )
     return repositories
Beispiel #4
0
    def get_page_class(self, basepath=None,relpath=None, pkg=None, plugin=None,request_args=None,request_kwargs=None):
        """TODO
        
        :param path: TODO
        :param pkg: the :ref:`package <packages>` object"""

        module_path = os.path.join(basepath,relpath)
        page_module = gnrImport(module_path, avoidDup=True,silent=False)
        page_factory = getattr(page_module, 'page_factory', GnrWebPage)
        custom_class = getattr(page_module, 'GnrCustomWebPage')
        mainPkg = pkg
        if hasattr(custom_class,'getMainPackage'):
            kw = dict()
            if 'page_id' in request_kwargs:
                kw = self.site.register.pageStore(request_kwargs['page_id']).getItem('pageArgs') or dict()
                kw.update(request_kwargs)
            mainPkg = custom_class.getMainPackage(request_args=request_args,request_kwargs=kw)
        py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''), ',')
        plugin_webpage_classes = self.plugin_webpage_classes(relpath, pkg=mainPkg)
        for plugin_webpage_class in plugin_webpage_classes:
            plugin_py_requires = splitAndStrip(getattr(plugin_webpage_class, 'py_requires', ''), ',')
            py_requires.extend(plugin_py_requires)
        page_class = cloneClass('GnrCustomWebPage', page_factory)
        page_class.__module__ = page_module.__name__
        self.page_class_base_mixin(page_class, pkg=mainPkg)
        package_py_requires = splitAndStrip(getattr(page_class, 'package_py_requires', ''), ',')
        package_js_requires = splitAndStrip(getattr(page_class, 'package_js_requires', ''), ',')
        package_css_requires = splitAndStrip(getattr(page_class, 'package_css_requires', ''), ',') 
        if package_py_requires:
            py_requires = uniquify(package_py_requires + py_requires)
        page_class.dojo_version = getattr(custom_class, 'dojo_version', None) or self.site.config[
                                                                                 'dojo?version'] or '11'
        page_class.theme = getattr(custom_class, 'theme', None) or self.site.config['dojo?theme'] or 'tundra'
        page_class.gnrjsversion = getattr(custom_class, 'gnrjsversion', None) or self.site.config[
                                                                                 'gnrjs?version'] or '11'
        page_class.maintable = getattr(custom_class, 'maintable', None)
        page_class.recordLock = getattr(custom_class, 'recordLock', None)
        page_class.user_polling = int(
                getattr(custom_class, 'user_polling', None) or self.site.config['polling?user'] or 3)
        page_class.auto_polling = int(
                getattr(custom_class, 'auto_polling', None) or self.site.config['polling?auto'] or 30)
        if hasattr(custom_class,'polling_enabled'):
            page_class.polling_enabled = getattr(custom_class, 'polling_enabled')
        page_class.eagers = getattr(custom_class, 'eagers', {})
        page_class.css_requires = []
        page_class.js_requires = splitAndStrip(getattr(custom_class, 'js_requires', ''), ',')
        if package_js_requires:
            page_class.js_requires = uniquify(package_js_requires + page_class.js_requires)
        page_class.pageOptions = getattr(custom_class, 'pageOptions', {})
        page_class.auth_tags = getattr(custom_class, 'auth_tags', '')
        page_class.resourceDirs = self.page_class_resourceDirs(page_class, module_path, pkg=mainPkg)
        self.page_pyrequires_mixin(page_class, py_requires)
        classMixin(page_class, custom_class, only_callables=False)
        page_class.css_requires.extend([x for x in splitAndStrip(getattr(custom_class, 'css_requires', ''), ',') if x])
        if package_css_requires:
            page_class.css_requires = uniquify(page_class.css_requires+package_css_requires)
        page_class.tpldirectories = page_class.resourceDirs + [
                self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')]
        page_class._packageId = mainPkg
        self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
        self.page_class_custom_mixin(page_class, relpath, pkg=mainPkg)
        self.page_factories[module_path] = page_class
        return page_class