Skip to content
Snippets Groups Projects
testing.py 1.06 KiB
from pathlib import Path

dirs = [
    'algorithms',
    'misc',
    'contests',
    'problems'
]

def get_file_tree():
    tree = {}
    for di in dirs:
        path_list = Path(di).glob('**/*.cpp')

        for path in path_list:
            branch = str(path).split('/')

            curr = tree
            for i in branch[:-2]:
                if not i in curr:
                    curr[i] = {}
                curr = curr[i]

            if not branch[-2] in curr:
                curr[branch[-2]] = []
            curr[branch[-2]].append(str(path))

    return tree


def gen_code_latex(arr, depth):
    for i in arr:
        print('\\' + depth + '{' + i + '}')


def gen_latex(tree):
    stack = [ (tree, 0) ]
    depth = ['chapter', 'section', 'subsection']

    while len(stack) != 0:
        x, h = stack.pop()
        if type(x) == list:
            for i in x:
                gen_code_latex(x, depth[h])

        #print('\\' + depth[h] + '{' + i + '}')
        for i in x:
            stack.append((x[i], h + 1))
    


tree = get_file_tree()
#print(tree)
gen_latex(tree)