Beispiel #1
0
    def parse_arguments(*args, **options):  # pylint: disable=unused-argument
        """
        Parse and validate arguments for update_assets command.

        Args:
            *args: Positional arguments passed to the update_assets command
            **options: optional arguments passed to the update_assets command
        Returns:
            A tuple containing parsed values for themes, system, source comments and output style.
            1. themes (list): list of Theme objects
            2. system (bool): True if system sass need to be compiled, False otherwise
            3. source_comments (bool): True if source comments need to be included in output, False otherwise
            4. output_style (str): Coding style for compiled css files.
        """
        given_themes = options.get("themes", ["all"])
        output_style = options.get("output_style", "nested")
        system = options.get("system", True)
        source_comments = options.get("source_comments", False)
        collect = options.get("collect", True)

        available_themes = {t.theme_dir: t for t in get_themes()}

        if 'no' in given_themes or 'all' in given_themes:
            # Raise error if 'all' or 'no' is present and theme names are also given.
            if len(given_themes) > 1:
                raise CommandError(
                    "Invalid themes value, It must either be 'all' or 'no' or list of themes."
                )
        # Raise error if any of the given theme name is invalid
        # (theme name would be invalid if it does not exist in themes directory)
        elif (not set(given_themes).issubset(available_themes.keys())
              ) and is_comprehensive_theming_enabled():
            raise CommandError(
                "Given themes '{invalid_themes}' do not exist inside themes directory '{themes_dir}'"
                .format(
                    invalid_themes=", ".join(
                        set(given_themes) - set(available_themes.keys())),
                    themes_dir=get_base_themes_dir(),
                ), )

        if "all" in given_themes:
            themes = get_themes()
        elif "no" in given_themes:
            themes = []
        else:
            # convert theme names to Theme objects
            themes = [available_themes.get(theme) for theme in given_themes]

        return themes, system, source_comments, output_style, collect
    def test_parse_arguments(self):
        """
        Test parse arguments method for update_asset command.
        """
        # make sure update_assets picks all themes when called with 'themes=all' option
        parsed_args = Command.parse_arguments(themes=["all"])
        self.assertEqual(parsed_args[0], get_themes())

        # make sure update_assets picks no themes when called with 'themes=no' option
        parsed_args = Command.parse_arguments(themes=["no"])
        self.assertEqual(parsed_args[0], [])

        # make sure update_assets picks only specified themes
        parsed_args = Command.parse_arguments(themes=["test-theme"])
        self.assertEqual(parsed_args[0], [theme for theme in get_themes() if theme.theme_dir_name == "test-theme"])
    def test_parse_arguments(self):
        """
        Test parse arguments method for update_asset command.
        """
        # make sure update_assets picks all themes when called with 'themes=all' option
        parsed_args = Command.parse_arguments(themes=["all"])
        self.assertEqual(parsed_args[0], get_themes())

        # make sure update_assets picks no themes when called with 'themes=no' option
        parsed_args = Command.parse_arguments(themes=["no"])
        self.assertEqual(parsed_args[0], [])

        # make sure update_assets picks only specified themes
        parsed_args = Command.parse_arguments(themes=["test-theme"])
        self.assertEqual(parsed_args[0], [theme for theme in get_themes() if theme.theme_dir == "test-theme"])
Beispiel #4
0
 def test_get_themes_with_theming_disabled(self):
     """
     Tests get_themes returns empty list when theming is disabled.
     """
     with override_settings(ENABLE_COMPREHENSIVE_THEMING=False):
         actual_themes = get_themes()
         self.assertItemsEqual([], actual_themes)
Beispiel #5
0
 def test_get_themes_with_theming_disabled(self):
     """
     Tests get_themes returns empty list when theming is disabled.
     """
     with override_settings(ENABLE_COMPREHENSIVE_THEMING=False):
         actual_themes = get_themes()
         self.assertItemsEqual([], actual_themes)
Beispiel #6
0
def enable_theming():
    """
        Add directories and relevant paths to settings for comprehensive theming.
    """
    for theme in get_themes():
        locale_dir = theme.path / "conf" / "locale"
        if locale_dir.isdir():
            settings.LOCALE_PATHS = (locale_dir, ) + settings.LOCALE_PATHS
