Ejemplo n.º 1
0
def get_data(theme):
    data = {}
    data['chain'] = utils.get_theme_chain(theme, DIR)
    data['name'] = theme
    readme = utils.get_asset_path('README.md', data['chain'], _themes_dir=DIR)
    conf_sample = utils.get_asset_path('conf.py.sample', data['chain'], _themes_dir=DIR)
    if readme:
        data['readme'] = io.open(readme, 'r', encoding='utf-8').read()
    else:
        data['readme'] = 'No README.md file available.'

    if conf_sample:
        data['confpy'] = pygments.highlight(
            io.open(conf_sample, 'r', encoding='utf-8').read(),
            PythonLexer(), HtmlFormatter(cssclass='code'))
    else:
        data['confpy'] = None

    data['bootswatch'] = ('bootstrap' in data['chain'] or
        'bootstrap-jinja' in data['chain'] or
        'bootstrap3-jinja' in data['chain'] or
        'bootstrap3' in data['chain']) and \
        'bootstrap3-gradients' not in data['chain']
    data['engine'] = utils.get_template_engine(data['chain'], DIR)
    data['chain'] = data['chain'][::-1]

    data['allver'] = []
    for v in ALL_VERSIONS_SUPPORTED:
        if glob.glob('v{0}/*'.format(v)):
            data['allver'].append(v)

    return data
Ejemplo n.º 2
0
def get_data(theme):
    data = {}
    data['chain'] = utils.get_theme_chain(theme)
    data['name'] = theme
    readme = utils.get_asset_path('README.md', data['chain'])
    conf_sample = utils.get_asset_path('conf.py.sample', data['chain'])
    if readme:
        data['readme'] = codecs.open(readme, 'r', 'utf8').read()
    else:
        data['readme'] = 'No README.md file available.'

    if conf_sample:
        data['confpy'] = pygments.highlight(
            codecs.open(conf_sample, 'r', 'utf8').read(),
            PythonLexer(), HtmlFormatter(cssclass='code'))
    else:
        data['confpy'] = None

    data['bootswatch'] = ('bootstrap' in data['chain'] or
        'bootstrap-jinja' in data['chain'] or
        'bootstrap3-jinja' in data['chain'] or
        'bootstrap3' in data['chain']) and \
        'bootstrap3-gradients' not in data['chain']
    data['engine'] = utils.get_template_engine(data['chain'])
    data['chain'] = data['chain'][::-1]
    return data
Ejemplo n.º 3
0
    def new_theme(self, name, engine, parent, create_legacy_meta=False):
        """Create a new theme."""
        base = 'themes'
        themedir = os.path.join(base, name)
        LOGGER.info(
            "Creating theme {0} with parent {1} and engine {2} in {3}".format(
                name, parent, engine, themedir))
        if not os.path.exists(base):
            os.mkdir(base)
            LOGGER.info("Created directory {0}".format(base))

        # Check if engine and parent match
        parent_engine = utils.get_template_engine(
            utils.get_theme_chain(parent, self.site.themes_dirs))

        if parent_engine != engine:
            LOGGER.error(
                "Cannot use engine {0} because parent theme '{1}' uses {2}".
                format(engine, parent, parent_engine))
            return 2

        # Create theme
        if not os.path.exists(themedir):
            os.mkdir(themedir)
            LOGGER.info("Created directory {0}".format(themedir))
        else:
            LOGGER.error("Theme already exists")
            return 2

        cp = configparser.ConfigParser()
        cp['Theme'] = {'engine': engine, 'parent': parent}

        theme_meta_path = os.path.join(themedir, name + '.theme')
        with io.open(theme_meta_path, 'w', encoding='utf-8') as fh:
            cp.write(fh)
            LOGGER.info("Created file {0}".format(theme_meta_path))

        if create_legacy_meta:
            with io.open(os.path.join(themedir, 'parent'),
                         'w',
                         encoding='utf-8') as fh:
                fh.write(parent + '\n')
                LOGGER.info("Created file {0}".format(
                    os.path.join(themedir, 'parent')))
            with io.open(os.path.join(themedir, 'engine'),
                         'w',
                         encoding='utf-8') as fh:
                fh.write(engine + '\n')
                LOGGER.info("Created file {0}".format(
                    os.path.join(themedir, 'engine')))

        LOGGER.info("Theme {0} created successfully.".format(themedir))
        LOGGER.info(
            'Remember to set THEME="{0}" in conf.py to use this theme.'.format(
                name))
