コード例 #1
0
    def test_populate_horizon_config_consistent_result(self):
        fd.walk = another_fake_walk
        horizon_config = {}

        fd.populate_horizon_config(horizon_config, base_path)
        sources = horizon_config['js_files']
        test_files = horizon_config['js_spec_files']
        templates = horizon_config['external_templates']

        self.assertEqual(len(sources), 6)
        self.assertEqual(len(test_files), 8)
        self.assertEqual(len(templates), 2)

        self.assertTrue(sources[0].endswith('a.module.js'))
        self.assertTrue(sources[1].endswith('b.module.js'))

        self.assertTrue(sources[2].endswith('a.controller.js'))
        self.assertTrue(sources[3].endswith('a.directive.js'))
        self.assertTrue(sources[4].endswith('b.controller.js'))
        self.assertTrue(sources[5].endswith('b.directive.js'))

        self.assertTrue(test_files[0].endswith('.mock.js'))
        self.assertTrue(test_files[1].endswith('.mock.js'))

        self.assertTrue(test_files[2].endswith('.spec.js'))
        self.assertTrue(test_files[3].endswith('.spec.js'))
        self.assertTrue(test_files[4].endswith('.spec.js'))
        self.assertTrue(test_files[5].endswith('.spec.js'))
        self.assertTrue(test_files[6].endswith('.spec.js'))
        self.assertTrue(test_files[7].endswith('.spec.js'))

        self.assertTrue(templates[0].endswith('.html'))
        self.assertTrue(templates[1].endswith('.html'))
コード例 #2
0
    def test_populate_horizon_config_consistent_result(self):
        fd.walk = another_fake_walk
        horizon_config = {}

        fd.populate_horizon_config(horizon_config, base_path)
        sources = horizon_config['js_files']
        test_files = horizon_config['js_spec_files']
        templates = horizon_config['external_templates']

        self.assertEqual(len(sources), 6)
        self.assertEqual(len(test_files), 8)
        self.assertEqual(len(templates), 2)

        self.assertTrue(sources[0].endswith('a.module.js'))
        self.assertTrue(sources[1].endswith('b.module.js'))

        self.assertTrue(sources[2].endswith('a.controller.js'))
        self.assertTrue(sources[3].endswith('a.directive.js'))
        self.assertTrue(sources[4].endswith('b.controller.js'))
        self.assertTrue(sources[5].endswith('b.directive.js'))

        self.assertTrue(test_files[0].endswith('.mock.js'))
        self.assertTrue(test_files[1].endswith('.mock.js'))

        self.assertTrue(test_files[2].endswith('.spec.js'))
        self.assertTrue(test_files[3].endswith('.spec.js'))
        self.assertTrue(test_files[4].endswith('.spec.js'))
        self.assertTrue(test_files[5].endswith('.spec.js'))
        self.assertTrue(test_files[6].endswith('.spec.js'))
        self.assertTrue(test_files[7].endswith('.spec.js'))

        self.assertTrue(templates[0].endswith('.html'))
        self.assertTrue(templates[1].endswith('.html'))
コード例 #3
0
ファイル: static_settings.py プロジェクト: Bibibi888/horizon
def find_static_files(ROOT_PATH, HORIZON_CONFIG):
    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(ROOT_PATH, '..', 'horizon', 'static/')
    )

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                                   if not f.startswith('horizon/')])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(ROOT_PATH, 'static/'),
        sub_path='app/'
    )
コード例 #4
0
def find_static_files(ROOT_PATH, HORIZON_CONFIG):
    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(ROOT_PATH, '..', 'horizon', 'static/')
    )

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                                   if not f.startswith('horizon/')])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(ROOT_PATH, 'static/'),
        sub_path='app/'
    )
コード例 #5
0
def find_static_files(HORIZON_CONFIG):
    import model_manager
    import horizon
    model_manager_home_dir = model_manager.__path__[0]
    horizon_home_dir = horizon.__path__[0]

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG, os.path.join(horizon_home_dir, 'static/'))

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([
        f for f in HORIZON_CONFIG['js_files'] if not f.startswith('horizon/')
    ])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(HORIZON_CONFIG,
                                           os.path.join(
                                               model_manager_home_dir,
                                               'static/'),
                                           sub_path='app/')
