From a9a7fa115af2a32bd45f68a3caee688b4923c242 Mon Sep 17 00:00:00 2001 From: Zach Smith Date: Sat, 4 Jun 2016 14:49:15 -0400 Subject: Add -s to continue on bad files --- pycco/main.py | 34 +++++++++++++++++++++++----------- setup.py | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pycco/main.py b/pycco/main.py index 416178d..fe1a8be 100644 --- a/pycco/main.py +++ b/pycco/main.py @@ -319,7 +319,7 @@ languages = { ".sql": {"name": "sql", "symbol": "--"}, - ".sh": { "name": "bash", "symbol": "#" }, + ".sh": {"name": "bash", "symbol": "#"}, ".c": {"name": "c", "symbol": "//", "multistart": "/*", "multiend": "*/"}, @@ -482,7 +482,8 @@ def _flatten_sources(sources): return _sources -def process(sources, preserve_paths=True, outdir=None, language=None, encoding="utf8", index=False): +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: @@ -510,14 +511,20 @@ def process(sources, preserve_paths=True, outdir=None, language=None, encoding=" except OSError: pass - 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) + 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() @@ -596,6 +603,10 @@ def main(): parser.add_option('-i', '--generate_index', action='store_true', help='Generate an index.html document with sitemap content') + parser.add_option('-s', '--skip-bad-files', action='store_true', + dest='skip_bad_files', + help='Continue processing after hitting a bad file') + opts, sources = parser.parse_args() if opts.outdir == '': outdir = '.' @@ -603,7 +614,8 @@ def main(): outdir = opts.outdir process(sources, outdir=outdir, preserve_paths=opts.paths, - language=opts.language, index=opts.generate_index) + language=opts.language, index=opts.generate_index, + skip=opts.skip_bad_files) # If the -w / --watch option was present, monitor the source directories # for changes and re-generate documentation for source files whenever they diff --git a/setup.py b/setup.py index 6405ca9..c9a38e0 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="Pycco", - version="0.4.1", + version="0.5.1", description="""A Python port of Docco: the original quick-and-dirty, hundred-line-long, literate-programming-style documentation generator. """, -- cgit v1.2.1