コード例 #1
0
ファイル: plugins.py プロジェクト: jssuzanne/AnyBlok
    def load_registry(self):
        if self.enabled and self.registryLoaded is False:
            # Load the registry here not in configuration,
            # because the configuration are not load in order of score
            self.registryLoaded = True
            BlokManager.load()
            load_init_function_from_entry_points(unittest=True)
            Configuration.load_config_for_test()
            Configuration.parse_options(self.AnyBlokOptions, ('bloks',))
            db_name = Configuration.get('db_name')
            if not db_name:
                raise Exception("No database defined to run Test")

            registry = RegistryManager.get(db_name)
            if registry:
                installed_bloks = registry.System.Blok.list_by_state(
                    "installed")
                selected_bloks = Configuration.get('selected_bloks')
                if not selected_bloks:
                    selected_bloks = installed_bloks

                unwanted_bloks = Configuration.get('unwanted_bloks')
                if unwanted_bloks is None:
                    unwanted_bloks = []

                self.bloks_path = [BlokManager.getPath(x)
                                   for x in BlokManager.ordered_bloks]

                self.authoried_bloks_test_files = [
                    path for blok in installed_bloks
                    if blok in selected_bloks and blok not in unwanted_bloks
                    for path in [join(BlokManager.getPath(blok), 'tests')]
                    if exists(path)]
                registry.close()  # free the registry to force create it again
コード例 #2
0
ファイル: scripts.py プロジェクト: jssuzanne/AnyBlok
def anyblok_nose():
    """Run nose unit test for the registry
    """
    warnings.simplefilter('default')
    registry = anyblok.start('nose', useseparator=True, unittest=True)

    defaultTest = []
    if registry:
        installed_bloks = registry.System.Blok.list_by_state("installed")
        selected_bloks = return_list(
            Configuration.get('selected_bloks')) or installed_bloks

        unwanted_bloks = return_list(
            Configuration.get('unwanted_bloks')) or []

        defaultTest = []
        for blok in installed_bloks:
            if blok not in selected_bloks or blok in unwanted_bloks:
                continue

            startpath = BlokManager.getPath(blok)
            for root, dirs, _ in walk(startpath):
                if 'tests' in dirs:
                    defaultTest.append(join(root, 'tests'))

        registry.close()  # free the registry to force create it again

    sys.exit(main(defaultTest=defaultTest))
コード例 #3
0
def current_blok():
    filename = inspect.stack()[1][1]
    for blok in BlokManager.ordered_bloks:
        if filename.startswith(BlokManager.getPath(blok)):
            return blok

    raise AnyBlokPyramidException("You are not in a Blok")  # pragma: no cover
コード例 #4
0
def anyblok_nose():
    """Run nose unit test for the registry
    """
    registry = anyblok.start('nose', useseparator=True, unittest=True)

    defaultTest = []
    if registry:
        installed_bloks = registry.System.Blok.list_by_state("installed")
        selected_bloks = return_list(
            Configuration.get('selected_bloks')) or installed_bloks

        unwanted_bloks = return_list(
            Configuration.get('unwanted_bloks')) or []

        defaultTest = []
        for blok in installed_bloks:
            if blok not in selected_bloks or blok in unwanted_bloks:
                continue

            startpath = BlokManager.getPath(blok)
            for root, dirs, _ in walk(startpath):
                if 'tests' in dirs:
                    defaultTest.append(join(root, 'tests'))

        registry.close()  # free the registry to force create it again

    sys.exit(main(defaultTest=defaultTest))