コード例 #6
0
ファイル: static_settings.py プロジェクト: 28607895/horizon
def find_static_files(HORIZON_CONFIG):
    import horizon
    import openstack_dashboard
    os_dashboard_home_dir = openstack_dashboard.__path__[0]
    horizon_home_dir = horizon.__path__[0]

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(horizon_home_dir, 'static/')
    )

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                                   if not f.startswith('horizon/')])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(os_dashboard_home_dir, 'static/'),
        sub_path='app/'
    )
コード例 #7
0
ファイル: settings.py プロジェクト: Tesora/tesora-horizon
def update_dashboards(modules, horizon_config, installed_apps):
    """Imports dashboard and panel configuration from modules and applies it.

    The submodules from specified modules are imported, and the configuration
    for the specific dashboards is merged, with the later modules overriding
    settings from the former. Then the configuration is applied to
    horizon_config and installed_apps, in alphabetical order of files from
    which the configurations were imported.

    For example, given this setup:

        | foo/__init__.py
        | foo/_10_baz.py
        | foo/_20_qux.py

        | bar/__init__.py
        | bar/_30_baz_.py

    and being called with ``modules=[foo, bar]``, we will first have the
    configuration from ``_10_baz`` and ``_30_baz`` merged, then the
    configurations will be applied in order ``qux``, ``baz`` (``baz`` is
    second, because the most recent file which contributed to it, ``_30_baz``,
    comes after ``_20_qux``).

    Panel specific configurations are stored in horizon_config. Dashboards
    from both plugin-based and openstack_dashboard must be registered before
    the panel configuration can be applied. Making changes to the panel is
    deferred until the horizon autodiscover is completed, configurations are
    applied in alphabetical order of files where it was imported.
    """
    config_dashboards = horizon_config.get('dashboards', [])
    if config_dashboards or horizon_config.get('default_dashboard'):
        logging.warning(
            '"dashboards" and "default_dashboard" in (local_)settings is '
            'DEPRECATED now and may be unsupported in some future release. '
            'The preferred way to specify the order of dashboards and the '
            'default dashboard is the pluggable dashboard mechanism (in %s).',
            ', '.join([os.path.abspath(module.__path__[0])
                       for module in modules])
        )

    enabled_dashboards = []
    disabled_dashboards = []
    exceptions = horizon_config.get('exceptions', {})
    apps = []
    angular_modules = []
    js_files = []
    js_spec_files = []
    scss_files = []
    panel_customization = []
    update_horizon_config = {}
    for key, config in import_dashboard_config(modules):
        if config.get('DISABLED', False):
            if config.get('DASHBOARD'):
                disabled_dashboards.append(config.get('DASHBOARD'))
            continue

        _apps = config.get('ADD_INSTALLED_APPS', [])
        apps.extend(_apps)

        if config.get('AUTO_DISCOVER_STATIC_FILES', False):
            for _app in _apps:
                module = importlib.import_module(_app)
                base_path = os.path.join(module.__path__[0], 'static/')
                fd.populate_horizon_config(horizon_config, base_path)

        add_exceptions = six.iteritems(config.get('ADD_EXCEPTIONS', {}))
        for category, exc_list in add_exceptions:
            exceptions[category] = tuple(set(exceptions.get(category, ())
                                             + exc_list))

        angular_modules.extend(config.get('ADD_ANGULAR_MODULES', []))
        # avoid pulling in dashboard javascript dependencies multiple times
        existing = set(js_files)
        js_files.extend([f for f in config.get('ADD_JS_FILES', [])
                         if f not in existing])
        js_spec_files.extend(config.get('ADD_JS_SPEC_FILES', []))
        scss_files.extend(config.get('ADD_SCSS_FILES', []))
        update_horizon_config.update(
            config.get('UPDATE_HORIZON_CONFIG', {}))
        if config.get('DASHBOARD'):
            dashboard = key
            enabled_dashboards.append(dashboard)
            if config.get('DEFAULT', False):
                horizon_config['default_dashboard'] = dashboard
        elif config.get('PANEL') or config.get('PANEL_GROUP'):
            config.pop("__builtins__", None)
            panel_customization.append(config)
    # Preserve the dashboard order specified in settings
    dashboards = ([d for d in config_dashboards
                   if d not in disabled_dashboards] +
                  [d for d in enabled_dashboards
                   if d not in config_dashboards])

    horizon_config['panel_customization'] = panel_customization
    horizon_config['dashboards'] = tuple(dashboards)
    horizon_config.setdefault('exceptions', {}).update(exceptions)
    horizon_config.update(update_horizon_config)
    horizon_config.setdefault('angular_modules', []).extend(angular_modules)
    horizon_config.setdefault('js_files', []).extend(js_files)
    horizon_config.setdefault('js_spec_files', []).extend(js_spec_files)
    horizon_config.setdefault('scss_files', []).extend(scss_files)
    installed_apps[0:0] = apps
コード例 #8
0
def update_dashboards(modules, horizon_config, installed_apps):
    """Imports dashboard and panel configuration from modules and applies it.

    The submodules from specified modules are imported, and the configuration
    for the specific dashboards is merged, with the later modules overriding
    settings from the former. Then the configuration is applied to
    horizon_config and installed_apps, in alphabetical order of files from
    which the configurations were imported.

    For example, given this setup:

        | foo/__init__.py
        | foo/_10_baz.py
        | foo/_20_qux.py

        | bar/__init__.py
        | bar/_30_baz_.py

    and being called with ``modules=[foo, bar]``, we will first have the
    configuration from ``_10_baz`` and ``_30_baz`` merged, then the
    configurations will be applied in order ``qux``, ``baz`` (``baz`` is
    second, because the most recent file which contributed to it, ``_30_baz``,
    comes after ``_20_qux``).

    Panel specific configurations are stored in horizon_config. Dashboards
    from both plugin-based and openstack_dashboard must be registered before
    the panel configuration can be applied. Making changes to the panel is
    deferred until the horizon autodiscover is completed, configurations are
    applied in alphabetical order of files where it was imported.
    """
    config_dashboards = horizon_config.get('dashboards', [])
    if config_dashboards or horizon_config.get('default_dashboard'):
        logging.warning(
            '"dashboards" and "default_dashboard" in (local_)settings is '
            'DEPRECATED now and may be unsupported in some future release. '
            'The preferred way to specify the order of dashboards and the '
            'default dashboard is the pluggable dashboard mechanism (in %s).',
            ', '.join(
                [os.path.abspath(module.__path__[0]) for module in modules]))

    enabled_dashboards = []
    disabled_dashboards = []
    exceptions = horizon_config.get('exceptions', {})
    apps = []
    angular_modules = []
    js_files = []
    js_spec_files = []
    scss_files = []
    panel_customization = []
    update_horizon_config = {}
    for key, config in import_dashboard_config(modules):
        if config.get('DISABLED', False):
            if config.get('DASHBOARD'):
                disabled_dashboards.append(config.get('DASHBOARD'))
            continue

        _apps = config.get('ADD_INSTALLED_APPS', [])
        apps.extend(_apps)

        if config.get('AUTO_DISCOVER_STATIC_FILES', False):
            for _app in _apps:
                module = import_module(_app)
                base_path = os.path.join(module.__path__[0], 'static/')
                file_discovery.populate_horizon_config(horizon_config,
                                                       base_path)

        add_exceptions = config.get('ADD_EXCEPTIONS', {}).items()
        for category, exc_list in add_exceptions:
            exceptions[category] = tuple(
                set(exceptions.get(category, ()) + exc_list))

        angular_modules.extend(config.get('ADD_ANGULAR_MODULES', []))
        # avoid pulling in dashboard javascript dependencies multiple times
        existing = set(js_files)
        js_files.extend(
            [f for f in config.get('ADD_JS_FILES', []) if f not in existing])
        js_spec_files.extend(config.get('ADD_JS_SPEC_FILES', []))
        scss_files.extend(config.get('ADD_SCSS_FILES', []))
        update_horizon_config.update(config.get('UPDATE_HORIZON_CONFIG', {}))
        if config.get('DASHBOARD'):
            dashboard = key
            enabled_dashboards.append(dashboard)
            if config.get('DEFAULT', False):
                horizon_config['default_dashboard'] = dashboard
        elif config.get('PANEL') or config.get('PANEL_GROUP'):
            config.pop("__builtins__", None)
            panel_customization.append(config)
    # Preserve the dashboard order specified in settings
    dashboards = (
        [d for d in config_dashboards if d not in disabled_dashboards] +
        [d for d in enabled_dashboards if d not in config_dashboards])

    horizon_config['panel_customization'] = panel_customization
    horizon_config['dashboards'] = tuple(dashboards)
    horizon_config.setdefault('exceptions', {}).update(exceptions)
    horizon_config.update(update_horizon_config)
    horizon_config.setdefault('angular_modules', []).extend(angular_modules)
    horizon_config.setdefault('js_files', []).extend(js_files)
    horizon_config.setdefault('js_spec_files', []).extend(js_spec_files)
    horizon_config.setdefault('scss_files', []).extend(scss_files)

    # apps contains reference to applications declared in the enabled folder
    # basically a list of applications that are internal and external plugins
    # installed_apps contains reference to applications declared in settings
    # such as django.contribe.*, django_pyscss, compressor, horizon, etc...
    # for translation, we are only interested in the list of external plugins
    # so we save the reference to it before we append to installed_apps
    horizon_config.setdefault('plugins', []).extend(apps)
    installed_apps[0:0] = apps
