Пример #1
0
def make_empty_project(in_path: str,
                       name: str=None) -> bool:
    """ Build an empty project that can be used as a starting point. """

    destination_path = in_path

    if name is not None and len(name) > 0:
        # make sure any whitespace is replaced with dashes
        name_components = name.split(' ')
        name = '-'.join(name_components).lower()

        destination_path = os.path.join(destination_path, name)

    empty_project_path = os.path.join(get_base_path(), 'templates/project')
    destination_path = os.path.join(destination_path, 'src')

    if os.path.isdir(destination_path):
        WarningDisplay.could_not_make_new_project_error(
            destination_path, already_exists=True)

        return False

    try:
        shutil.copytree(empty_project_path, destination_path)

        print('Made new project\n -> {0}\'{1}\'{2}'.format(
            WarningDisplay.apply_normal_color_underlined, destination_path,
            WarningDisplay.apply_normal_color))

        print()

        open_path(destination_path)

        return True
    except IOError as error:
        WarningDisplay.could_not_make_new_project_error(
            destination_path, reason=str(error))

    return False
Пример #2
0
def make_empty_project(in_path: str, name: str = None) -> bool:
    """ Build an empty project that can be used as a starting point. """

    name = name if name is not None else "empty"

    if name is not None and len(name) > 0:
        # make sure any whitespace is replaced with dashes
        name_components = name.split(" ")
        name = "-".join(name_components).lower()

    empty_project_path = os.path.join(get_base_path(), "templates/project")
    destination_path = os.path.join(in_path, "{0}/src".format(name))

    if os.path.isdir(destination_path):
        WarningDisplay.could_not_make_new_project_error(destination_path, already_exists=True)

        return False

    try:
        shutil.copytree(empty_project_path, destination_path)

        print(
            "Made new project\n → {0}'{1}'{2}".format(
                WarningDisplay.apply_normal_color_underlined, destination_path, WarningDisplay.apply_normal_color
            )
        )

        print()

        open_path(destination_path)

        return True
    except IOError as error:
        WarningDisplay.could_not_make_new_project_error(destination_path, reason=str(error))

    return False