Пример #1
0
 def load_plugin(self, plugin_name):
     if self.page.packageId:
         plugin_folder = os.path.join(self.page.pkgapp.libPath, 'plugins')
         plugin_module_name = "%s.py" % plugin_name
         plugin_module = gnrImport(os.path.join(os.path.join(plugin_folder, plugin_module_name)), avoidDup=True)
     if not plugin_module:
         plugin_module = gnrImport('gnr.web.gnrwebpage_plugin.%s' % plugin_name)
         plugin_class = getattr(plugin_module, 'Plugin')
     return plugin_class
                 
Пример #2
0
 def loadTableScript(self, page, table=None, respath=None, class_name=None):
     """TODO
     
     :param page: TODO
     :param table: the :ref:`database table <table>` name on which the query will be executed,
                   in the form ``packageName.tableName`` (packageName is the name of the
                   :ref:`package <packages>` to which the table belongs to)
     :param respath: TODO
     :param class_name: TODO
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if ':' in respath:
         table, respath = respath.split(':')
     if isinstance(table, basestring):
         table = application.db.table(table)
     if not table:
         tablename = '_default'
         modName = os.path.join('tables', tablename, *(respath.split('/')))
     else:
         tablename = table.name
         pkgname = table.pkg.name
         modName = os.path.join('tables', '_packages', pkgname, tablename,
                                *(respath.split('/')))
     resourceDirs = page.resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py')
     if not modPathList and table is not None:
         resourceDirs = self.package_resourceDirs(table.pkg.name)
         modName = os.path.join('tables', tablename, *(respath.split('/')))
         modPathList = self.getResourceList(resourceDirs, modName, 'py')
         if not modPathList:
             tablename = '_default'
             resourceDirs = page.resourceDirs
             modName = os.path.join('tables', tablename,
                                    *(respath.split('/')))
             modPathList = self.getResourceList(resourceDirs, modName, 'py')
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class = cloneClass('CustomResource', resource_class)
             custom_resource_class = getattr(resource_module, class_name,
                                             None)
             if resource_class:
                 classMixin(resource_class,
                            custom_resource_class,
                            only_callables=False)
         resource_obj = resource_class(page=page, resource_table=table)
         return resource_obj
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Пример #3
0
 def load_plugin(self, plugin_name):
     if self.page.packageId:
         plugin_folder = os.path.join(self.page.pkgapp.libPath, 'plugins')
         plugin_module_name = "%s.py" % plugin_name
         plugin_module = gnrImport(os.path.join(
             os.path.join(plugin_folder, plugin_module_name)),
                                   avoidDup=True)
     if not plugin_module:
         plugin_module = gnrImport('gnr.web.gnrwebpage_plugin.%s' %
                                   plugin_name)
         plugin_class = getattr(plugin_module, 'Plugin')
     return plugin_class
Пример #4
0
 def loadTableScript(self,
                     page,
                     table=None,
                     respath=None,
                     class_name=None,
                     _onDefault=None):
     """add???
     
     :param page: add???
     :param table: add???. Default value is ``None``
     :param respath: add???. Default value is ``None``
     :param class_name: add???. Default value is ``None``
     :param _onDefault: add???. Default value is ``None``
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if not table:
         _onDefault = True
     if ':' in respath:
         table, respath = respath.split(':')
     if _onDefault:
         tablename = '_default'
         resourceDirs = page.resourceDirs
     else:
         if isinstance(table, basestring):
             table = application.db.table(table)
         tablename = table.name
         resourceDirs = self.package_resourceDirs(table.pkg.name)
     modName = os.path.join('tables', tablename, *(respath.split('/')))
     #resourceDirs = application.packages[table.pkg.name].resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         resource_obj = resource_class(page=page, resource_table=table)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class = getattr(resource_module, class_name, None)
             if resource_class:
                 instanceMixin(resource_obj,
                               resource_class,
                               only_callables=False)
         return resource_obj
     elif not _onDefault:
         return self.loadTableScript(page,
                                     table=table,
                                     respath=respath,
                                     _onDefault=True)
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Пример #5
0
 def loadTableScript(self, page, table=None, respath=None, class_name=None):
     """TODO
     
     :param page: TODO
     :param table: the :ref:`database table <table>` name on which the query will be executed,
                   in the form ``packageName.tableName`` (packageName is the name of the
                   :ref:`package <packages>` to which the table belongs to)
     :param respath: TODO
     :param class_name: TODO
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if ':' in respath:
         table, respath = respath.split(':')
     if isinstance(table, basestring):
         table = application.db.table(table)
     if not table:
         tablename = '_default'
         modName = os.path.join('tables', tablename, *(respath.split('/')))
     else:
         tablename = table.name
         pkgname = table.pkg.name
         modName = os.path.join('tables','_packages',pkgname, tablename, *(respath.split('/')))
     resourceDirs = page.resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py')
     if not modPathList and table is not None:
         resourceDirs = self.package_resourceDirs(table.pkg.name)
         modName = os.path.join('tables', tablename, *(respath.split('/')))
         modPathList = self.getResourceList(resourceDirs, modName, 'py')
         if not modPathList:
             tablename = '_default'
             resourceDirs = page.resourceDirs
             modName = os.path.join('tables', tablename, *(respath.split('/')))
             modPathList = self.getResourceList(resourceDirs, modName, 'py')
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class =cloneClass('CustomResource', resource_class)
             custom_resource_class = getattr(resource_module, class_name, None)
             if resource_class:
                 classMixin(resource_class, custom_resource_class, only_callables=False)
         resource_obj = resource_class(page=page, resource_table=table)
         return resource_obj
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Пример #6
0
 def find_webtools(self):
     """TODO"""
     def isgnrwebtool(cls):
         return inspect.isclass(cls) and issubclass(cls, BaseWebtool) and cls is not BaseWebtool
         
     tools = {}
     webtool_pathlist = []
     if 'webtools' in self.gnr_config['gnr.environment_xml']:
         for path in self.gnr_config['gnr.environment_xml'].digest('webtools:#a.path'):
             webtool_pathlist.append(expandpath(path))
     for package in self.gnrapp.packages.values():
         webtool_pathlist.append(os.path.join(package.packageFolder, 'webtools'))
     project_resource_path = os.path.join(self.site_path, '..', '..', 'webtools')
     webtool_pathlist.append(os.path.normpath(project_resource_path))
     for path in webtool_pathlist:
         if not os.path.isdir(path):
             continue
         for tool_module in os.listdir(path):
             if tool_module.endswith('.py'):
                 module_path = os.path.join(path, tool_module)
                 try:
                     module = gnrImport(module_path, avoidDup=True)
                     tool_classes = inspect.getmembers(module, isgnrwebtool)
                     tool_classes = [(name.lower(), value) for name, value in tool_classes]
                     tools.update(dict(tool_classes))
                 except ImportError:
                     pass
     return tools
Пример #7
0
        def cb(node, _pathlist=None):
            has_parameters = False
            if node.attr['file_ext'] == 'py':
                resmodule = gnrImport(node.attr['abs_path'])
                tags = getattr(resmodule, 'tags', '')

                if tags and not self.application.checkResourcePermission(
                        tags, self.userTags):
                    if node.label == '_doc':
                        forbiddenNodes.append('.'.join(_pathlist))
                    return
                caption = getattr(resmodule, 'caption', node.label)
                description = getattr(resmodule, 'description', '')
                if node.label == '_doc':
                    result.setAttr(
                        '.'.join(_pathlist),
                        dict(caption=caption,
                             description=description,
                             tags=tags,
                             has_parameters=has_parameters))
                else:
                    mainclass = getattr(resmodule, 'Main', None)
                    assert mainclass, 'Main class is mandatory in tablescript resource'
                    has_parameters = hasattr(mainclass, 'parameters_pane')
                    result.setItem('.'.join(_pathlist + [node.label]),
                                   None,
                                   caption=caption,
                                   description=description,
                                   resource=node.attr['rel_path'][:-3],
                                   has_parameters=has_parameters)
Пример #8
0
        def cb(node, _pathlist=None):
            has_parameters = False
            if node.attr["file_ext"] == "py":
                resmodule = gnrImport(node.attr["abs_path"])
                tags = getattr(resmodule, "tags", "")

                if tags and not self.application.checkResourcePermission(tags, self.userTags):
                    if node.label == "_doc":
                        forbiddenNodes.append(".".join(_pathlist))
                    return
                caption = getattr(resmodule, "caption", node.label)
                description = getattr(resmodule, "description", "")
                if node.label == "_doc":
                    result.setAttr(
                        ".".join(_pathlist),
                        dict(caption=caption, description=description, tags=tags, has_parameters=has_parameters),
                    )
                else:
                    mainclass = getattr(resmodule, "Main", None)
                    assert mainclass, "Main class is mandatory in tablescript resource"
                    has_parameters = hasattr(mainclass, "parameters_pane")
                    result.setItem(
                        ".".join(_pathlist + [node.label]),
                        None,
                        caption=caption,
                        description=description,
                        resource=node.attr["rel_path"][:-3],
                        has_parameters=has_parameters,
                    )
Пример #9
0
 def addSiteServices(self):
     services = self.site.config['services']
     if not services:
         return
     for service in services:
         kw = dict(service.attr)
         if service.value:
             kw['_content'] = service.value
         resource = kw.pop('resource', service.label)
         service_type = kw.pop('service_type', service.label)
         resmodule, resclass = resource.split(
             ':') if ':' in resource else resource, 'Main'
         modules = self.site.resource_loader.getResourceList(
             self.site.resources_dirs,
             'services/%s/%s.py' % (service_type, resmodule))
         assert modules, 'Missing module %s for service %s ' % (
             resmodule, service_type)
         module = modules[0]
         try:
             module = gnrImport(module)
             service_class = getattr(module, resclass)
             self.add(service_class, service_name=service.label, **kw)
         except ImportError, import_error:
             log.exception("Could not import %s" % module)
             log.exception(str(import_error))
Пример #10
0
    def find_webtools(self):
        """add???"""
        def isgnrwebtool(cls):
            return inspect.isclass(cls) and issubclass(
                cls, BaseWebtool) and cls is not BaseWebtool

        tools = {}
        webtool_pathlist = []
        if 'webtools' in self.gnr_config['gnr.environment_xml']:
            for path in self.gnr_config['gnr.environment_xml'].digest(
                    'webtools:#a.path'):
                webtool_pathlist.append(expandpath(path))
        for package in self.gnrapp.packages.values():
            webtool_pathlist.append(
                os.path.join(package.packageFolder, 'webtools'))
        project_resource_path = os.path.join(self.site_path, '..', '..',
                                             'webtools')
        webtool_pathlist.append(os.path.normpath(project_resource_path))
        for path in webtool_pathlist:
            if not os.path.isdir(path):
                continue
            for tool_module in os.listdir(path):
                if tool_module.endswith('.py'):
                    module_path = os.path.join(path, tool_module)
                    try:
                        module = gnrImport(module_path, avoidDup=True)
                        tool_classes = inspect.getmembers(module, isgnrwebtool)
                        tool_classes = [(name.lower(), value)
                                        for name, value in tool_classes]
                        tools.update(dict(tool_classes))
                    except ImportError:
                        pass
        return tools
Пример #11
0
 def batch_loader(self, batch_class):
     if ':' in batch_class:
         module_path, class_name = batch_class.split(':')
         module = gnrImport(module_path)
     else:
         class_name = batch_class
         module = gnr.app.gnrbatch
     return getattr(module, class_name, None)
Пример #12
0
 def parseClass(self, txt):
     module, clsname = txt.split(':')
     m = gnrImport(module)
     c = getattr(m, clsname)
     if hasattr(c, '__safe__'):
         return c
     else:
         raise Exception('Unsecure class %s' % txt)
Пример #13
0
 def batch_loader(self, batch_class):
     if ':' in batch_class:
         module_path, class_name = batch_class.split(':')
         module = gnrImport(module_path)
     else:
         class_name = batch_class
         module = gnr.app.gnrbatch
     return getattr(module, class_name, None)
Пример #14
0
 def loadTableScript(self, page, table=None, respath=None, class_name=None, _onDefault=None):
     """add???
     
     :param page: add???
     :param table: add???. Default value is ``None``
     :param respath: add???. Default value is ``None``
     :param class_name: add???. Default value is ``None``
     :param _onDefault: add???. Default value is ``None``
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if not table:
         _onDefault = True
     if ':' in respath:
         table, respath = respath.split(':')
     if _onDefault:
         tablename = '_default'
         resourceDirs = page.resourceDirs
     else:
         if isinstance(table, basestring):
             table = application.db.table(table)
         tablename = table.name
         resourceDirs = self.package_resourceDirs(table.pkg.name)
     modName = os.path.join('tables', tablename, *(respath.split('/')))
     #resourceDirs = application.packages[table.pkg.name].resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         resource_obj = resource_class(page=page, resource_table=table)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class = getattr(resource_module, class_name, None)
             if resource_class:
                 instanceMixin(resource_obj, resource_class, only_callables=False)
         return resource_obj
     elif not _onDefault:
         return self.loadTableScript(page, table=table, respath=respath, _onDefault=True)
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Пример #15
0
 def get_page_class(self, path=None, pkg=None):
     """add???
     
     :param path: add???. Default value is ``None``
     :param pkg: add???. Default value is ``None``
     :returns: add???
     """
     if pkg == '*':
         module_path = os.path.join(self.site_path, path)
         pkg = self.site.config['packages?default']
     else:
         module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder, 'webpages', path)
         
     # if module_path in self.page_factories:
     #    return self.page_factories[module_path]
     page_module = gnrImport(module_path, avoidDup=True)
     page_factory = getattr(page_module, 'page_factory', GnrWebPage)
     custom_class = getattr(page_module, 'GnrCustomWebPage')
     py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''), ',')
     plugin_webpage_classes = self.plugin_webpage_classes(path, pkg=pkg)
     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
     self.page_class_base_mixin(page_class, pkg=pkg)
     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)
     page_class.eagers = getattr(custom_class, 'eagers', {})
     page_class.css_requires = []
     page_class.js_requires = splitAndStrip(getattr(custom_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=pkg)
     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])
     page_class.tpldirectories = page_class.resourceDirs + [
             self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')]
     page_class._packageId = pkg
     self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
     self.page_class_custom_mixin(page_class, path, pkg=pkg)
     self.page_factories[module_path] = page_class
     return page_class
Пример #16
0
 def startServiceDaemon(self,sitename, service_name=None):
     p = PathResolver()
     siteconfig = p.get_siteconfig(sitename)
     services = siteconfig['services']
     service_attr = services.getAttr(service_name)
     pkg, pathlib = service_attr['daemon'].split(':')
     p = os.path.join(p.package_name_to_path(pkg), 'lib', '%s.py' % pathlib)
     m = gnrImport(p)
     service_attr.update({'sitename': sitename})
     proc = Process(name='service_daemon_%s_%s' %(sitename, service_name), 
                     target=getattr(m, 'run'), kwargs=service_attr)
     proc.daemon = True
     proc.start()
     return proc
Пример #17
0
 def page_class_custom_mixin(self, page_class, path, pkg=None):
     """Look in the instance custom folder for a file named as the current webpage
     
     :param page_class: TODO
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     path = path.split(os.path.sep)
     if pkg:
         customPagePath = os.path.join(self.gnrapp.customFolder, pkg, 'webpages', *path)
         if os.path.isfile(customPagePath):
             component_page_module = gnrImport(customPagePath, avoidDup=True)
             component_page_class = getattr(component_page_module, 'WebPage', None)
             if component_page_class:
                 classMixin(page_class, component_page_class, only_callables=False)
Пример #18
0
 def page_class_custom_mixin(self, page_class, path, pkg=None):
     """Look in the instance custom folder for a file named as the current webpage
     
     :param page_class: TODO
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     path = path.split(os.path.sep)
     if pkg:
         customPagePath = os.path.join(self.gnrapp.customFolder, pkg, 'webpages', *path)
         if os.path.isfile(customPagePath):
             component_page_module = gnrImport(customPagePath, avoidDup=True)
             component_page_class = getattr(component_page_module, 'WebPage', None)
             if component_page_class:
                 classMixin(page_class, component_page_class, only_callables=False)
Пример #19
0
 def startServiceDaemon(self, sitename, service_name=None):
     p = PathResolver()
     siteconfig = p.get_siteconfig(sitename)
     services = siteconfig['services']
     service_attr = services.getAttr(service_name)
     pkg, pathlib = service_attr['daemon'].split(':')
     p = os.path.join(p.package_name_to_path(pkg), 'lib', '%s.py' % pathlib)
     m = gnrImport(p)
     service_attr.update({'sitename': sitename})
     proc = Process(name='service_daemon_%s_%s' % (sitename, service_name),
                    target=getattr(m, 'run'),
                    kwargs=service_attr)
     proc.daemon = True
     proc.start()
     return proc
Пример #20
0
 def plugin_webpage_classes(self, path, pkg=None):
     """Look in the plugins folders for a file named as the current webpage and get all classes
     
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     plugin_webpage_classes = []
     path = path.split(os.path.sep)
     pkg = pkg and self.site.gnrapp.packages[pkg]
     if pkg:
         pkg_plugins = pkg.getPlugins()
         for plugin in pkg_plugins:
             pluginPagePath = os.path.join(plugin.webpages_path, *path)
             if os.path.isfile(pluginPagePath):
                 component_page_module = gnrImport(pluginPagePath, avoidDup=True)
                 component_page_class = getattr(component_page_module, 'GnrCustomWebPage', None)
                 if component_page_class:
                     plugin_webpage_classes.append(component_page_class)
     return plugin_webpage_classes
Пример #21
0
 def plugin_webpage_classes(self, path, pkg=None):
     """Look in the plugins folders for a file named as the current webpage and get all classes
     
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     plugin_webpage_classes = []
     path = path.split(os.path.sep)
     pkg = pkg and self.site.gnrapp.packages[pkg]
     if pkg:
         pkg_plugins = pkg.getPlugins()
         for plugin in pkg_plugins:
             pluginPagePath = os.path.join(plugin.webpages_path, *path)
             if os.path.isfile(pluginPagePath):
                 component_page_module = gnrImport(pluginPagePath, avoidDup=True)
                 component_page_class = getattr(component_page_module, 'GnrCustomWebPage', None)
                 if component_page_class:
                     plugin_webpage_classes.append(component_page_class)
     return plugin_webpage_classes
Пример #22
0
 def addSiteServices_old(self, service_names=None):
     service_list = []
     if isinstance(service_names, basestring):
         service_names = service_names.replace(';',',').split(',')
     if service_names:
         service_finder = lambda cls: is_ServiceHandler(cls, service_names=service_names)
     elif service_names==[]:
         return
     else:
         service_finder = is_ServiceHandler
     modules = self.site.resource_loader.getResourceList(self.site.resources_dirs, 'services/*.py')
     for module_file in modules:
         try:
             module = gnrImport(module_file)
         except ImportError, import_error:
             log.exception("Could not import %s"%module_file)
             log.exception(str(import_error))
         else:
             service_list.extend(inspect.getmembers(module, service_finder))
Пример #23
0
 def addSiteServices(self):
     services = self.site.config['services']
     if not services:
         return
     for service in services:
         kw = dict(service.attr)
         resource = kw.pop('resource',service.label)
         service_type = kw.pop('service_type',service.label)
         resmodule,resclass = resource.split(':') if ':' in resource else resource,'Main'
         modules = self.site.resource_loader.getResourceList(self.site.resources_dirs, 'services/%s/%s.py' %(service_type,resmodule))
         assert modules,'Missing module %s for service %s '  %(resmodule,service_type)    
         module = modules[0]
         try:
             module = gnrImport(module)
             service_class = getattr(module,resclass)
             self.add(service_class,service_name=service.label,**kw)
         except ImportError, import_error:
             log.exception("Could not import %s"%module)
             log.exception(str(import_error))
Пример #24
0
 def cb(node, _pathlist=None):
     has_parameters = False
     if node.attr['file_ext'] == 'py':
         resmodule = gnrImport(node.attr['abs_path'])
         tags = getattr(resmodule, 'tags', '')
         if tags and not self.application.checkResourcePermission(tags, self.userTags):
             if node.label == '_doc':
                 forbiddenNodes.append('.'.join(_pathlist))
             return
         caption = getattr(resmodule, 'caption', node.label)
         description = getattr(resmodule, 'description', '')
         description = getattr(resmodule, 'needSelection', True)
         if  node.label == '_doc':
             result.setAttr('.'.join(_pathlist), dict(caption=caption, description=description, tags=tags,
                                                      has_parameters=has_parameters))
         else:
             mainclass = getattr(resmodule, 'Main', None)
             assert mainclass, 'Main class is mandatory in tablescript resource'
             has_parameters = hasattr(mainclass, 'parameters_pane')
             result.setItem('.'.join(_pathlist + [node.label]), None, caption=caption, description=description,
                            resource=node.attr['rel_path'][:-3], has_parameters=has_parameters)
Пример #25
0
 def addSiteServices(self, service_names=None):
     service_list = []
     if isinstance(service_names, basestring):
         service_names = service_names.replace(';', ',').split(',')
     if service_names:
         service_finder = lambda cls: is_ServiceHandler(
             cls, service_names=service_names)
     elif service_names == []:
         return
     else:
         service_finder = is_ServiceHandler
     modules = self.site.resource_loader.getResourceList(
         self.site.resources_dirs, 'services/*.py')
     for module_file in modules:
         try:
             module = gnrImport(module_file)
         except ImportError, import_error:
             log.exception("Could not import %s" % module_file)
             log.exception(str(import_error))
         else:
             service_list.extend(inspect.getmembers(module, service_finder))
Пример #26
0
 def __init__(self,filepath=None,autoconvert=False,**kwargs):
     super(ConfigStruct, self).__init__()
     self.setBackRef()
     if not filepath:
         return
     filename,ext = os.path.splitext(filepath)
     if not ext:
         if os.path.exists('%s.xml' %filepath):
             filepath = '%s.xml' %filepath
             ext = '.xml'
         elif os.path.exists('%s.py' %filepath):
             filepath = '%s.py' %filepath
             ext = '.py'
         else:
             return
     if ext=='.py':
         m = gnrImport(filepath, avoidDup=True)
         getattr(m,self.config_method)(self,**kwargs)
     elif ext=='.xml':
         self.fillFrom(filepath)
         if len(self) and autoconvert:
             self.toPython(filepath.replace('.xml','.py'))
     else:
         raise Exception('Wrong extension for filepath')
Пример #27
0
    def get_page_class(self, path=None, pkg=None):
        """add???
        
        :param path: add???. Default value is ``None``
        :param pkg: add???. Default value is ``None``
        :returns: add???
        """
        if pkg == '*':
            module_path = os.path.join(self.site_path, path)
            pkg = self.site.config['packages?default']
        else:
            module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder,
                                       'webpages', path)

        # if module_path in self.page_factories:
        #    return self.page_factories[module_path]
        page_module = gnrImport(module_path, avoidDup=True)
        page_factory = getattr(page_module, 'page_factory', GnrWebPage)
        custom_class = getattr(page_module, 'GnrCustomWebPage')
        py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''),
                                    ',')
        plugin_webpage_classes = self.plugin_webpage_classes(path, pkg=pkg)
        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
        self.page_class_base_mixin(page_class, pkg=pkg)
        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)
        page_class.eagers = getattr(custom_class, 'eagers', {})
        page_class.css_requires = []
        page_class.js_requires = splitAndStrip(
            getattr(custom_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=pkg)
        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
        ])
        page_class.tpldirectories = page_class.resourceDirs + [
            self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')
        ]
        page_class._packageId = pkg
        self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
        self.page_class_custom_mixin(page_class, path, pkg=pkg)
        self.page_factories[module_path] = page_class
        return page_class
Пример #28
0
 def get_page_class(self, path=None, pkg=None, plugin=None,request_args=None,request_kwargs=None):
     """TODO
     
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     if pkg == '*':
         module_path = os.path.join(self.site_path, path)
         pkg = self.site.config['packages?default']
     else:
         if plugin:
             module_path= os.path.join(self.gnrapp.packages[pkg].plugins[plugin].webpages_path, path)
         else:
             module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder, 'webpages', path)
         
     # if module_path in self.page_factories:
     #    return self.page_factories[module_path]
     page_module = gnrImport(module_path, avoidDup=True)
     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(path, 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)
     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', ''), ',')
     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])
     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, path, pkg=mainPkg)
     self.page_factories[module_path] = page_class
     return page_class
Пример #29
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