Ejemplo n.º 1
0
def find_files(dir):
    with fs.open_fs(dir) as the_fs:
        for a_file in the_fs.listdir("."):
            relative_path = url_join(dir, a_file)
            if is_dir(relative_path):
                a_list = find_files(relative_path)
                yield from a_list
            else:
                yield relative_path
Ejemplo n.º 2
0
def walk_tree(parent_directory):
    dir_list = []
    p = fs.open_fs(parent_directory)
    for a_file in p.listdir("."):
        relative_path = url_join(parent_directory, a_file)
        if is_dir(relative_path):
            a_list = walk_tree(relative_path)
            dir_list.append(a_list)
        else:
            dir_list.append(relative_path)
    return dir_list
Ejemplo n.º 3
0
def find_sub_directories(parent_directory):
    dir_list = []
    p = fs.open_fs(parent_directory)
    for a_file in p.listdir("."):
        relative_path = url_join(parent_directory, a_file)
        if is_dir(relative_path):
            a_list = find_sub_directories(relative_path)
            key = cookiefy(a_file)
            if a_list:
                dir_list.append({key: a_list})
            else:
                dir_list.append(key)
    return dir_list
Ejemplo n.º 4
0
def search_file(base_dir, file_name):
    the_file = file_name
    if not file_system.exists(the_file):
        if base_dir:
            file_under_base_dir = file_system.url_join(base_dir, the_file)
            if file_system.exists(file_under_base_dir):
                the_file = file_system.fs_url(file_under_base_dir)
            else:
                raise IOError(constants.ERROR_DATA_FILE_NOT_FOUND %
                              (file_name, the_file))
        else:
            raise IOError(constants.ERROR_DATA_FILE_ABSENT % the_file)
    return the_file
Ejemplo n.º 5
0
def cookiecutter_json_to_yehua_file(path):
    content = read_unicode(url_join(path, "cookiecutter.json"))
    cookie_questions = json.loads(content)

    questions = []
    for key, value in cookie_questions.items():
        if isinstance(value, list):
            complex_question = {"question": f"{key}:"}
            for index, option in enumerate(value, 1):
                complex_question[f"{index}. {option}"] = "N/A"
            questions.append({key: [complex_question]})
        else:
            questions.append({key: f"{key} [{value}]: "})
    project_dir = find_project_name(path)
    dir_list = walk_tree(url_join(path, project_dir))
    better_list = cleanse(dir_list, url_join(path, project_dir))
    layout = find_sub_directories(url_join(path, project_dir))

    git_repo_files = []
    for entry in better_list:
        git_repo_files += list(entry.keys())
    git_repo_files += [".moban.yml", cookiefy(project_dir + ".yml")]
    yehua = {
        "introduction": INTRODUCTION,
        "configuration": {
            "template_path": project_dir,
            "static_path": project_dir,
        },
        "post-moban": {
            "git-repo-files": git_repo_files
        },
        "questions": questions,
        "moban": better_list,
        "layout": layout,
    }
    yaml_content = StringIO()
    dump_yaml(yehua, yaml_content)
    return yaml_content.getvalue()
Ejemplo n.º 6
0
def test_reference_pypi_package(fake_inputs):
    project_name = "project_s"
    fake_inputs.return_value = {
        "full_name": "full_n",
        "email": "email_",
        "github_username": "******",
        "project_name": "project_n",
        "project_slug": "project_s",
        "project_short_description": "project_sd",
        "pypi_username": "******",
        "version": "1.0",
        "use_pytest": "y",
        "use_pypi_deployment_with_travis": "y",
        "add_pyup_badge": "y",
        "command_line_interface": "Click",
        "create_author_file": "y",
        "open_source_license": "MIT license",
    }
    path = "gh:moremoban/cookiecutter-pypackage"
    with patch.object(sys, "argv", ["yh", path]):
        main()

    assert os.path.exists(os.path.join("project_s", ".git"))

    for a_file in find_files("project_s"):
        reference = url_join("tests/fixtures", a_file)
        if ".git" in a_file:
            continue
        if fs.path.basename(a_file) in [
            ".moban.yml",
            "HISTORY.rst",
            ".moban.hashes",
        ]:
            # no way to compare them
            continue
        r = read_unicode(reference)
        a = read_unicode(a_file)
        eq_(r, a, f"{a_file} differs")
        os.unlink(a_file)

    shutil.rmtree(project_name)
def test_url_join():
    for parent, child, expected_path in URL_JOIN_TEST_FIXTURES:
        actual = file_system.url_join(parent, child)
        eq_(actual, expected_path)