コード例 #5
0
ファイル: scripts.py プロジェクト: jssuzanne/AnyBlok
def run_exit(application, configuration_groups, **kwargs):
    """Run nose unit test for the registry

    :param application: name of the application
    :param configuration_groups: list configuration groupe to load
    :param \**kwargs: ArgumentParser named arguments
    """
    format_configuration(configuration_groups, 'unittest')
    registry = anyblok.start(application,
                             configuration_groups=configuration_groups,
                             useseparator=True, unittest=True, **kwargs)

    defaultTest = []
    if registry:
        installed_bloks = registry.System.Blok.list_by_state("installed")
        selected_bloks = Configuration.get('selected_bloks')
        if not selected_bloks:
            selected_bloks = installed_bloks

        unwanted_bloks = Configuration.get('unwanted_bloks') or []

        defaultTest = [path
                       for blok in installed_bloks
                       if blok in selected_bloks and blok not in unwanted_bloks
                       for path in [join(BlokManager.getPath(blok), 'tests')]
                       if exists(path)]
        registry.close()  # free the registry to force create it again

    sys.exit(main(defaultTest=defaultTest))
コード例 #6
0
    def import_file(self, Importer, model, *file_path, **kwargs):
        """ Import data file

        :param importer_name: Name of the importer (need installation of the
                              Blok which have the importer)
        :param model: Model of the data to import
        :param file_path: relative path of the path in this Blok
        :param kwargs: Option for the importer
        :rtype: return dict of result
        """
        blok_path = BlokManager.getPath(self.name)
        _file = join(blok_path, *file_path)
        logger.info("import %r file: %r", Importer, _file)
        file_to_import = None
        with open(_file, 'rb') as fp:
            file_to_import = fp.read()

        importer = Importer.insert(model=model,
                                   file_to_import=file_to_import,
                                   **kwargs)
        started_at = datetime.now()
        res = importer.run(self.name)
        stoped_at = datetime.now()
        dt = stoped_at - started_at
        logger.info("Create %d entries, Update %d entries (%d.%d sec)",
                    len(res['created_entries']), len(res['updated_entries']),
                    dt.seconds, dt.microseconds)
        if 'error_found' in res and res['error_found']:
            for error in res['error_found']:
                logger.error(error)
        else:
            importer.delete()

        return res
コード例 #7
0
ファイル: furetui.py プロジェクト: AnyBlok/anyblok_furetui
    def export_i18n(cls, blok_name):
        b = BlokManager.get(blok_name)
        bpath = BlokManager.getPath(blok_name)
        po = polib.POFile()
        po.metadata = {
            'Project-Id-Version': b.version,
            'POT-Creation-Date': datetime.now().isoformat(),
            'MIME-Version': '1.0',
            'Content-Type': 'text/plain; charset=utf-8',
            'Content-Transfer-Encoding': '8bit',
        }
        if hasattr(b, 'furetui'):
            templates = Template()
            for template in b.furetui.get('templates', []):
                with open(join(bpath, template), 'r') as fp:
                    templates.load_file(fp, ignore_missing_extend=True)

            templates.export_i18n(po)

        Mapping = cls.anyblok.IO.Mapping
        for mapping in Mapping.query().filter_by(blokname=blok_name):
            obj = Mapping.get(mapping.model, mapping.key)
            if not obj:
                continue

            for context, text in obj.get_i18n_to_export(mapping.key):
                entry = Translation.define(context, text)
                po.append(entry)

        cls.export_i18n_bases(blok_name, po)

        Path(path.join(bpath, 'locale')).mkdir(exist_ok=True)
        po.save(path.join(bpath, 'locale', f'{blok_name}.pot'))
コード例 #8
0
ファイル: __init__.py プロジェクト: AnyBlok/Anyblok_Pyramid
def current_blok():
    filename = inspect.stack()[1][1]
    for blok in BlokManager.ordered_bloks:
        if filename.startswith(BlokManager.getPath(blok)):
            return blok

    raise AnyBlokPyramidException("You are not in a Blok")
コード例 #9
0
 def test_get_client_file(self, webserver, rollback_registry):
     path = Configuration.get('furetui_client_path', '/furet-ui')
     response = webserver.get(path)
     blok_path = BlokManager.getPath('furetui')
     path = join(blok_path, 'static', 'index.html')
     assert response.status_code == 200
     assert response.content_type == 'text/html'
     with open(path, 'rb') as fp:
         assert fp.read() == response.body