Ejemplo n.º 4
0
def sanity_check(theme=None):
    if theme is None:  # Check them all
        for theme in theme_list():
            sanity_check(theme)
        return
    themes = utils.get_theme_chain(theme, themes_dirs=['v7'])
    themes_bn = [os.path.basename(i) for i in themes]
    engine = utils.get_template_engine(themes)

    # Inheritance checks

    # All themes must inherit from base
    if themes_bn[-1] != 'base':
        error("theme {0} doesn't inherit from base".format(theme))
    # All jinja themes must inherit from base-jinja
    if engine == "jinja" and "base-jinja" not in themes_bn:
        error("theme {0} is jinja-based and doesn't inherit from base-jinja".format(theme))
    # All mako themes must NOT inherit from base-jinja
    if engine == "mako" and "base-jinja" in themes_bn:
        error("theme {0} is mako-based and inherits from base-jinja".format(theme))

    # Detect exact asset duplication in theme chain
    for root, dirs, files in os.walk("v7/"+theme):
        for f in files:
            path = "/".join([root, f])
            asset = path.split("/", 2)[-1]
            r, p1, p2 = is_asset_duplicated(asset, themes)
            if r:
                error("duplicated asset: {0} {1}".format(p1, p2))

    # Detect deprecated names and anonymous namespaces
    for root, dirs, files in os.walk("v7/"+theme+"/templates"):
        for f in files:
            path = "/".join([root, f])
            with io.open(path, "r", encoding="utf-8") as inf:
                data = inf.read()
            for k, exceptions in blacklist:
                if k in data and f not in exceptions:
                    error("theme '{0}' contains deprecated name '{1}' in {2}".format(theme, k, path))

    # Ensure the theme has a README.md
    if utils.get_asset_path('README.md', themes) is None:
        error("theme '{0}' has no README.md".format(theme))

    # Ensure the theme has a meta file
    if utils.get_asset_path(theme + '.theme', themes) is None:
        warning("theme '{0}' has no {0}.theme meta file".format(theme))
Ejemplo n.º 5
0
def get_data(theme):
    data = {}
    data['name'] = theme
    readme = utils.get_asset_path('README', [theme])
    if readme:
        data['readme'] = open(readme).read()
    else:
        data['readme'] = 'No readme file available'
    data['chain'] = utils.get_theme_chain(theme)
    data['bootswatch'] = ('bootstrap' in data['chain'] or
        'bootstrap-jinja' in data['chain'] or
        'bootstrap3-jinja' in data['chain'] or
        'bootstrap3' in data['chain']) and \
        'bootstrap3-gradients' not in data['chain']
    data['engine'] = utils.get_template_engine(data['chain'])
    data['chain'] = data['chain'][::-1]
    return data
Ejemplo n.º 6
0
    def new_theme(self, name, engine, parent, create_legacy_meta=False):
        """Create a new theme."""
        base = 'themes'
        themedir = os.path.join(base, name)
        LOGGER.info("Creating theme {0} with parent {1} and engine {2} in {3}".format(name, parent, engine, themedir))
        if not os.path.exists(base):
            os.mkdir(base)
            LOGGER.info("Created directory {0}".format(base))

        # Check if engine and parent match
        parent_engine = utils.get_template_engine(utils.get_theme_chain(parent, self.site.themes_dirs))

        if parent_engine != engine:
            LOGGER.error("Cannot use engine {0} because parent theme '{1}' uses {2}".format(engine, parent, parent_engine))
            return 2

        # Create theme
        if not os.path.exists(themedir):
            os.mkdir(themedir)
            LOGGER.info("Created directory {0}".format(themedir))
        else:
            LOGGER.error("Theme already exists")
            return 2

        cp = configparser.ConfigParser()
        cp['Theme'] = {
            'engine': engine,
            'parent': parent
        }

        theme_meta_path = os.path.join(themedir, name + '.theme')
        with io.open(theme_meta_path, 'w', encoding='utf-8') as fh:
            cp.write(fh)
            LOGGER.info("Created file {0}".format(theme_meta_path))

        if create_legacy_meta:
            with io.open(os.path.join(themedir, 'parent'), 'w', encoding='utf-8') as fh:
                fh.write(parent + '\n')
                LOGGER.info("Created file {0}".format(os.path.join(themedir, 'parent')))
            with io.open(os.path.join(themedir, 'engine'), 'w', encoding='utf-8') as fh:
                fh.write(engine + '\n')
                LOGGER.info("Created file {0}".format(os.path.join(themedir, 'engine')))

        LOGGER.info("Theme {0} created successfully.".format(themedir))
        LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(name))
Ejemplo n.º 7
0
def read_theme(theme):
    # Gather this theme's data
    theme_name = os.path.basename(theme)
    data = {}
    data['name'] = theme_name
    readme = os.path.join(theme, 'README.md')
    if os.path.isfile(readme):
        with codecs.open(readme, 'r', 'utf8') as inf:
            data['readme'] = inf.read()
    else:
        data['readme'] = ''

    themes = utils.get_theme_chain(theme_name)
    data['engine'] = utils.get_template_engine(themes)

    if 'bootstrap3' in themes:
        data['bs_version'] = 3
    elif 'bootstrap' in themes:
        data['bs_version'] = 2
    else:
        data['bs_version'] = 0
Ejemplo n.º 8
0
def read_theme(theme):
    # Gather this theme's data
    theme_name = os.path.basename(theme)
    data = {}
    data['name'] = theme_name
    readme = os.path.join(theme, 'README.md')
    if os.path.isfile(readme):
        with codecs.open(readme, 'r', 'utf8') as inf:
            data['readme'] = inf.read()
    else:
        data['readme'] = ''

    themes = utils.get_theme_chain(theme_name)
    data['engine'] = utils.get_template_engine(themes)


    if 'bootstrap3' in themes:
        data['bs_version'] = 3
    elif 'bootstrap' in themes:
        data['bs_version'] = 2
    else:
        data['bs_version'] = 0