示例#1
0
def get_file_content(file_path: str) -> str:
    output: str = ""
    with open(file_path, "r") as input_file:
        output = input_file.read()
        if not output:
            print_error("Could not read file {}. Aborting.".format(file_path))
            sys.exit(ERROR_COULD_NOT_OPEN_INPUT_FILE)
    return output
示例#2
0
def main():
    args: Args = parse(Args)
    if not args.input_file.exists():
        print_error("File {} not found. Aborting operation.".format(
            args.input_file.as_posix()))
    output: str = ""
    with open(file_path, "r") as input_file:
        content: str = input_file.read()
        output = process_document(content, args.input_file)
    print(output)
示例#3
0
    def replace_link(match: re.Match) -> str:
        filename: str = match.group(1)
        if not filename in files:
            print_error(
                "Trying to link to a nonexistent file named '{}', aborting.".
                format(filename))
            sys.exit(ERROR_LINK_TO_NONEXISTENT_FILE)

        link: str = "/".join((filename, filename)) + ".html"
        if match.group(2):
            link += f"#{match.group(2)}"

        return LINK_TEMPLATE.format(filename, link)
示例#4
0
def process_document(content: str, file_path: Path) -> str:
    output: str = ""
    project_directory: Path = find_git_root_directory(file_path)
    if not project_directory:
        print_error("Error: no documents to link to found. Aborting.")
        sys.exit(ERROR_PROJECT_DIRECTORY_NOT_FOUND)

    files = find_content_files(project_directory)
    if not files:
        LINK_LOGGER.warning(
            "Warning: no project documents found, links will need to use complete paths to the target."
        )

    output = replace_links(content, files)

    return output
示例#5
0
def main():
    args: argparse.Namespace = parse_command_line_arguments(sys.argv[1:])
    logging.basicConfig(level=logging.ERROR)
    filepaths: List[str] = [
        f for f in args.files
        if f.lower().endswith(".md") and os.path.exists(f)
    ]
    if len(filepaths) != len(args.files):
        print_error("\n".join([
            "Some files are missing or their path is incorrect.",
            "Please ensure there's no typo in the path.",
            "Aborting operation.",
        ]))
        sys.exit(ERROR_INCORRECT_FILE_PATHS)

    documents: List[ProcessedDocument] = list(map(process_file, filepaths))
    list(map(output_result, itertools.repeat(args), documents))
示例#6
0
def main():
    args = parse_command_line_arguments(sys.argv[1:])
    src: str = args.godot_directory
    target_folder_name: str = args.title
    output_folder: str = os.path.abspath(args.output)

    # Check input and output directories.
    if not os.path.exists(src):
        print_error(
            "Directory {} does not exist, aborting operation.".format(src))
        sys.exit(ERROR_GODOT_DIRECTORY_NOT_FOUND)
    if not os.path.isfile(os.path.join(src, "project.godot")):
        print_error(
            "Directory {} is not a Godot project, aborting operation.".format(
                src))
        sys.exit(ERROR_GODOT_DIRECTORY_INVALID)
    if not os.path.isdir(output_folder):
        print_error(
            "Output directory {} does not exist. Aborting operation.".format(
                output_folder))
        sys.exit(ERROR_OUTPUT_DIRECTORY_INVALID)

    with tempfile.TemporaryDirectory() as temporary_directory:
        target_directory: str = os.path.join(temporary_directory,
                                             target_folder_name)
        shutil.copytree(src,
                        target_directory,
                        ignore=shutil.ignore_patterns(".import", ".git"))
        archive_path: str = shutil.make_archive(target_folder_name, "zip",
                                                target_directory)
        if output_folder != ".":
            output_filename: str = os.path.join(output_folder,
                                                os.path.basename(archive_path))
            os.rename(archive_path, output_filename)