Beispiel #7
0
def enable_theming():
    """
        Add directories and relevant paths to settings for comprehensive theming.
    """
    for theme in get_themes():
        locale_dir = theme.path / "conf" / "locale"
        if locale_dir.isdir():
            settings.LOCALE_PATHS = (locale_dir, ) + settings.LOCALE_PATHS
    def parse_arguments(*args, **options):  # pylint: disable=unused-argument
        """
        Parse and validate arguments for update_assets command.

        Args:
            *args: Positional arguments passed to the update_assets command
            **options: optional arguments passed to the update_assets command
        Returns:
            A tuple containing parsed values for themes, system, source comments and output style.
            1. themes (list): list of Theme objects
            2. system (bool): True if system sass need to be compiled, False otherwise
            3. source_comments (bool): True if source comments need to be included in output, False otherwise
            4. output_style (str): Coding style for compiled css files.
        """
        given_themes = options.get("themes", ["all"])
        output_style = options.get("output_style", "nested")
        system = options.get("system", True)
        source_comments = options.get("source_comments", False)
        collect = options.get("collect", True)

        available_themes = {t.theme_dir: t for t in get_themes()}

        if 'no' in given_themes or 'all' in given_themes:
            # Raise error if 'all' or 'no' is present and theme names are also given.
            if len(given_themes) > 1:
                raise CommandError("Invalid themes value, It must either be 'all' or 'no' or list of themes.")
        # Raise error if any of the given theme name is invalid
        # (theme name would be invalid if it does not exist in themes directory)
        elif (not set(given_themes).issubset(available_themes.keys())) and is_comprehensive_theming_enabled():
            raise CommandError(
                "Given themes '{invalid_themes}' do not exist inside themes directory '{themes_dir}'".format(
                    invalid_themes=", ".join(set(given_themes) - set(available_themes.keys())),
                    themes_dir=get_base_themes_dir(),
                ),
            )

        if "all" in given_themes:
            themes = get_themes()
        elif "no" in given_themes:
            themes = []
        else:
            # convert theme names to Theme objects
            themes = [available_themes.get(theme) for theme in given_themes]

        return themes, system, source_comments, output_style, collect
Beispiel #9
0
 def test_get_themes(self):
     """
     Tests get_themes returns all themes in themes directory.
     """
     expected_themes = [
         Theme('test-theme', 'test-theme'),
         Theme('test-theme-2', 'test-theme-2'),
     ]
     actual_themes = get_themes()
     self.assertItemsEqual(expected_themes, actual_themes)
Beispiel #10
0
 def test_get_themes(self):
     """
     Tests get_themes returns all themes in themes directory.
     """
     theme_dirs = get_theme_base_dirs()
     expected_themes = [
         Theme('test-theme', 'test-theme', theme_dirs[0]),
         Theme('test-theme-2', 'test-theme-2', theme_dirs[0]),
         Theme('test-theme-3', 'test-theme-3', theme_dirs[1]),
     ]
     actual_themes = get_themes()
     self.assertItemsEqual(expected_themes, actual_themes)
Beispiel #11
0
 def test_get_themes(self):
     """
     Tests get_themes returns all themes in themes directory.
     """
     theme_dirs = get_theme_base_dirs()
     expected_themes = [
         Theme('test-theme', 'test-theme', theme_dirs[0]),
         Theme('test-theme-2', 'test-theme-2', theme_dirs[0]),
         Theme('test-theme-3', 'test-theme-3', theme_dirs[1]),
     ]
     actual_themes = get_themes()
     self.assertItemsEqual(expected_themes, actual_themes)
Beispiel #12
0
def enable_theming(themes_dir):
    """
    Add directories and relevant paths to settings for comprehensive theming.

    Args:
        themes_dir (str): path to base theme directory
    """
    if isinstance(themes_dir, basestring):
        themes_dir = Path(themes_dir)

    for theme in get_themes(themes_dir):
        locale_dir = themes_dir / theme.theme_dir / "conf" / "locale"
        if locale_dir.isdir():
            settings.LOCALE_PATHS = (locale_dir, ) + settings.LOCALE_PATHS
