Documentation additions. Fixes to compilation. Made true passthrough which works.

This commit is contained in:
2019-04-17 19:19:09 -07:00
parent 1093636728
commit 3922b13fb1
24 changed files with 181 additions and 9 deletions

View File

@ -8,12 +8,14 @@
import argparse
import logging
import os
import shutil
import sys
import time
from typing import Dict, List, cast
from .processchain import ProcessorChains
from .processors.processors import PassthroughException
from .metadata import MetaTree
from .template_tools import file_list, file_name, file_content, file_metadata, time_iso8601
@ -73,8 +75,11 @@ def main() -> int:
"dir-template": "default-dir.jinja2",
"filters": {},
"build-time": time.time(),
"build-datetime": time.ctime(),
"uuid-oid-root": "pixywerk",
"summary": "",
"description": "",
"author": "",
"author_email": ""
}
meta_tree = MetaTree(args.root, default_metadata)
file_list_cache = cast(Dict, {})
@ -109,9 +114,13 @@ def main() -> int:
chain = process_chains.get_chain_for_filename(os.path.join(root, f), ctx=metadata)
print("process {} -> {}".format(os.path.join(root, f), os.path.join(target_dir, chain.output_filename)))
if not args.dry_run:
with open(os.path.join(target_dir, chain.output_filename), "w") as outfile:
for line in chain.output:
outfile.write(line)
try:
with open(os.path.join(target_dir, chain.output_filename), "w") as outfile:
for line in chain.output:
outfile.write(line)
except PassthroughException:
shutil.copyfile(os.path.join(root, f), os.path.join(target_dir, chain.output_filename))
return 0

View File

@ -2,7 +2,7 @@
import os
from .processors import Processor
from .processors import Processor, PassthroughException
from ..utils import guess_mime
from typing import Iterable, Optional, Dict, cast
@ -49,7 +49,7 @@ class PassThrough(Processor):
Returns:
iterable: The post-processed output stream
"""
return input_file
raise PassthroughException("passthrough")
def extension(self, oldname: str, ctx: Optional[Dict] = None) -> str:
"""Return the mimetype of the post-processed file.

View File

@ -3,6 +3,10 @@ import abc
from typing import Iterable, Optional, Dict
class PassthroughException(Exception):
"""Raised when the processor would like the file to pass through unchanged."""
class ProcessorException(Exception): # pragma: no cover
"""A base exception class to be used by processor objects."""