コード例 #9
0
def find_static_files(HORIZON_CONFIG, AVAILABLE_THEMES, THEME_COLLECTION_DIR,
                      ROOT_PATH):
    import horizon
    import openstack_dashboard

    os_dashboard_home_dir = openstack_dashboard.__path__[0]
    horizon_home_dir = horizon.__path__[0]

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG, os.path.join(horizon_home_dir, 'static/'))

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([
        f for f in HORIZON_CONFIG['js_files'] if not f.startswith('horizon/')
    ])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(HORIZON_CONFIG,
                                           os.path.join(
                                               os_dashboard_home_dir,
                                               'static/'),
                                           sub_path='app/')

    # Discover theme static resources, and in particular any
    # static HTML (client-side) that the theme overrides
    theme_static_files = {}
    theme_info = theme_settings.get_theme_static_dirs(AVAILABLE_THEMES,
                                                      THEME_COLLECTION_DIR,
                                                      ROOT_PATH)

    for url, path in theme_info:
        discovered_files = {}

        # discover static files provided by the theme
        file_discovery.populate_horizon_config(discovered_files, path)

        # Get the theme name from the theme url
        theme_name = url.split('/')[-1]

        # build a dictionary of this theme's static HTML templates.
        # For each overridden template, strip off the '/templates/' part of the
        # theme filename then use that name as the key, and the location in the
        # theme directory as the value. This allows the quick lookup of
        # theme path for any file overridden by a theme template
        template_overrides = {}
        for theme_file in discovered_files['external_templates']:
            # Example:
            #   external_templates_dict[
            #       'framework/widgets/help-panel/help-panel.html'
            #   ] = 'themes/material/templates/framework/widgets/\
            #        help-panel/help-panel.html'
            (templates_part, override_path) = theme_file.split('/templates/')
            template_overrides[override_path] = 'themes/' + \
                                                theme_name + theme_file

        discovered_files['template_overrides'] = template_overrides

        # Save all of the discovered file info for this theme in our
        # 'theme_files' object using the theme name as the key
        theme_static_files[theme_name] = discovered_files

    # Add the theme file info to the horizon config for use by template tags
    HORIZON_CONFIG['theme_static_files'] = theme_static_files
