Move directory check and overwriting/creating dirs to own function

This commit is contained in:
ines 2017-03-21 02:06:53 +01:00
parent 46bc3c36b0
commit 5230ed5b98
1 changed files with 12 additions and 1 deletions

View File

@ -20,7 +20,7 @@ def package(input_dir, output_dir, force):
main_path = output_path / model_name_v
package_path = main_path / model_name
Path.mkdir(package_path, parents=True)
create_dirs(package_path, force)
shutil.copytree(input_path, package_path / model_name_v)
create_file(main_path / 'meta.json', json.dumps(meta, indent=2))
create_file(main_path / 'setup.py', TEMPLATE_SETUP.strip())
@ -40,6 +40,17 @@ def check_dirs(input_path, output_path):
util.sys_exit(output_path.as_posix(), title="Output directory not found")
def create_dirs(package_path, force):
if package_path.exists():
if force:
shutil.rmtree(package_path)
else:
util.sys_exit(package_path.as_posix(),
"Please delete the directory and try again.",
title="Package directory already exists")
Path.mkdir(package_path, parents=True)
def create_file(file_path, contents):
file_path.touch()
file_path.write_text(contents, encoding='utf-8')