예제 #1
0
def test_copy(tmpdir):
    src_dir = path_append(tmpdir, "src")
    tar_dir = path_append(tmpdir, "tar")

    src = path_append(src_dir, "src.txt")
    tar = path_append(tar_dir, "tar.txt")

    with as_out_io(src) as wf:
        print("hello world", file=wf)

    config.OVERRIDE = False
    copytree(src_dir, tar_dir)
    copytree(src_dir, tar_dir)
    copyfile(src, tar)
    template_copy(src, tar)

    config.OVERRIDE = True
    copytree(src_dir, tar_dir)
    copyfile(src, tar)

    config.OVERRIDE = None
    with simulate_stdin("y", "y"):
        copytree(src_dir, tar_dir)
        copyfile(src, tar)

    with simulate_stdin("n", "n"):
        copytree(src_dir, tar_dir)
        copyfile(src, tar)

    with simulate_stdin("unk", "y"):
        default_legal_input("", __legal_input={"y"})
예제 #2
0
    def get_stage_params(stage_image_name=None,
                         stage_image_port=None,
                         on_stop=False,
                         only_master=None,
                         manual=None):
        _params = {}
        if stage_image_name is None:
            _params["image_name"] = default_legal_input("Choose a image",
                                                        is_legal=lambda x: True
                                                        if x else False)
        else:
            _params["image_name"] = default_legal_input(
                "Choose a image", __default_value=stage_image_name)

        if stage_image_port is not None:
            _params["image_port"] = legal_input(
                "Stage Image Port (default is %s) < " % stage_image_port,
                __default_value=stage_image_port)
        if on_stop:
            _params["on_stop"] = binary_legal_input(
                "Add Corresponding Stop Stage?")
        if only_master is not None:
            _params["only_master"] = binary_legal_input(
                "Only triggered in master branch?", _default=only_master)
        if manual is not None:
            _params["manual"] = binary_legal_input("Triggered manually?",
                                                   _default=manual)
        return _params
예제 #3
0
def docs_cli(project=None,
             title=None,
             author=None,
             copyright=None,
             default_style="sphinx",
             **kwargs):
    params = dict(
        project=legal_input("Project Name < ",
                            is_legal=lambda x: True if x else False)
        if not project else project,
        docs_style=default_legal_input("Docs Style",
                                       __legal_input={"mxnet", "sphinx"},
                                       __default_value="%s" % default_style),
        docs_root="docs/" if binary_legal_input("Make 'docs/' directory?",
                                                _default="y") else "./",
    )
    if params["docs_style"] != "sphinx":
        params.update(
            dict(
                title=legal_input(
                    "Docs Title (default is %s) < " % params["project"],
                    __default_value=params["project"]) if not title else title,
                author=legal_input("Author < ",
                                   is_legal=lambda x: True if x else False)
                if not author else author,
            ))

        default_copyright = "%s, %s" % (datetime.date.today().year,
                                        params["author"])
        params.update(
            dict(copyright=legal_input("Copyright (default is %s) < " %
                                       default_copyright,
                                       __default_value=default_copyright)
                 if not copyright else copyright, ))
    params.update(readthedocs=binary_legal_input("Install .readthedocs.yml?"))

    if binary_legal_input("Install Dockerfile for documents?"):
        params.update(
            dict(docker_params=dockerfile_cli("docs", docker_type="nginx")))

    return params
예제 #4
0
def dockerfile_cli(project_type, docker_type=None, port=None):
    project_docker = {
        "python": {"cli", "flask"},
        "web": {"nginx", "vue"},
        "docs": {"nginx"},
    }

    docker_params = {}

    docker_type = legal_input(
        "Choose a service type (%s) < " %
        "/".join(project_docker[project_type]),
        __legal_input=project_docker[project_type],
    ) if docker_type is None else docker_type

    docker_params["docker_type"] = docker_type

    if docker_type in {"nginx", "vue"}:
        docker_params.update(image_name=default_legal_input(
            "Choose a image", __default_value="nginx"),
                             path_to_html=default_legal_input(
                                 "Specify the html directory",
                                 __default_value="_build/html"
                                 if project_type == "docs" else "build/html"))

    if project_type == "python":
        docker_params.update(image_name=default_legal_input(
            "Choose a image", __default_value="python:3.6"))
        if docker_type == "cli":
            docker_params.update(path_to_main=default_legal_input(
                "Specify the main entry (e.g., the path to main.py)",
                is_legal=lambda x: True if x else False))
        elif docker_type == "flask":
            docker_params.update(path_to_main=default_legal_input(
                "Specify the main entry (e.g., main_package.main_py:main_func)",
                is_legal=lambda x: True if x else False),
                                 port=default_legal_input(
                                     "Specify the port that docker will listen",
                                     is_legal=lambda x: True if x else False)
                                 if port is None else port)

        else:  # pragma: no cover
            raise TypeError(
                "%s: cannot handle docker type %s, only supports %s" %
                (project_type, docker_type, project_docker[project_type]))

    return docker_params
예제 #5
0
def cli(skip_top=True, project=None, override=None, tar_dir="./", **kwargs):
    """
    The main function for arch
    """
    config.OVERRIDE = override

    main_params = main_cli(skip_top, project, **kwargs)

    kwargs.update(main_params)

    indicator = dict(travis=binary_legal_input("Install travis?"), )

    docs = binary_legal_input("Install docs?")
    if main_params["project_type"] == "docs" or docs:
        default_style = "mxnet" if main_params[
            "project_type"] == "docs" else "sphinx"
        docs_params = docs_cli(default_style=default_style, **kwargs)
    else:
        docs_params = {}

    service_params = {}
    docker_params = {}
    if main_params["project_type"] != "docs":
        service = binary_legal_input("To deploy as a service")
        if service:
            docker_params.update(
                dockerfile_cli(project_type=main_params["project_type"]))
            if "port" not in docker_params:
                port = default_legal_input("Image Port", __default_value=None)
            else:
                port = docker_params["port"]
            service_params["port"] = None if port == 'null' else port
            service_params.update(
                dict(private=binary_legal_input("Is private project?"), ))
            stages_candidates = {
                "test": {
                    "stage_image_name": docker_params["image_name"]
                }
            }
            if main_params["project_type"] == "python":
                stages_candidates["build"] = {"need": "n"}
            if binary_legal_input("Install .gitlab-ci.yml?"):
                service_params.update(
                    dict(gitlab_ci_params=gitlab_ci_cli(
                        port=port,
                        docs=docs,
                        stages_candidates=stages_candidates), ))

        elif binary_legal_input("Install Dockerfile?"):
            docker_params.update(
                dockerfile_cli(project_type=main_params["project_type"]))

    if skip_top:
        tar_dir = path_append(tar_dir, "./")
    else:
        tar_dir = path_append(tar_dir, main_params["project"])
        os.makedirs(tar_dir)

    __project_type = main_params["project_type"]

    project_types[__project_type](tar_dir=tar_dir,
                                  main_params=main_params,
                                  docs_params=docs_params,
                                  docker_params=docker_params,
                                  service_params=service_params,
                                  **indicator)