summaryrefslogtreecommitdiff
path: root/src/pyssg/discovery.py
blob: 8dbbf69283ca9b2c5c08f50951d066a105c69cdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os


def get_file_list(directory: str,
                  extensions: list[str],
                  exclude: list[str]=None) -> list[str]:
    out: list[str] = []
    for root, dirs, files in os.walk(directory):
        if exclude is not None:
            dirs[:] = [d for d in dirs if d not in exclude]

        for f in files:
            if f.endswith(tuple(extensions)):
                out.append(os.path.join(root, f).replace(directory, '')[1:])

    return out


def get_dir_structure(directory: str,
                      exclude: list[str]=None) -> list[str]:
    out: list[str] = []
    for root, dirs, files in os.walk(directory):
        if exclude is not None:
            dirs[:] = [d for d in dirs if d not in exclude]

        for d in dirs:
            if root in out:
                out.remove(root)
                out.append(os.path.join(root, d))

    return [o.replace(directory, '')[1:] for o in out]