コード例 #10
0
ファイル: common.py プロジェクト: jssuzanne/ERPBlok
def get_templates_from(attr):
    tmpl = Template(forclient=True)
    for blok_name in BlokManager.ordered_bloks:
        blok = BlokManager.get(blok_name)
        if hasattr(blok, attr):
            bpath = BlokManager.getPath(blok_name)
            for template in getattr(blok, attr):
                with open(join(bpath, template), 'r') as fp:
                    tmpl.load_file(fp)

    tmpl.compile()
    return tmpl.get_all_template()
コード例 #11
0
ファイル: blok.py プロジェクト: AnyBlok/AnyBlok
    def get_logo(self):
        """fget of ``logo`` return the path in the blok of the logo

        :rtype: absolute path or None if unexiste logo
        """
        blok = BlokManager.get(self.name)
        blok_path = BlokManager.getPath(blok.name)
        file_path = join(blok_path, blok.logo)
        if isfile(file_path):
            return file_path

        return None
コード例 #12
0
    def get_logo(self):
        """fget of ``logo`` return the path in the blok of the logo

        :rtype: absolute path or None if unexiste logo
        """
        blok = BlokManager.get(self.name)
        blok_path = BlokManager.getPath(blok.name)
        file_path = join(blok_path, blok.logo)
        if isfile(file_path):
            return file_path

        return None
コード例 #13
0
ファイル: furetui.py プロジェクト: AnyBlok/anyblok_furetui
    def import_i18n(cls, lang):
        reload_at_change = Configuration.get('pyramid.reload_all', False)
        if Translation.has_lang(lang) and not reload_at_change:
            return

        Blok = cls.anyblok.System.Blok
        for blok in Blok.list_by_state('installed'):
            bpath = BlokManager.getPath(blok)
            if path.exists(path.join(bpath, 'locale', f'{lang}.po')):
                po = polib.pofile(path.join(bpath, 'locale', f'{lang}.po'))
                for entry in po:
                    Translation.set(lang, entry)
コード例 #14
0
 def pyramid_load_config(cls, config):
     json_data_adapter(config)
     blok_name, static_path = Configuration.get(
         'furetui_client_static', 'furetui:static/furet-ui').split(':')
     blok_path = BlokManager.getPath(blok_name)
     path = join(blok_path, *static_path.split('/'))
     config.add_static_view('furet-ui/js', join(path, 'js'))
     config.add_static_view('furet-ui/css', join(path, 'css'))
     config.add_static_view('/js', join(path, 'js'))
     config.add_static_view('/css', join(path, 'css'))
     config.add_static_view('/images', join(path, 'images'))
     config.scan(cls.__module__ + '.views')
コード例 #15
0
ファイル: __init__.py プロジェクト: ERPBlok/ERPBlok
    def load(self):
        from os.path import join
        tmpl = Template()
        Blok = self.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'views'):
                bpath = BlokManager.getPath(blok)
                for template in b.views:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        self.registry.erpblok_views = tmpl
コード例 #16
0
    def load(self):
        from os.path import join
        tmpl = Template()
        Blok = self.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'views'):
                bpath = BlokManager.getPath(blok)
                for template in b.views:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        self.registry.furetui_views = tmpl
