diff options
Diffstat (limited to 'repo/www/make-deps.py')
| -rwxr-xr-x | repo/www/make-deps.py | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/repo/www/make-deps.py b/repo/www/make-deps.py deleted file mode 100755 index d88d333..0000000 --- a/repo/www/make-deps.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python3 - -"""Write dependencies for all website pages in makefile syntax. - -We want to compute: - -- a list of leaf pages, -- a list of auto-generated indices, -- dependencies for leaf pages: - OUTPUT/foo/bar.html: foo/bar.txt | OUTPUT/foo - - special case for READMEs: - OUTPUT/foo/index.html: foo/README.txt foo | OUTPUT/foo -""" - -from os import path -from sys import argv, exit - -from git import Repo - -from helpers import compute_directories - - -def parse_arguments(args): - if len(args) != 3: - exit(f'Usage: {argv[0]} EXTENSIONS OUTPUT-DIR') - - return argv[1].split(), argv[2] - - -def pjoin(directory, item): - return ( - path.join(directory, item) - if item # Avoid trailing slash for top-level files. - else directory - ) - - -def write_dependencies(deps_file, directories, top_dir, out_dir): - pages = list() - indices = list() - autoindices = list() - - for dpath, d in directories.items(): - autoindex = True - - src_dir = pjoin(top_dir, dpath) - - for f in d.files: - src_path = path.join(src_dir, f) - - name, _ = path.splitext(f) - deps = [src_path] - target = pages - - if name == 'README': - name = 'index' - deps.append(src_dir) - target = indices - autoindex = False - - html_dir = pjoin(out_dir, dpath) - html_path = path.join(html_dir, name+'.html') - - print(f'{html_path}: {" ".join(deps)} | {html_dir}', file=deps_file) - target.append(html_path) - - if autoindex: - autoindices.append( - path.join(out_dir, dpath, 'index.html') - ) - - print(file=deps_file) - print(f'pages = {" ".join(pages)}', file=deps_file) - print(f'indices = {" ".join(indices)}', file=deps_file) - print(f'autoindices = {" ".join(autoindices)}', file=deps_file) - - -def main(arguments): - extensions, out_dir = parse_arguments(arguments) - - repository = Repo(search_parent_directories=True) - top_dir = path.relpath(repository.working_dir, path.curdir) - - directories = compute_directories(extensions, repository) - - with open('deps.mk', 'w') as deps: - write_dependencies(deps, directories, top_dir, out_dir) - - -if __name__ == '__main__': - main(argv) |
