Add project-tools #142
@ -1,9 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def valid_dir_arg(value):
|
||||||
|
"""Determine if the value is a valid directory"""
|
||||||
|
filepath = pathlib.Path(value)
|
||||||
|
|
||||||
|
if not filepath.exists() or not filepath.is_dir():
|
||||||
|
msg = f"Error! This is not a directory: {value}"
|
||||||
|
raise argparse.ArgumentTypeError(msg)
|
||||||
|
else:
|
||||||
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
def create_folder_structure(cur_path, path_dict, source_folder):
|
def create_folder_structure(cur_path, path_dict, source_folder):
|
||||||
@ -24,10 +37,18 @@ def create_folder_structure(cur_path, path_dict, source_folder):
|
|||||||
create_folder_structure(next_path, nested_item, source_folder)
|
create_folder_structure(next_path, nested_item, source_folder)
|
||||||
|
|
||||||
|
|
||||||
current_file_folder = pathlib.Path(__file__).parent
|
def main(args):
|
||||||
with open(current_file_folder / "folder_structure.json") as json_file:
|
parser = argparse.ArgumentParser(description="Generate project structure.")
|
||||||
path_dict = json.load(json_file)
|
parser.add_argument("-t", "--target", type=valid_dir_arg)
|
||||||
target_folder = pathlib.Path("/tmp/pets")
|
args = parser.parse_args(args)
|
||||||
create_folder_structure(target_folder, path_dict["../../"], current_file_folder)
|
target_folder = args.target or pathlib.Path.cwd().parent.parent
|
||||||
print()
|
folder_structure = pathlib.Path(__file__).parent / "folder_structure.json"
|
||||||
print("Done!")
|
|
||||||
|
with open(folder_structure) as json_file:
|
||||||
|
path_dict = json.load(json_file)
|
||||||
|
create_folder_structure(target_folder, path_dict["../../"], folder_structure.parent)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv[1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user