コード例 #17
0
ファイル: plugins.py プロジェクト: gracinet/AnyBlok
    def load_registry(self):
        if self.enabled and self.registryLoaded is False:
            # Load the registry here not in configuration,
            # because the configuration are not load in order of score
            self.registryLoaded = True
            load_init_function_from_entry_points(unittest=True)
            Configuration.load_config_for_test()
            Configuration.parse_options(self.AnyBlokOptions)
            configuration_post_load()
            BlokManager.load()
            db_name = get_db_name()

            registry = RegistryManager.get(db_name)
            if registry:
                installed_bloks = registry.System.Blok.list_by_state(
                    "installed")
                selected_bloks = return_list(
                    Configuration.get('selected_bloks')) or installed_bloks

                unwanted_bloks = return_list(
                    Configuration.get('unwanted_bloks')) or []

                self.bloks_path = [BlokManager.getPath(x)
                                   for x in BlokManager.ordered_bloks]

                self.authoried_bloks_test_files = []
                for blok in installed_bloks:
                    if blok not in selected_bloks or blok in unwanted_bloks:
                        continue

                    startpath = BlokManager.getPath(blok)
                    for root, dirs, _ in walk(startpath):
                        if 'tests' in dirs:
                            self.authoried_bloks_test_files.append(
                                join(root, 'tests'))

                registry.close()  # free the registry to force create it again
コード例 #18
0
    def get_logo(self):
        """ Return the logo define in blok description

        ::

            class MyBlok(Blok):
                logo = 'path/to/the/logo/in/blok'

        """
        file_path = super(Blok, self).get_logo()
        if not file_path:
            file_path = join(BlokManager.getPath('blok_manager'),
                             'static/image/none.png')

        return self.registry.Web.Image.filepath2html(file_path)
コード例 #19
0
ファイル: __init__.py プロジェクト: ERPBlok/ERPBlok
    def get_templates(cls):
        """ Return the list of the web client template to load """
        from os.path import join
        tmpl = Template(forclient=True)
        Blok = cls.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'client_templates'):
                bpath = BlokManager.getPath(blok)
                for template in b.client_templates:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        return tmpl.get_all_template()
コード例 #20
0
ファイル: common.py プロジェクト: petrus-v/anyblok_attachment
def format_path(path):
    """Return the absolute path in function of the blok

    :param path: the path to format
    :return: the absolute path
    :exception: PathException
    """
    if '#=#' in path:
        blokname, path = path.split('#=#')
        path = os.path.join(BlokManager.getPath(blokname), path)

    if not os.path.exists(path):
        raise PathException("%s does not exists", path)

    return path
コード例 #21
0
ファイル: blok.py プロジェクト: AnyBlok/AnyBlok
    def get_long_description(self):
        """ fget of the ``long_description`` Column.Selection

        :rtype: the readme file of the blok
        """
        blok = BlokManager.get(self.name)
        path = BlokManager.getPath(self.name)
        readme = getattr(blok, 'readme', 'README.rst')
        if readme == '__doc__':
            return blok.__doc__

        file_path = join(path, readme)
        description = ''
        if isfile(file_path):
            with open(file_path, 'r') as fp:
                description = fp.read()

        return description
コード例 #22
0
    def get_long_description(self):
        """ fget of the ``long_description`` Column.Selection

        :rtype: the readme file of the blok
        """
        blok = BlokManager.get(self.name)
        path = BlokManager.getPath(self.name)
        readme = getattr(blok, 'readme', 'README.rst')
        if readme == '__doc__':
            return blok.__doc__

        file_path = join(path, readme)
        description = ''
        if isfile(file_path):
            with open(file_path, 'r') as fp:
                description = fp.read()

        return description
コード例 #23
0
def static_paths(config):
    """Pyramid includeme, add the static path of the blok

    :param config: Pyramid configurator instance
    """

    for blok, cls in BlokManager.bloks.items():
        if hasattr(cls, 'static_paths'):
            paths = cls.static_paths
            if isinstance(paths, str):
                paths = [paths]
        else:
            paths = ['static']

        blok_path = BlokManager.getPath(blok)

        for p in paths:
            config.add_static_view(join(blok, p), join(blok_path, p))