Beispiel #13
0
def offline_context():
    """
    offline context for compress management command, offline_context function iterates
    through all applied themes and returns a separate context for each theme.
    """
    main_css_path = "css/base/main.css"

    for theme in get_themes():
        main_css = ThemeStorage(prefix=theme.theme_dir_name).url(main_css_path)

        yield {
            'main_css': main_css,
        }

    yield {
        'main_css': ThemeStorage().url(main_css_path),
    }
    def find(self, path, all=False):  # pylint: disable=redefined-builtin
        """
        Looks for files in the theme directories.
        """
        matches = []
        theme_dir = path.split("/", 1)[0]

        themes = {t.theme_dir: t for t in get_themes()}
        # if path is prefixed by theme name then search in the corresponding storage other wise search all storages.
        if theme_dir in themes:
            theme = themes[theme_dir]
            path = "/".join(path.split("/")[1:])
            match = self.find_in_theme(theme.theme_dir, path)
            if match:
                if not all:
                    return match
                matches.append(match)
        return matches
    def __init__(self, *args, **kwargs):
        # The list of themes that are handled
        self.themes = []
        # Mapping of theme names to storage instances
        self.storages = OrderedDict()

        themes = get_themes()
        for theme in themes:
            theme_storage = self.storage_class(
                os.path.join(theme.path, self.source_dir),
                prefix=theme.theme_dir,
            )

            self.storages[theme.theme_dir] = theme_storage
            if theme.theme_dir not in self.themes:
                self.themes.append(theme.theme_dir)

        super(ThemeFilesFinder, self).__init__(*args, **kwargs)
Beispiel #16
0
    def find(self, path, all=False):  # pylint: disable=redefined-builtin
        """
        Looks for files in the theme directories.
        """
        matches = []
        theme_dir = path.split("/", 1)[0]

        themes = {t.theme_dir_name: t for t in get_themes()}
        # if path is prefixed by theme name then search in the corresponding storage other wise search all storages.
        if theme_dir in themes:
            theme = themes[theme_dir]
            path = "/".join(path.split("/")[1:])
            match = self.find_in_theme(theme.theme_dir_name, path)
            if match:
                if not all:
                    return match
                matches.append(match)
        return matches
Beispiel #17
0
    def __init__(self, *args, **kwargs):
        # The list of themes that are handled
        self.themes = []
        # Mapping of theme names to storage instances
        self.storages = OrderedDict()

        themes = get_themes()
        for theme in themes:
            theme_storage = self.storage_class(
                os.path.join(theme.path, self.source_dir),
                prefix=theme.theme_dir_name,
            )

            self.storages[theme.theme_dir_name] = theme_storage
            if theme.theme_dir_name not in self.themes:
                self.themes.append(theme.theme_dir_name)

        super(ThemeFilesFinder, self).__init__(*args, **kwargs)
def offline_context():
    """
    offline context for compress management command, offline_context function iterates
    through all applied themes and returns a separate context for each theme.
    """

    for theme in get_themes():
        main_css = ThemeStorage(prefix=theme.theme_dir).url("css/base/main.css")
        swagger_css = ThemeStorage(prefix=theme.theme_dir).url("css/base/edx-swagger.css")

        yield {
            'main_css': main_css,
            'swagger_css': swagger_css,
        }

    yield {
        'main_css': ThemeStorage().url("css/base/main.css"),
        'swagger_css': ThemeStorage().url("css/base/edx-swagger.css"),
    }
def offline_context():
    """
    offline context for compress management command, offline_context function iterates
    through all applied themes and returns a separate context for each theme.
    """

    for theme in get_themes():
        main_css = ThemeStorage(
            prefix=theme.theme_dir).url("css/base/main.css")
        swagger_css = ThemeStorage(
            prefix=theme.theme_dir).url("css/base/edx-swagger.css")

        yield {
            'main_css': main_css,
            'swagger_css': swagger_css,
        }

    yield {
        'main_css': ThemeStorage().url("css/base/main.css"),
        'swagger_css': ThemeStorage().url("css/base/edx-swagger.css"),
    }
 def setUp(self):
     super(TestUpdateAssets, self).setUp()
     self.themes = get_themes()
 def setUp(self):
     super(TestUpdateAssets, self).setUp()
     self.themes = get_themes()