Commit 0b0acd0a authored by Willi Rath's avatar Willi Rath

Add --in-place flag

parent 607e13fd
......@@ -573,6 +573,11 @@ def cli_run_renderer(argvec=None):
parser = argparse.ArgumentParser(description="Data repo renderer")
parser.add_argument("--verbose", action='store_true',
help="Print debugging output.")
parser.add_argument("--in-place", action='store_true',
help=(
"Render in place? This will render everything in "
"the parent directory of `yaml_file`. "
"Incompatible with --prefix and --util."))
parser.add_argument("--prefix", help=("Custom path to a directory that "
"will contain the rendered repo. "
"Defaults to: './rendered/'"))
......@@ -583,11 +588,27 @@ def cli_run_renderer(argvec=None):
help="Use this YAML file to render repo.")
args = parser.parse_args(argvec)
# extract arguments
# are we verbose?
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/")
# do we do in-place rerendering?
in_place = (args.in_place is True)
# check for incompatible args
if in_place and args.prefix is not None:
raise ValueError("--prefix and --in-place are incompatible.")
if in_place and args.util is not None:
raise ValueError("--util and --in-place are incompatible.")
# Read paths from cli
yaml_file = Path(args.yaml_file)
if in_place:
prefix = yaml_file.parent
util_src = prefix / "util"
else:
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/")
# set up logging
logger = logging.getLogger("data_repo_renderer")
......@@ -649,26 +670,29 @@ def cli_run_renderer(argvec=None):
ReadmeRenderer(yaml_dict, output_file=readme_file)
# copy yaml file
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
if not in_place:
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): 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
if not in_place:
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
_make_file_executable(update_script)
_make_file_executable(init_script)
list(map(_make_file_executable, util_dst.glob("*.*")))
if not in_place:
list(map(_make_file_executable, util_dst.glob("*.*")))
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