コード例 #24
0
def static_paths(config):
    """Pyramid includeme, add the static path of the blok

    :param config: Pyramid configurator instance
    """

    for blok, cls in BlokManager.bloks.items():
        if hasattr(cls, 'static_paths'):
            paths = cls.static_paths
            if isinstance(paths, str):
                paths = [paths]
        else:
            paths = ['static']

        blok_path = BlokManager.getPath(blok)

        for p in paths:
            config.add_static_view(join(blok, p), join(blok_path, p))
コード例 #25
0
ファイル: plugins.py プロジェクト: zakibelm/AnyBlok
    def load_registry(self):
        if not self.enabled or self.registryLoaded:
            return

        from anyblok.config import Configuration, get_db_name
        from anyblok import (
            load_init_function_from_entry_points,
            configuration_post_load,
        )
        from anyblok.blok import BlokManager
        from anyblok.registry import RegistryManager, return_list

        # Load the registry here not in configuration,
        # because the configurations are not loaded in order of score
        self.registryLoaded = True
        load_init_function_from_entry_points(unittest=True)
        Configuration.load_config_for_test()
        Configuration.parse_options(self.AnyBlokOptions)
        configuration_post_load()
        BlokManager.load()
        db_name = get_db_name()

        registry = RegistryManager.get(db_name)
        if not registry:
            return

        installed_bloks = registry.System.Blok.list_by_state("installed")
        selected_bloks = return_list(
            Configuration.get('selected_bloks')) or installed_bloks

        unwanted_bloks = return_list(Configuration.get('unwanted_bloks')) or []

        self.authorized_blok_paths = set(
            BlokManager.getPath(b) for b in BlokManager.list()
            if b in selected_bloks and b not in unwanted_bloks)

        test_dirs = self.authorized_blok_test_dirs = set()
        for startpath in self.authorized_blok_paths:
            for root, dirs, _ in walk(startpath):
                if 'tests' in dirs:
                    test_dirs.add(join(root, 'tests'))

        registry.close()  # free the registry to force create it again
コード例 #26
0
def static_paths(config):
    """Pyramid includeme, add the static path of the blok

    :param config: Pyramid configurator instance
    """

    for blok, cls in BlokManager.bloks.items():
        if hasattr(cls, 'static_paths'):  # pragma: no cover
            paths = cls.static_paths
            if isinstance(paths, str):
                paths = [paths]
        else:
            paths = ['static']

        blok_path = BlokManager.getPath(blok)
        cache_max_age = Configuration.get('pyramid_cache_max_age', 3600)
        for p in paths:
            config.add_static_view(join(blok, p),
                                   join(blok_path, p),
                                   cache_max_age=cache_max_age)
コード例 #27
0
def get_static_file(request):
    blok_name = request.matchdict['blok_name']
    file_path = request.matchdict['file_path']
    blok_path = BlokManager.getPath(blok_name)
    path = join(blok_path, file_path)
    content_type = 'text/html'
    if request.matchdict['filetype'] == 'js':
        content_type = 'application/javascript'
        if eval(Configuration.get('furetui_debug', 'False'), {}, {}) is True:
            parser = MyPyJsParser()
            with open(path, 'r') as fp:
                content = fp.read()
                parser.parse(blok_name, file_path, content)

    elif request.matchdict['filetype'] == 'css':
        content_type = 'text/css'

    response = FileResponse(path, request=request, content_type=content_type)
    response.headerlist.append(('Access-Control-Allow-Origin', '*'))
    return response
