厨师长

ccextender的Python项目详细描述


ccextender—具有分支构建的CookiCutter

https://github.com/asecurityteam/ccextender

概述

ccextender或ccx是一个构建在cookiecutter(模板程序)之上的存储库构建应用程序。它的主要目的是为逻辑分支构建路径提供一个框架,可以根据用户的决策创建定制的存储库。

ccextender的工作原理,简要介绍
  1. 您将创建各种cookiecutter模板,其中包含典型存储库设置的构建块。使用ccextender引入的一些新技术,您的模板将可以接收大量复杂的更改包(更改包)。
  2. 您将编写一个配置文件,在其中定义这些所谓的更改包,以及用户提示和构建逻辑,这些逻辑将用于构建未来的repo。
  3. 从现在起,只要您想创建存储库,就可以对配置文件运行ccender。通过回答配置文件中的提示,您将指导每个存储库的构建以满足您的需要。ccextender将通过自动进行各种配置更改来节省您的时间,同时确保您的存储库只有您所需要的内容。
  4. < > >
    什么是ccender的优点:
    • 定期创建具有类似结构和内容的新存储库的开发人员
    • 任何希望自动创建模板化文件和文件夹的人
    什么是ccender的坏处:
    • 一次性创建存储库。ccextender是一种预先加载创建多个存储库工作的方法,对于只需要一个或两个类似的repo的团队来说,它不会带来太大的价值。

    命令

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    

    安装

    先决条件:

    蟒蛇3

    oyaml-允许将yaml文件作为有序字典读取的python包

    CookiCutter-模板应用程序

    pip3 install cookiecutter oyaml
    
    pip3 install ccextender
    

    用法

    ccextender需要一个yaml配置文件和至少一个cookiecutter模板目录才能运行。

    有关如何设置CookieCutter模板的详细信息,请访问:https://cookiecutter.readthedocs.io/en/latest/first_steps.html" rel="nofollow">https://cookiecutter.readthedocs.io/en/latest/first_steps.html

    有关如何设置配置文件,请阅读本文档的"配置"部分。

    <H4>1。创建配置文件。

    配置文件将包含交互式生成的逻辑、计划使用的模板的说明,以及应将哪些模板化更改与您的决策关联。

    默认情况下,ccexender将在当前目录中查找名为ccexender.yaml的文件,但您可以通过--ccx_config标志指示它读取任何文件:

    ccextender --ccx_config=/Users/me/Documents/myconfig.yaml
    

    您的配置文件必须遵循yaml格式。看看如何编写一个ccextender配置文件,请参见配置

    <H4>2。运行ccextender

    一旦创建了配置文件,ccextender将完成其余工作。剩下的就是对yaml文件中的提示做出响应。

    使用示例:

    要读取特定配置文件并将输出写入其他目录:

    ccextender -c /Users/me/Documents/SecDev_Build.yaml -o /python/src/github.com/asecurityteam/
    

    查看可用命令:

    ccextender help

    要将特定模板用于标准的默认值,请执行以下操作:

    ccextender -s template-standards
    

    注意:这不是模板的路径或位置,而是模板的目录名。您应该在配置文件的"位置"部分下添加模板位置。请参见配置。

    使用默认变量运行:

    ccextender
    

    每个命令的默认值为:

    --ccx_config, -c = ccextender.yaml
    --std_template, -s = template-standards
    --test_mode, -t = None
    --outdir, -o = .
    

    配置

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    0

    设置模板

    CookieCutter模板相当简单。

    它们的结构是:

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    1

    json文件是传统上定义模板变量及其默认值的地方。它们可能看起来像这样:

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    2

    当您运行cookiecutter时,它会提示您为每个变量输入值,然后替换模板中每个文件中{{cookiecutter.<;variable name>;}}的所有实例,然后将它们复制到目标目录。

    不过,ccextender的工作方式有所不同。您需要手动输入的唯一值是标准模板中的变量(通常是项目名称、联系人电子邮件等常规内容),其余模板中的所有变量都将由您在配置文件中配置的更改包设置。

    因此,假设您运行了ccextender并做出了一个触发更改包的决定-a:

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    3

    change-pack-a为makefile模板和docker文件模板的cookiecutter.json文件中的变量赋值。这些文件可能如下所示:

    模板makefile/cookiecutter.json

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    4

    模板dockerfile/cookiecutter.json

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    5

    然后,当ccextender创建一个新的存储库时,它使用change-pack-a中的变量分配作为对应的cookiecutter变量。因此,您可以考虑在ccextender.yaml文件的更改包块中分配变量,以基本上取代在传统的Cookiecutter会话中手动输入变量。

    可加变量赋值

    ccextender允许您为同一个变量分配多个值。例如,让我们看看前面的dockerfile模板的cookiecutter.json:

    模板dockerfile/cookiecutter.json

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    5

    pip_install变量对应于dockerfile:

    文档文件

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    7

    现在假设您有一个配置文件,其中有一个changepack部分,如下所示:

    ccextender.yaml

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    8

    现在让我们假设我们运行了ccender,并且我们的决定导致使用了更改包a、b和c。这意味着pip_install被赋值4次。在第一个赋值之后,ccextender会将每个后续赋值追加到当前值字符串的末尾,并用"\n"分隔。这将导致ccender在一个值中插入多行。在我们的例子中,dockerfile现在看起来像:

    文档文件

    ccextender
        help
        --ccx_config, -c <Path to configuration file>
        --std_template, -s <Path to template containing defaults for your standards> #(See #standards)
        --test_mode, -t # Activates test mode (which disables prompts for stdin)
        --outdir, -o <Path to desired repository location>
    
    9

    你好,世界

    <H4>1。创建练习模板
    创建模板目录:
    pip3 install cookiecutter oyaml
    
    0
    创建自述模板:

    在template project info/目录中,添加包含以下内容的文件cookiecutter.json:

    pip3 install cookiecutter oyaml
    
    1

    然后进入下面的目录:

    pip3 install cookiecutter oyaml
    
    2

    添加文件readme.txt以下内容:

    pip3 install cookiecutter oyaml
    
    3
    创建Hello World模板:

    在模板hello目录中,添加包含以下内容的文件cookiecutter.json:

    pip3 install cookiecutter oyaml
    
    4

    然后进入下面的目录:

    pip3 install cookiecutter oyaml
    
    2

    添加包含以下内容的文件hello.py:

    pip3 install cookiecutter oyaml
    
    6
    创建再见模板:

    在模板再见目录中,添加包含以下内容的文件cookiecutter.json:

    pip3 install cookiecutter oyaml
    
    7

    然后进入下面的目录:

    pip3 install cookiecutter oyaml
    
    2

    添加包含以下内容的文件hello.py:

    pip3 install cookiecutter oyaml
    
    6
    创建标准模板:

    在template standards目录中,添加包含以下内容的文件cookiecutter.json:

    pip3 install cookiecutter oyaml
    
    1 <H4>2。创建配置文件:

    在"模板"文件夹中,创建一个包含以下内容的文件ccextender.yaml:

    pip3 install ccextender
    
    1 <H4>3。运行ccextender

    现在,导航到保存ccextender.yaml的目录,然后键入:

    ccextender
    

    回答提示。完成后,您将看到在当前目录中创建了一个新的存储库。导航到回购和运行:

    pip3 install ccextender
    
    3

    您应该看到您的更改已经实现。尝试运行该程序几次,您将看到构建是如何变化的。

    常见问题

    ccender找不到模板的cookiecutter.json

    因此,这要么意味着指向模板的路径或url已断开,要么意味着其中一个Cookiecutter模板缺少Cookiecutter.json文件。验证所有模板目录(包括标准模板)中是否都有cookiecutter.json,然后使用以下命令手动调用链接/路径以验证它们是否正常工作:

    pip3 install ccextender
    
    4

    扩展ccextender

    添加新的逻辑标志

    因此,在编写本文时,ccextender只有两个逻辑标志:include if和exclude if。但是对于可以添加多少新标志,以及它们可以做什么,没有限制。若要添加新标志,请导航到pkg/ccextender中的ccextender.py并查看类函数prompt_user_decision。您应该看到一个注释,指示逻辑标志部分。现在,它看起来像这样:

    pip3 install ccextender
    
    5

    新代码只需要以下标准部分:

    pip3 install ccextender
    
    6

    例如,假设我们想让用户配置用户提示的颜色:

    pip3 install ccextender
    
    7

    然后,我们只需将以下行添加到任何要着色的决策块:

    pip3 install ccextender
    
    8

    欢迎加入QQ群-->: 979659372 Python中文网_新手群

    推荐PyPI第三方库


热门话题
java语义理解递归反向字符串返回语句   java toString()方法打印空值   java大型IN子句   如何使用JavaSpring在JavaScriptjQuery中设置post路径   java ByteArrayOutputStream已上载到服务器   java为什么轮询在SocketIO上获取数据“无法加载请求的项”?   java源代码应该以UTF8格式保存   Java数据库轮询器?   在Java中将double转换为float   java AccessDeniedException:C:\Windows\System32\drivers\etc\hosts