| 1 | #!/usr/bin/env python3 |
| 2 |
|
| 3 | import shutil |
| 4 | import os |
| 5 | import sys |
| 6 |
|
| 7 | # Path of build script |
| 8 | current_dir = os.path.realpath(os.path.dirname(__file__)) |
| 9 |
|
| 10 | # Path of build output, clear and recreate |
| 11 | buildpath = os.path.join(current_dir, "build") |
| 12 | shutil.rmtree(buildpath, ignore_errors=True) |
| 13 | os.makedirs(buildpath, exist_ok=False) |
| 14 |
|
| 15 | # Add template generator directory as top level path (lets us directly import targets.py) |
| 16 | sitepath = os.path.join(current_dir, "site") |
| 17 | sys.path.insert(0, sitepath) |
| 18 | import targets |
| 19 |
|
| 20 | files = targets.template() |
| 21 |
|
| 22 | for file in files.keys(): |
| 23 | content = files[file] |
| 24 | path = os.path.join(buildpath, file) |
| 25 | print(f"Writing file {path}") |
| 26 | os.makedirs(os.path.dirname(path), exist_ok=True) |
| 27 | buf = open(path, "wb") |
| 28 | buf.write(content) |
| 29 | buf.close() |
| 30 |
|