Add project-tools #142
@ -1,9 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import json
|
||||
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):
|
||||
@ -24,10 +37,18 @@ def create_folder_structure(cur_path, path_dict, source_folder):
|
||||
create_folder_structure(next_path, nested_item, source_folder)
|
||||
|
||||
|
||||
current_file_folder = pathlib.Path(__file__).parent
|
||||
with open(current_file_folder / "folder_structure.json") as json_file:
|
||||
def main(args):
|
||||
parser = argparse.ArgumentParser(description="Generate project structure.")
|
||||
parser.add_argument("-t", "--target", type=valid_dir_arg)
|
||||
args = parser.parse_args(args)
|
||||
target_folder = args.target or pathlib.Path.cwd().parent.parent
|
||||
folder_structure = pathlib.Path(__file__).parent / "folder_structure.json"
|
||||
|
||||
with open(folder_structure) as json_file:
|
||||
path_dict = json.load(json_file)
|
||||
target_folder = pathlib.Path("/tmp/pets")
|
||||
create_folder_structure(target_folder, path_dict["../../"], current_file_folder)
|
||||
print()
|
||||
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