From 134cefafecbf84bcfd033bc2ebaf20bce470f122 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 14 Jun 2021 08:43:53 +0200 Subject: [PATCH] restructure of project using imports --- .vscode/settings.json | 3 + __init__.py | 0 dir_builder/__init__.py | 1 + o_creator.py => dir_builder/builder.py | 51 +++++----- backwards.py => folder_encoder/backwards.py | 0 old files/file_system_outliner.py | 97 ------------------- old files/folder_creator.py | 63 ------------ old files/lexer_test.py | 53 ---------- outline_parser/__init__.py | 4 + .../add_numbers.py | 14 +-- o_ast.py => outline_parser/ast.py | 6 +- o_lexer.py => outline_parser/lexer.py | 0 o_parser.py => outline_parser/parser.py | 7 +- test.py | 69 +------------ test2.py | 71 -------------- test_files/verifier.txt | 54 ----------- test_files/verifier_master.txt | 54 ----------- tests/__init__.py | 0 tests/test.py | 63 ++++++++++++ tests/test2.py | 50 ++++++++++ .../test_input_files}/folderstruct1.txt | 0 .../test_input_files}/folderstruct2.txt | 0 .../test_input_files}/folderstruct3.txt | 0 .../test_input_files}/folderstruct4.txt | 0 tests/test_output/2/last folder/finalfile.js | 1 + tests/test_output/2/myfolder/myfile.txt | 1 + .../nextfolder/anotherfolder/myfile.txt | 1 + tests/test_output/3/last folder/finalfile.js | 1 + tests/test_output/3/myfolder/myfile.py | 3 + tests/test_output/3/myfolder/myfile.txt | 2 + .../nextfolder/anotherfolder/myfile.txt | 1 + .../3/myfolder/nextfolder/emptyfile.md | 0 tests/test_verification_files/verifier.txt | 54 +++++++++++ .../verifier_master.txt | 54 +++++++++++ utils/__init__.py | 1 + counter.py => utils/counter.py | 0 logger.py => utils/logger.py | 0 37 files changed, 281 insertions(+), 498 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 __init__.py create mode 100644 dir_builder/__init__.py rename o_creator.py => dir_builder/builder.py (71%) rename backwards.py => folder_encoder/backwards.py (100%) delete mode 100644 old files/file_system_outliner.py delete mode 100644 old files/folder_creator.py delete mode 100644 old files/lexer_test.py create mode 100644 outline_parser/__init__.py rename add_numbers.py => outline_parser/add_numbers.py (89%) rename o_ast.py => outline_parser/ast.py (95%) rename o_lexer.py => outline_parser/lexer.py (100%) rename o_parser.py => outline_parser/parser.py (97%) delete mode 100644 test2.py delete mode 100644 test_files/verifier.txt delete mode 100644 test_files/verifier_master.txt create mode 100644 tests/__init__.py create mode 100644 tests/test.py create mode 100644 tests/test2.py rename {test_files => tests/test_input_files}/folderstruct1.txt (100%) rename {test_files => tests/test_input_files}/folderstruct2.txt (100%) rename {test_files => tests/test_input_files}/folderstruct3.txt (100%) rename {test_files => tests/test_input_files}/folderstruct4.txt (100%) create mode 100644 tests/test_output/2/last folder/finalfile.js create mode 100644 tests/test_output/2/myfolder/myfile.txt create mode 100644 tests/test_output/2/myfolder/nextfolder/anotherfolder/myfile.txt create mode 100644 tests/test_output/3/last folder/finalfile.js create mode 100644 tests/test_output/3/myfolder/myfile.py create mode 100644 tests/test_output/3/myfolder/myfile.txt create mode 100644 tests/test_output/3/myfolder/nextfolder/anotherfolder/myfile.txt create mode 100644 tests/test_output/3/myfolder/nextfolder/emptyfile.md create mode 100644 tests/test_verification_files/verifier.txt create mode 100644 tests/test_verification_files/verifier_master.txt create mode 100644 utils/__init__.py rename counter.py => utils/counter.py (100%) rename logger.py => utils/logger.py (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7e26029 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\Philistine\\Envs\\pyQt_0\\Scripts\\python.exe" +} \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dir_builder/__init__.py b/dir_builder/__init__.py new file mode 100644 index 0000000..4dd19f3 --- /dev/null +++ b/dir_builder/__init__.py @@ -0,0 +1 @@ +from .builder import create_main \ No newline at end of file diff --git a/o_creator.py b/dir_builder/builder.py similarity index 71% rename from o_creator.py rename to dir_builder/builder.py index f4f5eef..daf507c 100644 --- a/o_creator.py +++ b/dir_builder/builder.py @@ -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 == '': for n in node.children: - create_helper(n, path) + build_helper(n, path) elif node.node_type == '': 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_path = path / node.value @@ -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) @@ -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) @@ -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") \ No newline at end of file + build_dir_structure(tree1, "1") + build_dir_structure(tree2, "2") + build_dir_structure(tree3, "3") + build_dir_structure(tree4, "4") \ No newline at end of file diff --git a/backwards.py b/folder_encoder/backwards.py similarity index 100% rename from backwards.py rename to folder_encoder/backwards.py diff --git a/old files/file_system_outliner.py b/old files/file_system_outliner.py deleted file mode 100644 index 08150c3..0000000 --- a/old files/file_system_outliner.py +++ /dev/null @@ -1,97 +0,0 @@ -import re -import os - - -def check_if_file(item): - - file_pattern = re.compile('[\\.].+') - - if file_pattern.search(item['name']) is not None: - return True - else: - return False - - -def parse_document(path): - - with open(path) as mydata: - data = mydata.read().split("\n") - - items = [] - - parent_file = None - parent_level = 1 - - for i, arg in enumerate(data): - - if parent_file is not None: - if not check_if_file(current_item) and current_item != parent_level: - parent_file['contents'].append - continue - - current_level = 1 - - for c in arg: - if c == '\t': - current_level += 1 - - current_item = {} - current_item['name'] = arg[current_level - 1 :] - current_item['level'] = current_level - current_item['children'] = [] - - current_item['is_file'] = check_if_file(current_item) - - if current_item['is_file']: - parent_file = current_item - parent_level = current_item['level'] - - - items.append(current_item) - - return items - -def create_nested_item_list(current_item, level, Q, sibling_list): - - while len(Q) >= 0: - print(current_item) - - if current_item is None: - break - - if current_item['level'] == level: - sibling_list.append(current_item) - previous_item = current_item - try: - current_item = Q.pop(0) - except: - break - elif current_item['level'] > level: - current_item = create_nested_item_list( - current_item, current_item['level'], Q, previous_item['children'] - ) - continue - elif current_item['level'] < level: - return current_item - - -def create_folders(root_path, base_items): - - for i in base_items: - os.mkdir(f"{root_path}\\{i['name']}") - if len(i['children']) > 0: - create_folders(f"{root_path}\\{i['name']}", i['children']) - - - -################################################# - -Q = parse_document('folderstruct2.txt') -print(Q) -base_items = [] -create_nested_item_list(Q.pop(0), 1, Q, base_items) - -for i in base_items: - print(i) - -#create_folders(os.path.abspath(''), base_items) \ No newline at end of file diff --git a/old files/folder_creator.py b/old files/folder_creator.py deleted file mode 100644 index 4ebe23a..0000000 --- a/old files/folder_creator.py +++ /dev/null @@ -1,63 +0,0 @@ -import re -import os - -def parse_document(path): - with open(path) as mydata: - data = mydata.read() - - data = data.split("\n") - items = [] - - for i, arg in enumerate(data): - current_level = 1 - - for c in arg: - if c == '\t': - current_level += 1 - - current_item = {} - current_item['name'] = arg[current_level - 1 :] - current_item['level'] = current_level - current_item['children'] = [] - - items.append(current_item) - - return items - -def create_nested_item_list(current_item, level, Q, sibling_list): - - while len(Q) >= 0: - print(current_item) - if current_item['level'] == level: - sibling_list.append(current_item) - previous_item = current_item - try: - current_item = Q.pop(0) - except: - break - elif current_item['level'] > level: - current_item = create_nested_item_list(current_item, current_item['level'], Q, previous_item['children']) - continue - elif current_item['level'] < level: - return current_item - - -def create_folders(root_path, base_items): - - for i in base_items: - os.mkdir(f"{root_path}\\{i['name']}") - if len(i['children']) > 0: - create_folders(f"{root_path}\\{i['name']}", i['children']) - - - -################################################# - -Q = parse_document('folderstruct1.txt') -base_items = [] -create_nested_item_list(Q.pop(0), 1, Q, base_items) - -for i in base_items: - print(i) - -create_folders(os.path.abspath(''), base_items) \ No newline at end of file diff --git a/old files/lexer_test.py b/old files/lexer_test.py deleted file mode 100644 index 03f1c5d..0000000 --- a/old files/lexer_test.py +++ /dev/null @@ -1,53 +0,0 @@ -from lexing import lexer -import io -import sys - -def foo(inStr): - print ("hi"+inStr) - -def test_foo(): - capturedOutput = io.StringIO() # Create StringIO object - sys.stdout = capturedOutput # and redirect stdout. - - lexemes = lexer('test_files\\folderstruct1.txt') - print_lex(lexemes) - - sys.stdout = sys.__stdout__ # Reset redirect. - print ('Captured', capturedOutput.getvalue()) # Now works as before. - - lexemes = lexer('test_files\\folderstruct1.txt') - print_lex(lexemes) - lexemes = lexer('test_files\\folderstruct2.txt') - print_lex(lexemes) - lexemes = lexer('test_files\\folderstruct3.txt') - print_lex(lexemes) - -test_foo() - - - -class TestLexer(unittest.TestCase): - """ - Our basic test class - """ - - def test_lex(self): - """ - The actual test. - Any method which starts with ``test_`` will considered as a test case. - """ - res = lexer('test_files\\folderstruct1.txt') - self.assertEqual(res, 120) - - -if __name__ == '__main__': - unittest.main() - - -if __name__ == "__main__": - lexemes = lexer('test_files\\folderstruct1.txt') - print_lex(lexemes) - lexemes = lexer('test_files\\folderstruct2.txt') - print_lex(lexemes) - lexemes = lexer('test_files\\folderstruct3.txt') - print_lex(lexemes) \ No newline at end of file diff --git a/outline_parser/__init__.py b/outline_parser/__init__.py new file mode 100644 index 0000000..1020138 --- /dev/null +++ b/outline_parser/__init__.py @@ -0,0 +1,4 @@ +from .add_numbers import number_tree +from .parser import parse +from .ast import build_tree +from .lexer import lex \ No newline at end of file diff --git a/add_numbers.py b/outline_parser/add_numbers.py similarity index 89% rename from add_numbers.py rename to outline_parser/add_numbers.py index e671edf..6deac1a 100644 --- a/add_numbers.py +++ b/outline_parser/add_numbers.py @@ -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 = [] diff --git a/o_ast.py b/outline_parser/ast.py similarity index 95% rename from o_ast.py rename to outline_parser/ast.py index 4ff17d0..5c9caf6 100644 --- a/o_ast.py +++ b/outline_parser/ast.py @@ -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 @@ -15,13 +17,13 @@ def __init__(self, node_type = None, value = None): # -def build_tree(tok): +def build_tree(tok: token): root = Node("", "root") current_tab_level = 0 root.children, _temp = build_helper(tok, [root]) - + return root diff --git a/o_lexer.py b/outline_parser/lexer.py similarity index 100% rename from o_lexer.py rename to outline_parser/lexer.py diff --git a/o_parser.py b/outline_parser/parser.py similarity index 97% rename from o_parser.py rename to outline_parser/parser.py index e3ad321..958b7d0 100644 --- a/o_parser.py +++ b/outline_parser/parser.py @@ -14,6 +14,7 @@ level or more greater than the file, is considered a file. """ +from outline_parser.lexer import Lexeme class token: def __init__( @@ -29,8 +30,8 @@ def __init__( self.line_no = line_no self.next = None -def parse(root_lex): - +def parse(root_lex: Lexeme): + flags = { 'tok_type': None, 'current_value': None, @@ -77,7 +78,7 @@ def parse(root_lex): line_no += 1 prev_tab_level = tab_level tab_level = 0 - + elif lex.tok_type == '': tab_level += 1 diff --git a/test.py b/test.py index 1ccbd4c..a0b66ad 100644 --- a/test.py +++ b/test.py @@ -1,67 +1,2 @@ -from o_lexer import lex -from o_parser import parse -from o_ast import build_tree -from o_creator import create -import os -import glob - - - -with open('test_files\\folderstruct1.txt') as mydata: - data1 = mydata.read() -with open('test_files\\folderstruct2.txt') as mydata: - data2 = mydata.read() -with open('test_files\\folderstruct3.txt') as mydata: - data3 = mydata.read() -with open('test_files\\folderstruct4.txt') as mydata: - data4 = mydata.read() - -lexemes1 = lex(data1) -lexemes2 = lex(data2) -lexemes3 = lex(data3) -lexemes4 = lex(data4) - -second_pass1 = parse(lexemes1) -second_pass2 = parse(lexemes2) -second_pass3 = parse(lexemes3) -second_pass4 = parse(lexemes4) - -tree1 = build_tree(second_pass1) -tree2 = build_tree(second_pass2) -tree3 = build_tree(second_pass3) -tree4 = build_tree(second_pass4) - -print("\n\n=====STARTING=====\n\n") - -create(tree1, "1") -create(tree2, "2") -create(tree3, "3") -create(tree4, "4") - - -path = "output" - -# for root, subdirs, files in os.walk(path): - -# for subdir in subdirs: -# new path - -open('test_files\\verifier.txt', 'w').close() - -with open('test_files\\verifier.txt', 'a') as f: - for filename in glob.iglob(path + '**/**', recursive=True): - f.write(filename) - f.write('\n') - if os.path.isfile(filename): - with open(filename) as c: - f.writelines(c) - f.write('\n') - - -with open('test_files\\verifier.txt', 'r') as v: - with open('test_files\\verifier_master.txt', 'r') as m: - if v.read() != m.read(): - raise Exception("Verification Failed!") - -print("\n\n=====================\n\nverification success!") - +import dir_builder +import tests \ No newline at end of file diff --git a/test2.py b/test2.py deleted file mode 100644 index 59b1ebd..0000000 --- a/test2.py +++ /dev/null @@ -1,71 +0,0 @@ -from o_lexer import lex -from o_parser import parse -from o_ast import build_tree -from o_creator import create_main -import os -import glob - - - -# with open('test_files\\folderstruct1.txt') as mydata: -# data1 = mydata.read() -# with open('test_files\\folderstruct2.txt') as mydata: -# data2 = mydata.read() -# with open('test_files\\folderstruct3.txt') as mydata: -# data3 = mydata.read() -# with open('test_files\\folderstruct4.txt') as mydata: -# data4 = mydata.read() - -# lexemes1 = lex(data1) -# lexemes2 = lex(data2) -# lexemes3 = lex(data3) -# lexemes4 = lex(data4) - -# second_pass1 = parse(lexemes1) -# second_pass2 = parse(lexemes2) -# second_pass3 = parse(lexemes3) -# second_pass4 = parse(lexemes4) - -# tree1 = build_tree(second_pass1) -# tree2 = build_tree(second_pass2) -# tree3 = build_tree(second_pass3) -# tree4 = build_tree(second_pass4) - -# print("\n\n=====STARTING=====\n\n") - -# create(tree1, "1") -# create(tree2, "2") -# create(tree3, "3") -# create(tree4, "4") - -create_main('test_files\\folderstruct1.txt', "output\\1", number = False) -create_main('test_files\\folderstruct2.txt', "output\\2", number = False) -create_main('test_files\\folderstruct3.txt', "output\\3", number = False) -create_main('test_files\\folderstruct4.txt', "output\\4", number = False) - -path = "output" - -# for root, subdirs, files in os.walk(path): - -# for subdir in subdirs: -# new path - -open('test_files\\verifier.txt', 'w').close() - -with open('test_files\\verifier.txt', 'a') as f: - for filename in glob.iglob(path + '**/**', recursive=True): - f.write(filename) - f.write('\n') - if os.path.isfile(filename): - with open(filename) as c: - f.writelines(c) - f.write('\n') - - -with open('test_files\\verifier.txt', 'r') as v: - with open('test_files\\verifier_master.txt', 'r') as m: - if v.read() != m.read(): - raise Exception("Verification Failed!") - -print("\n\n=====================\n\nverification success!") - diff --git a/test_files/verifier.txt b/test_files/verifier.txt deleted file mode 100644 index 4d42c2b..0000000 --- a/test_files/verifier.txt +++ /dev/null @@ -1,54 +0,0 @@ -output\ -output\1 -output\1\06-basic_syntax -output\1\07-primitive_data_types -output\1\08-arrays -output\1\09-objects -output\1\10-conditional_statements -output\1\11-functions -output\1\12-loops -output\1\13-advanced_iteration -output\1\14-manipulating_dom -output\1\15-events -output\1\16-working_with_api -output\1\17-requests -output\1\18-api_project_starter_files -output\2 -output\2\last folder -output\2\last folder\finalfile.js -helloworld -output\2\myfolder -output\2\myfolder\myfile.txt -helloworld - -output\2\myfolder\nextfolder -output\2\myfolder\nextfolder\anotherfolder -output\2\myfolder\nextfolder\anotherfolder\myfile.txt -helloworld - -output\3 -output\3\last folder -output\3\last folder\finalfile.js -console.log("hello world"); -output\3\myfolder -output\3\myfolder\myfile.py -def hi(x): - x = x * 2 - return x - -output\3\myfolder\myfile.txt -mycontents -morecontents - -output\3\myfolder\nextfolder -output\3\myfolder\nextfolder\anotherfolder -output\3\myfolder\nextfolder\anotherfolder\myfile.txt -helloworld - -output\3\myfolder\nextfolder\emptyfile.md - -output\4 -output\4\folder root -output\4\myfolder -output\4\myfolder\folder2 -output\4\myfolder\folder2\folder3 diff --git a/test_files/verifier_master.txt b/test_files/verifier_master.txt deleted file mode 100644 index 4d42c2b..0000000 --- a/test_files/verifier_master.txt +++ /dev/null @@ -1,54 +0,0 @@ -output\ -output\1 -output\1\06-basic_syntax -output\1\07-primitive_data_types -output\1\08-arrays -output\1\09-objects -output\1\10-conditional_statements -output\1\11-functions -output\1\12-loops -output\1\13-advanced_iteration -output\1\14-manipulating_dom -output\1\15-events -output\1\16-working_with_api -output\1\17-requests -output\1\18-api_project_starter_files -output\2 -output\2\last folder -output\2\last folder\finalfile.js -helloworld -output\2\myfolder -output\2\myfolder\myfile.txt -helloworld - -output\2\myfolder\nextfolder -output\2\myfolder\nextfolder\anotherfolder -output\2\myfolder\nextfolder\anotherfolder\myfile.txt -helloworld - -output\3 -output\3\last folder -output\3\last folder\finalfile.js -console.log("hello world"); -output\3\myfolder -output\3\myfolder\myfile.py -def hi(x): - x = x * 2 - return x - -output\3\myfolder\myfile.txt -mycontents -morecontents - -output\3\myfolder\nextfolder -output\3\myfolder\nextfolder\anotherfolder -output\3\myfolder\nextfolder\anotherfolder\myfile.txt -helloworld - -output\3\myfolder\nextfolder\emptyfile.md - -output\4 -output\4\folder root -output\4\myfolder -output\4\myfolder\folder2 -output\4\myfolder\folder2\folder3 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..3046278 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,63 @@ +import os +import glob + +import outline_parser +import dir_builder + + +with open('tests\\test_input_files\\folderstruct1.txt') as mydata: + data1 = mydata.read() +with open('tests\\test_input_files\\folderstruct2.txt') as mydata: + data2 = mydata.read() +with open('tests\\test_input_files\\folderstruct3.txt') as mydata: + data3 = mydata.read() +with open('tests\\test_input_files\\folderstruct4.txt') as mydata: + data4 = mydata.read() + +lexemes1 = outline_parser.lex(data1) +lexemes2 = outline_parser.lex(data2) +lexemes3 = outline_parser.lex(data3) +lexemes4 = outline_parser.lex(data4) + +second_pass1 = outline_parser.parse(lexemes1) +second_pass2 = outline_parser.parse(lexemes2) +second_pass3 = outline_parser.parse(lexemes3) +second_pass4 = outline_parser.parse(lexemes4) + +tree1 = outline_parser.build_tree(second_pass1) +tree2 = outline_parser.build_tree(second_pass2) +tree3 = outline_parser.build_tree(second_pass3) +tree4 = outline_parser.build_tree(second_pass4) + +dir_builder.builder.build_dir_structure(tree1, "1") +dir_builder.builder.build_dir_structure(tree2, "2") +dir_builder.builder.build_dir_structure(tree3, "3") +dir_builder.builder.build_dir_structure(tree4, "4") + + +path = "tests\\test_output" + +# for root, subdirs, files in os.walk(path): + +# for subdir in subdirs: +# new path + +open('tests\\test_verification_files\\verifier.txt', 'w').close() + +with open('tests\\test_verification_files\\verifier.txt', 'a') as f: + for filename in glob.iglob(path + '**/**', recursive=True): + f.write(filename) + f.write('\n') + if os.path.isfile(filename): + with open(filename) as c: + f.writelines(c) + f.write('\n') + + +with open('tests\\test_verification_files\\verifier.txt', 'r') as v: + with open('tests\\test_verification_files\\verifier_master.txt', 'r') as m: + if v.read() != m.read(): + print("=====================\nVerification Failed!\n=====================") + +print("=====================\nVerification Success!\n=====================") + diff --git a/tests/test2.py b/tests/test2.py new file mode 100644 index 0000000..8b88a75 --- /dev/null +++ b/tests/test2.py @@ -0,0 +1,50 @@ +import dir_builder + +import os +import glob + + + +dir_builder.create_main( + 'tests\\test_input_files\\folderstruct1.txt', + "tests\\test_output\\1", + number = False + ) +dir_builder.create_main( + 'tests\\test_input_files\\folderstruct2.txt', + "tests\\test_output\\2", + number = False + ) +dir_builder.create_main( + 'tests\\test_input_files\\folderstruct3.txt', + "tests\\test_output\\3", + number = False + ) +dir_builder.create_main( + 'tests\\test_input_files\\folderstruct4.txt', + "tests\\test_output\\4", + number = False + ) + +path = "tests\\test_output" + +# Clearing verification file +open('tests\\test_verification_files\\verifier.txt', 'w').close() + +with open('tests\\test_verification_files\\verifier.txt', 'a') as f: + for filename in glob.iglob(path + '**/**', recursive=True): + f.write(filename) + f.write('\n') + if os.path.isfile(filename): + with open(filename) as c: + f.writelines(c) + f.write('\n') + + +with open('tests\\test_verification_files\\verifier.txt', 'r') as v: + with open('tests\\test_verification_files\\verifier_master.txt', 'r') as m: + if v.read() != m.read(): + print("=====================\nVerification Failed!\n=====================") + +print("=====================\nVerification Success!\n=====================") + diff --git a/test_files/folderstruct1.txt b/tests/test_input_files/folderstruct1.txt similarity index 100% rename from test_files/folderstruct1.txt rename to tests/test_input_files/folderstruct1.txt diff --git a/test_files/folderstruct2.txt b/tests/test_input_files/folderstruct2.txt similarity index 100% rename from test_files/folderstruct2.txt rename to tests/test_input_files/folderstruct2.txt diff --git a/test_files/folderstruct3.txt b/tests/test_input_files/folderstruct3.txt similarity index 100% rename from test_files/folderstruct3.txt rename to tests/test_input_files/folderstruct3.txt diff --git a/test_files/folderstruct4.txt b/tests/test_input_files/folderstruct4.txt similarity index 100% rename from test_files/folderstruct4.txt rename to tests/test_input_files/folderstruct4.txt diff --git a/tests/test_output/2/last folder/finalfile.js b/tests/test_output/2/last folder/finalfile.js new file mode 100644 index 0000000..620ffd0 --- /dev/null +++ b/tests/test_output/2/last folder/finalfile.js @@ -0,0 +1 @@ +helloworld \ No newline at end of file diff --git a/tests/test_output/2/myfolder/myfile.txt b/tests/test_output/2/myfolder/myfile.txt new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/tests/test_output/2/myfolder/myfile.txt @@ -0,0 +1 @@ +helloworld diff --git a/tests/test_output/2/myfolder/nextfolder/anotherfolder/myfile.txt b/tests/test_output/2/myfolder/nextfolder/anotherfolder/myfile.txt new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/tests/test_output/2/myfolder/nextfolder/anotherfolder/myfile.txt @@ -0,0 +1 @@ +helloworld diff --git a/tests/test_output/3/last folder/finalfile.js b/tests/test_output/3/last folder/finalfile.js new file mode 100644 index 0000000..0f50426 --- /dev/null +++ b/tests/test_output/3/last folder/finalfile.js @@ -0,0 +1 @@ +console.log("hello world"); \ No newline at end of file diff --git a/tests/test_output/3/myfolder/myfile.py b/tests/test_output/3/myfolder/myfile.py new file mode 100644 index 0000000..2f393f9 --- /dev/null +++ b/tests/test_output/3/myfolder/myfile.py @@ -0,0 +1,3 @@ +def hi(x): + x = x * 2 + return x diff --git a/tests/test_output/3/myfolder/myfile.txt b/tests/test_output/3/myfolder/myfile.txt new file mode 100644 index 0000000..2224405 --- /dev/null +++ b/tests/test_output/3/myfolder/myfile.txt @@ -0,0 +1,2 @@ +mycontents +morecontents diff --git a/tests/test_output/3/myfolder/nextfolder/anotherfolder/myfile.txt b/tests/test_output/3/myfolder/nextfolder/anotherfolder/myfile.txt new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/tests/test_output/3/myfolder/nextfolder/anotherfolder/myfile.txt @@ -0,0 +1 @@ +helloworld diff --git a/tests/test_output/3/myfolder/nextfolder/emptyfile.md b/tests/test_output/3/myfolder/nextfolder/emptyfile.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_verification_files/verifier.txt b/tests/test_verification_files/verifier.txt new file mode 100644 index 0000000..a58755c --- /dev/null +++ b/tests/test_verification_files/verifier.txt @@ -0,0 +1,54 @@ +tests\test_output\ +tests\test_output\1 +tests\test_output\1\06-basic_syntax +tests\test_output\1\07-primitive_data_types +tests\test_output\1\08-arrays +tests\test_output\1\09-objects +tests\test_output\1\10-conditional_statements +tests\test_output\1\11-functions +tests\test_output\1\12-loops +tests\test_output\1\13-advanced_iteration +tests\test_output\1\14-manipulating_dom +tests\test_output\1\15-events +tests\test_output\1\16-working_with_api +tests\test_output\1\17-requests +tests\test_output\1\18-api_project_starter_files +tests\test_output\2 +tests\test_output\2\last folder +tests\test_output\2\last folder\finalfile.js +helloworld +tests\test_output\2\myfolder +tests\test_output\2\myfolder\myfile.txt +helloworld + +tests\test_output\2\myfolder\nextfolder +tests\test_output\2\myfolder\nextfolder\anotherfolder +tests\test_output\2\myfolder\nextfolder\anotherfolder\myfile.txt +helloworld + +tests\test_output\3 +tests\test_output\3\last folder +tests\test_output\3\last folder\finalfile.js +console.log("hello world"); +tests\test_output\3\myfolder +tests\test_output\3\myfolder\myfile.py +def hi(x): + x = x * 2 + return x + +tests\test_output\3\myfolder\myfile.txt +mycontents +morecontents + +tests\test_output\3\myfolder\nextfolder +tests\test_output\3\myfolder\nextfolder\anotherfolder +tests\test_output\3\myfolder\nextfolder\anotherfolder\myfile.txt +helloworld + +tests\test_output\3\myfolder\nextfolder\emptyfile.md + +tests\test_output\4 +tests\test_output\4\folder root +tests\test_output\4\myfolder +tests\test_output\4\myfolder\folder2 +tests\test_output\4\myfolder\folder2\folder3 diff --git a/tests/test_verification_files/verifier_master.txt b/tests/test_verification_files/verifier_master.txt new file mode 100644 index 0000000..a58755c --- /dev/null +++ b/tests/test_verification_files/verifier_master.txt @@ -0,0 +1,54 @@ +tests\test_output\ +tests\test_output\1 +tests\test_output\1\06-basic_syntax +tests\test_output\1\07-primitive_data_types +tests\test_output\1\08-arrays +tests\test_output\1\09-objects +tests\test_output\1\10-conditional_statements +tests\test_output\1\11-functions +tests\test_output\1\12-loops +tests\test_output\1\13-advanced_iteration +tests\test_output\1\14-manipulating_dom +tests\test_output\1\15-events +tests\test_output\1\16-working_with_api +tests\test_output\1\17-requests +tests\test_output\1\18-api_project_starter_files +tests\test_output\2 +tests\test_output\2\last folder +tests\test_output\2\last folder\finalfile.js +helloworld +tests\test_output\2\myfolder +tests\test_output\2\myfolder\myfile.txt +helloworld + +tests\test_output\2\myfolder\nextfolder +tests\test_output\2\myfolder\nextfolder\anotherfolder +tests\test_output\2\myfolder\nextfolder\anotherfolder\myfile.txt +helloworld + +tests\test_output\3 +tests\test_output\3\last folder +tests\test_output\3\last folder\finalfile.js +console.log("hello world"); +tests\test_output\3\myfolder +tests\test_output\3\myfolder\myfile.py +def hi(x): + x = x * 2 + return x + +tests\test_output\3\myfolder\myfile.txt +mycontents +morecontents + +tests\test_output\3\myfolder\nextfolder +tests\test_output\3\myfolder\nextfolder\anotherfolder +tests\test_output\3\myfolder\nextfolder\anotherfolder\myfile.txt +helloworld + +tests\test_output\3\myfolder\nextfolder\emptyfile.md + +tests\test_output\4 +tests\test_output\4\folder root +tests\test_output\4\myfolder +tests\test_output\4\myfolder\folder2 +tests\test_output\4\myfolder\folder2\folder3 diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..7718024 --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1 @@ +from .counter import Counter \ No newline at end of file diff --git a/counter.py b/utils/counter.py similarity index 100% rename from counter.py rename to utils/counter.py diff --git a/logger.py b/utils/logger.py similarity index 100% rename from logger.py rename to utils/logger.py