Skip to content

Commit

Permalink
restructure of project using imports
Browse files Browse the repository at this point in the history
  • Loading branch information
iansedano committed Jun 14, 2021
1 parent 042db35 commit 134cefa
Show file tree
Hide file tree
Showing 37 changed files with 281 additions and 498 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\Philistine\\Envs\\pyQt_0\\Scripts\\python.exe"
}
Empty file added __init__.py
Empty file.
1 change: 1 addition & 0 deletions dir_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .builder import create_main
51 changes: 24 additions & 27 deletions o_creator.py → dir_builder/builder.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
from o_lexer import lex
from o_parser import parse
from o_ast import build_tree
from add_numbers import number_tree
import outline_parser

import os
from pathlib import Path
import shutil

def create(node, name):

def build_dir_structure(node, name):
"""
TODO - Is this function even needed?
"""
path = Path.cwd() / "output" / name
build_helper(node, path)


create_helper(node, path)



def create_helper(node, path):

def build_helper(node, path):
"""
"""
if node.node_type == '<ROOT>':
for n in node.children:
create_helper(n, path)
build_helper(n, path)

elif node.node_type == '<FOLDER>':
folder_path = path / node.value
if not folder_path.exists():
Path.mkdir(folder_path, parents=True)
for n in node.children:
create_helper(n, folder_path)
build_helper(n, folder_path)

elif node.node_type == '<FILE>':
file_path = path / node.value
Expand All @@ -37,13 +33,14 @@ def create_helper(node, path):
raise Exception("invalid content")
f.write(c.value)


def create_main(source, output_path, number = False):

"""
TODO - Does some of this function belong elsewhere?
"""
source = Path(source)
if not Path.is_file(source):
raise Exception("invalid file")

output_path = Path(output_path)
if output_path.exists():
shutil.rmtree(output_path)
Expand All @@ -52,14 +49,14 @@ def create_main(source, output_path, number = False):

with open(source) as mydata:
source_text = mydata.read()
lexemes = lex(source_text)
tokens = parse(lexemes)
tree_root = build_tree(tokens)
lexemes = outline_parser.lex(source_text)
tokens = outline_parser.parse(lexemes)
tree_root = outline_parser.build_tree(tokens)

if number == True:
number_tree(tree_root, 3)
outline_parser.number_tree(tree_root, 3)

create_helper(tree_root, output_path)
build_helper(tree_root, output_path)



Expand Down Expand Up @@ -91,7 +88,7 @@ def create_main(source, output_path, number = False):

print("\n\n=====STARTING=====\n\n")

create(tree1, "1")
create(tree2, "2")
create(tree3, "3")
create(tree4, "4")
build_dir_structure(tree1, "1")
build_dir_structure(tree2, "2")
build_dir_structure(tree3, "3")
build_dir_structure(tree4, "4")
File renamed without changes.
97 changes: 0 additions & 97 deletions old files/file_system_outliner.py

This file was deleted.

63 changes: 0 additions & 63 deletions old files/folder_creator.py

This file was deleted.

53 changes: 0 additions & 53 deletions old files/lexer_test.py

This file was deleted.

4 changes: 4 additions & 0 deletions outline_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .add_numbers import number_tree
from .parser import parse
from .ast import build_tree
from .lexer import lex
14 changes: 7 additions & 7 deletions add_numbers.py → outline_parser/add_numbers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Stage 4 (Optional)
Takes the root of a tree and numbers all the siblings
Takes the root of a tree and numbers all the siblings, eg:
Root
01
02
Root
01
02
03
04
01
02
03
04
"""
from counter import Counter
from utils import Counter

def number_tree(root, pad):
folders = []
Expand Down
6 changes: 4 additions & 2 deletions o_ast.py → outline_parser/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# It could potentially be added to the node so that the next stage would have
# it easy...

from outline_parser.parser import token

class Node:
def __init__(self, node_type = None, value = None):
self.node_type = node_type
Expand All @@ -15,13 +17,13 @@ def __init__(self, node_type = None, value = None):

# <ROOT> <FOLDER> <FILE> <CONTENT>

def build_tree(tok):
def build_tree(tok: token):

root = Node("<ROOT>", "root")
current_tab_level = 0

root.children, _temp = build_helper(tok, [root])

return root


Expand Down
File renamed without changes.
Loading

0 comments on commit 134cefa

Please sign in to comment.