コード例 #28
0
ファイル: scripts.py プロジェクト: AnyBlok/AnyBlok
def anyblok_nose():
    """Run nose unit test after giving it the registry
    """
    warnings.simplefilter('default')
    warnings.warn(
        "This script is deprecated and will be removed soon. "
        "The Nose test machinery has been removed from the framework in order "
        "to be replaced with Pytest. "
        "If you need to run your tests with nose, install the Nose package.",
        DeprecationWarning, stacklevel=2)

    try:
        from nose import main
    except ImportError:
        logger.error('"Nosetest" is not installed, try: pip install nose')

    anyblok_registry = anyblok.start('nose', useseparator=True, unittest=True)

    if anyblok_registry:
        installed_bloks = anyblok_registry.System.Blok.list_by_state(
            "installed")
        selected_bloks = return_list(
            Configuration.get('selected_bloks')) or installed_bloks

        unwanted_bloks = return_list(
            Configuration.get('unwanted_bloks')) or []
        unwanted_bloks.extend(['anyblok-core', 'anyblok-test', 'model_authz'])

        defaultTest = []
        for blok in installed_bloks:
            if blok not in selected_bloks or blok in unwanted_bloks:
                continue

            startpath = BlokManager.getPath(blok)
            for root, dirs, _ in walk(startpath):
                if 'tests' in dirs:
                    defaultTest.append(join(root, 'tests'))

        anyblok_registry.close()  # free the registry to force create it again

    sys.exit(main(defaultTest=defaultTest))
コード例 #29
0
ファイル: furetui.py プロジェクト: AnyBlok/anyblok_furetui
    def pre_load(cls, lang='en'):
        logger.info('Preload furet UI component')
        templates = Template()
        i18n = {}
        Blok = cls.anyblok.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            bpath = BlokManager.getPath(blok)
            if hasattr(b, 'furetui'):
                for template in b.furetui.get('templates', []):
                    with open(join(bpath, template), 'r') as fp:
                        templates.load_file(fp)

                for local, translations in b.furetui.get('i18n', {}).items():
                    node = i18n.setdefault(local, {})
                    update_translation(node, translations)

        cls.import_i18n(lang)
        templates.compile(lang=lang)
        cls.anyblok.furetui_templates = templates
        cls.anyblok.furetui_i18n = i18n
コード例 #30
0
    def pre_load(cls):
        logger.info('Preload furet UI component')
        tmpl_views = Template()
        tmpl_components = Template()
        js = []
        css = []
        i18n = {}
        Blok = cls.registry.System.Blok
        timestamp = datetime.utcnow().timestamp()
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            bpath = BlokManager.getPath(blok)
            if hasattr(b, 'furetui'):
                for template in b.furetui.get('templates', []):
                    with open(join(bpath, template), 'r') as fp:
                        tmpl_components.load_file(fp)

                js.extend([
                    '%s?%s' %
                    (join('furet-ui', blok, 'js', filename), timestamp)
                    for filename in b.furetui.get('js', [])
                ])
                css.extend([
                    join('furet-ui', blok, 'css', filename)
                    for filename in b.furetui.get('css', [])
                ])

                for local, translations in b.furetui.get('i18n', {}).items():
                    node = i18n.setdefault(local, {})
                    update_translation(node, translations)

        tmpl_views.compile()
        cls.registry.furetui_views = tmpl_views
        tmpl_components.compile()
        cls.registry.furetui_components = tmpl_components
        cls.registry.furetui_js = js
        cls.registry.furetui_css = css
        cls.registry.furetui_i18n = i18n
コード例 #31
0
 def get_absolute_path(self):
     return os.path.join(BlokManager.getPath('report'), 'tests',
                         'test_common.py')
コード例 #32
0
ファイル: __init__.py プロジェクト: petrus-v/anyblok_furetui
 def pyramid_load_config(cls, config):
     blok_path = BlokManager.getPath('furetui')
     path = join(blok_path, 'static', 'furet-ui')
     config.add_static_view('furet-ui/js', join(path, 'js'))
     config.add_static_view('furet-ui/css', join(path, 'css'))
     config.scan(cls.__module__ + '.views')
コード例 #33
0
def get_client_file(request):
    print('get_client_file', request.query_string)
    blok_path = BlokManager.getPath('furetui')
    path = join(blok_path, 'static', 'index.html')
    return FileResponse(path, request=request, content_type='text/html')