theme.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:veripress 作者: veripress 项目源码 文件源码
def install_command(theme, branch, name):
    if re.fullmatch('[_\-A-Z0-9a-z]+', theme):
        theme_name = name or theme
        theme_path = os.path.join(get_themes_dir(), theme_name)
        cmd = 'git clone --branch {} https://github.com/veripress/themes.git {}'.format(theme, theme_path)
    else:
        m = re.fullmatch('([_\-A-Z0-9a-z]+)/([_\-A-Z0-9a-z]+)', theme)
        if not m:
            raise click.BadArgumentUsage('The theme should be like "default" (branch of veripress/themes) '
                                         'or "someone/the-theme" (third-party theme on GitHub)')
        user = m.group(1)
        repo = m.group(2)
        theme_name = name or repo
        theme_path = os.path.join(get_themes_dir(), theme_name)
        cmd = 'git clone --branch {} https://github.com/{}/{}.git {}'.format(branch, user, repo, theme_path)
    exit_code = os.system(cmd)
    if exit_code == 0:
        click.echo('\n"{}" theme has been installed successfully.'.format(theme_name))
    else:
        click.echo('\nSomething went wrong. Do you forget to install git? '
                   'Or is there another theme with same name existing?')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号