Commit 607e13fd authored by Willi Rath's avatar Willi Rath

Merge branch '73-add-verbose-flag' into 'develop'

Resolve "Add `--verbose` flag to print out exceptions"

See merge request !90
parents 25abfe3a f5c9cff4
"""data_repo_renderer."""
import argparse
import logging
from pathlib import Path
from pkg_resources import get_distribution, DistributionNotFound
import shutil
......@@ -570,6 +571,8 @@ def cli_run_renderer(argvec=None):
"""Run renderer."""
# parse command line args
parser = argparse.ArgumentParser(description="Data repo renderer")
parser.add_argument("--verbose", action='store_true',
help="Print debugging output.")
parser.add_argument("--prefix", help=("Custom path to a directory that "
"will contain the rendered repo. "
"Defaults to: './rendered/'"))
......@@ -581,10 +584,21 @@ def cli_run_renderer(argvec=None):
args = parser.parse_args(argvec)
# extract arguments
verbose = (args.verbose is True)
util_src = Path(args.util if args.util is not None else "./util/")
prefix = Path(args.prefix if args.prefix is not None else "./rendered/")
yaml_file = Path(args.yaml_file)
# set up logging
logger = logging.getLogger("data_repo_renderer")
if verbose:
_log_level = logging.DEBUG
else:
_log_level = logging.INFO
logging.basicConfig(
level=_log_level,
format='%(asctime)s %(name)-16s: %(levelname)-8s %(message)s')
# load YAML file
with yaml_file.open() as stream:
yaml_dict = yaml.load(stream)
......@@ -601,6 +615,7 @@ def cli_run_renderer(argvec=None):
try:
f.unlink()
except Exception as e:
logger.debug("failed to unlink {} with: {}".format(f, e))
pass
_unlink_files([update_script, init_script, readme_file])
......@@ -637,12 +652,20 @@ def cli_run_renderer(argvec=None):
try:
shutil.copy(str(yaml_file), str(prefix / "meta.yaml"))
except shutil.SameFileError as e:
logger.debug("failed to copy `meta.yaml` with: {}".format(e))
pass
# copy util scripts (if any)
# copy util scripts (if any): First, remove targed util, and then copy
# source util directory.
try:
shutil.rmtree(str(util_dst))
except Exception as e:
logger.debug("failed to unlink {} with: {}".format(util_dst, e))
pass
shutil.copytree(str(util_src), str(util_dst))
except Exception as e:
logger.debug("failed to copy {} to {} with: {}".format(
util_src, util_dst, e))
pass
# make scripts executable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment