File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 22
33
44def make_file (parent_path : str , filename : str ) -> None :
5+ """
6+ Creates a file in the given parent path
7+ with the given filename
8+ """
59 with open (f"{ parent_path } /{ filename } " , 'w' ) as f :
610 f .close ()
711
812
913def make_dir_tree (parent_path : str , tree : list ) -> None :
14+ """
15+ Creates Creates a directory tree in the given parent path
16+ with the given tree
17+ """
1018 for i in tree :
1119 if type (i ) == str :
1220 make_file (parent_path , i )
Original file line number Diff line number Diff line change 22import argparse
33
44
5- def get_args ():
5+ def get_args () -> argparse .Namespace :
6+ """
7+ Gets the commanf line arguments
8+ """
69 ap = argparse .ArgumentParser ()
710
811 ap .add_argument ('--root' , '-r' , type = str ,
@@ -27,19 +30,36 @@ def get_tree(arg: str) -> List[object]:
2730 i = 0
2831 while i < len (arg ):
2932 c = arg [i ]
33+ # Start of folder
3034 if c == '[' :
35+ # Stores contents of folder
3136 bracket_content = ''
37+ # How far into the folder tree are we?
3238 bracket_depth = 1
39+ # While still in the folder
3340 while bracket_depth > 0 :
3441 i += 1
3542 bracket_content_token = arg [i ]
43+
44+ # Another nested folder?
3645 if bracket_content_token == '[' :
37- bracket_depth += 1
46+ bracket_depth += 1 # Go 1 step deeper
47+
48+ # Folder ends?
3849 elif bracket_content_token == ']' :
39- bracket_depth -= 1
50+ bracket_depth -= 1 # Come out 1 step
51+
52+ # Still inside folder?
4053 if bracket_depth > 0 :
4154 bracket_content += bracket_content_token
55+
56+ '''
57+ Folder contents scanned,
58+ create subtree now and save under current folder
59+ '''
4260 tree .append ({current_token : get_tree (bracket_content )})
61+
62+ # Clear current folder name for next folder/file
4363 current_token = ''
4464 i += 1
4565 elif c == "+" and len (current_token ) > 0 :
You can’t perform that action at this time.
0 commit comments