コード例 #1
0
ファイル: main.py プロジェクト: SwingDev/pycco
def process(sources,
            preserve_paths=True,
            outdir=None,
            language=None,
            encoding="utf8",
            index=False,
            skip=False):
    """For each source file passed as argument, generate the documentation."""

    if not outdir:
        raise TypeError("Missing the required 'directory' keyword argument.")

    # Make a copy of sources given on the command line. `main()` needs the
    # original list when monitoring for changed files.
    sources = sorted(_flatten_sources(sources))

    # Proceed to generating the documentation.
    if sources:
        outdir = ensure_directory(outdir)
        css = open(path.join(outdir, "pycco.css"), "wb")
        css.write(pycco_css.encode(encoding))
        css.close()

        generated_files = []

        def next_file():
            s = sources.pop(0)
            dest = destination(s, preserve_paths=preserve_paths, outdir=outdir)

            try:
                os.makedirs(path.split(dest)[0])
            except OSError:
                pass

            try:
                with open(dest, "wb") as f:
                    f.write(
                        generate_documentation(s,
                                               preserve_paths=preserve_paths,
                                               outdir=outdir,
                                               language=language,
                                               encoding=encoding))

                print("pycco: {} -> {}".format(s, dest))
                generated_files.append(dest)
            except UnicodeDecodeError:
                if skip:
                    print("pycco [FAILURE]: {}".format(s))
                else:
                    raise

            if sources:
                next_file()

        next_file()

        if index:
            with open(path.join(outdir, "index.html"), "wb") as f:
                f.write(generate_index.generate_index(generated_files, outdir))
コード例 #2
0
ファイル: main.py プロジェクト: AllegorithmicSAS/pycco
def process(sources, theme, preserve_paths=True, outdir=None, language=None,
            encoding="utf8", index=False, skip=False):
    """For each source file passed as argument, generate the documentation."""

    if not outdir:
        raise TypeError("Missing the required 'directory' keyword argument.")

    # Make a copy of sources given on the command line. `main()` needs the
    # original list when monitoring for changed files.
    sources = sorted(_flatten_sources(sources))

    # Create HTML template for given theme
    pycco_template = pycco_resources.themes[theme][1]

    # Proceed to generating the documentation.
    if sources:
        outdir = ensure_directory(outdir)
        css = open(path.join(outdir, "pycco.css"), "wb")
        css_content = pycco_resources.themes[theme][0]
        css.write(css_content.encode(encoding))
        css.close()

        generated_files = []

        def next_file():
            s = sources.pop(0)
            dest = destination(s, preserve_paths=preserve_paths, outdir=outdir)

            try:
                os.makedirs(path.split(dest)[0])
            except OSError:
                pass

            try:
                with open(dest, "wb") as f:
                    f.write(generate_documentation(s, pycco_template, preserve_paths=preserve_paths,
                                                   outdir=outdir,
                                                   language=language,
                                                   encoding=encoding))

                print("pycco: {} -> {}".format(s, dest))
                generated_files.append(dest)
            except UnicodeDecodeError:
                if skip:
                    print("pycco [FAILURE]: {}".format(s))
                else:
                    raise

            if sources:
                next_file()
        next_file()

        if index:
            with open(path.join(outdir, "index.html"), "wb") as f:
                f.write(generate_index.generate_index(generated_files, outdir))
コード例 #3
0
ファイル: test_pycco.py プロジェクト: goosemo/pycco
def test_generate_index(path_lists, outdir_list):
    file_paths = [os.path.join(*path_list) for path_list in path_lists]
    outdir = os.path.join(*outdir_list)
    generate_index.generate_index(file_paths, outdir=outdir)
コード例 #4
0
def test_generate_index(path_lists, outdir_list):
    file_paths = [os.path.join(*path_list) for path_list in path_lists]
    outdir = os.path.join(*outdir_list)
    generate_index.generate_index(file_paths, outdir=outdir)