コード例 #10
0
ファイル: settings.py プロジェクト: amotoki/horizon
def find_static_files(
        HORIZON_CONFIG,
        AVAILABLE_THEMES,
        THEME_COLLECTION_DIR,
        ROOT_PATH):
    import horizon
    import openstack_dashboard

    os_dashboard_home_dir = openstack_dashboard.__path__[0]
    horizon_home_dir = horizon.__path__[0]

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(horizon_home_dir, 'static/')
    )

    # filter out non-angular javascript code and lib
    HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                                   if not f.startswith('horizon/')])

    # note the path must end in a '/' or the resultant file paths will have a
    # leading "/"
    file_discovery.populate_horizon_config(
        HORIZON_CONFIG,
        os.path.join(os_dashboard_home_dir, 'static/'),
        sub_path='app/'
    )

    # Discover theme static resources, and in particular any
    # static HTML (client-side) that the theme overrides
    theme_static_files = {}
    theme_info = theme_settings.get_theme_static_dirs(
        AVAILABLE_THEMES,
        THEME_COLLECTION_DIR,
        ROOT_PATH)

    for url, path in theme_info:
        discovered_files = {}

        # discover static files provided by the theme
        file_discovery.populate_horizon_config(
            discovered_files,
            path
        )

        # Get the theme name from the theme url
        theme_name = url.split('/')[-1]

        # build a dictionary of this theme's static HTML templates.
        # For each overridden template, strip off the '/templates/' part of the
        # theme filename then use that name as the key, and the location in the
        # theme directory as the value. This allows the quick lookup of
        # theme path for any file overridden by a theme template
        template_overrides = {}
        for theme_file in discovered_files['external_templates']:
            # Example:
            #   external_templates_dict[
            #       'framework/widgets/help-panel/help-panel.html'
            #   ] = 'themes/material/templates/framework/widgets/\
            #        help-panel/help-panel.html'
            (templates_part, override_path) = theme_file.split('/templates/')
            template_overrides[override_path] = 'themes/' + \
                                                theme_name + theme_file

        discovered_files['template_overrides'] = template_overrides

        # Save all of the discovered file info for this theme in our
        # 'theme_files' object using the theme name as the key
        theme_static_files[theme_name] = discovered_files

    # Add the theme file info to the horizon config for use by template tags
    HORIZON_CONFIG['theme_static_files'] = theme_static_files
コード例 #11
0
ファイル: settings.py プロジェクト: bogdanr/horizon
# statically
if os.path.exists(os.path.join(CUSTOM_THEME, 'static')):
    CUSTOM_THEME = os.path.join(CUSTOM_THEME, 'static')

STATICFILES_DIRS.append(
    ('custom', CUSTOM_THEME),
)

# populate HORIZON_CONFIG with auto-discovered JavaScript sources, mock files,
# specs files and external templates.
from horizon.utils import file_discovery as fd

# note the path must end in a '/' or the resultant file paths will have a
# leading "/"
fd.populate_horizon_config(
    HORIZON_CONFIG,
    os.path.join(ROOT_PATH, '..', 'horizon', 'static/')
)

# filter out non-angular javascript code and lib
HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                               if not f.startswith('horizon/')])

# note the path must end in a '/' or the resultant file paths will have a
# leading "/"
fd.populate_horizon_config(
    HORIZON_CONFIG,
    os.path.join(ROOT_PATH, 'static/'),
    sub_path='openstack-service-api/'
)
fd.populate_horizon_config(
    HORIZON_CONFIG,
コード例 #12
0
def find_static_files():
    for (module_name, sub_paths) in js_file_paths:
        file_discovery.populate_horizon_config(
            settings.HORIZON_CONFIG, os.path.join(get_module_path(module_name), "static/"), sub_path=sub_paths
        )
コード例 #13
0
STATIC_URL = WEBROOT + 'static/'
STATICFILES_DIRS = get_staticfiles_dirs(WEBROOT)

CUSTOM_THEME = os.path.join(ROOT_PATH, CUSTOM_THEME_PATH)
STATICFILES_DIRS.append(
    ('custom', CUSTOM_THEME),
)

# populate HORIZON_CONFIG with auto-discovered JavaScript sources, mock files,
# specs files and external templates.
from horizon.utils import file_discovery as fd

# note the path must end in a '/' or the resultant file paths will have a
# leading "/"
fd.populate_horizon_config(
    HORIZON_CONFIG,
    os.path.join(ROOT_PATH, '..', 'horizon', 'static/')
)

# filter out non-angular javascript code and lib
HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
                               if not f.startswith('horizon/')])

# note the path must end in a '/' or the resultant file paths will have a
# leading "/"
fd.populate_horizon_config(
    HORIZON_CONFIG,
    os.path.join(ROOT_PATH, 'static/'),
    sub_path='openstack-service-api/'
)
fd.populate_horizon_config(
    HORIZON_CONFIG,