memory-leaks

Still reachable: lots of words in many pages.
git clone https://git.kevinlegouguec.net/memory-leaks
Log | Files | Refs | README | LICENSE

commit 629664bd50ed4e72cffc33bf2e7082119d483469
parent 05e08f7a2aa8caa8479501ccc6123baed695a06d
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Sun, 12 Apr 2020 20:00:08 +0200

Finish fixing some files being inaccessible

Make generate-deps.py compute the list of indices instead of relying
on the list of source folders that contain text files, otherwise we
will miss intermediate folders that do not contain any file.

Remove TODO entry to maintain Makefile dependencies to scripts: that
sounds too tedious.  Let's assume that at some point the Makefile and
these scripts will be bundled together into a proper package.

Diffstat:
Mrepo/www/Makefile | 22++++++++++++----------
Mrepo/www/TODO | 3+--
Mrepo/www/generate-deps.py | 38+++++++++++++++++++++++++++++++-------
Mrepo/www/generate-index.py | 8++------
4 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/repo/www/Makefile b/repo/www/Makefile @@ -1,28 +1,30 @@ -# TODO: set dependencies to scripts correctly +# TODO: add a target for the file tree; use it in generate-* scripts. TOP_DIR = ../.. OUT_DIR = $(TOP_DIR)/public TEXT_FILES = md org dirname = $(patsubst %/,%,$(dir $(1))) +dirnames = $(sort $(call dirname,$(1))) text_patterns = $(foreach ext,$(TEXT_FILES),'$(TOP_DIR)/**.$(ext)') - -text_folders = $(sort $(call dirname,$(shell git ls-files $(text_patterns)))) -page_folders = $(patsubst $(TOP_DIR)%,$(OUT_DIR)%,$(text_folders)) -indices = $(addsuffix /index.html,$(page_folders)) +text_folders = $(call dirnames,$(shell git ls-files $(text_patterns))) all: site +# Defines $(pages) and $(indices). dependencies = deps.mk include $(dependencies) -$(dependencies): generate-deps.py $(text_folders) - python3 $< "$(TEXT_FILES)" $(OUT_DIR) +$(dependencies): $(text_folders) + ./generate-deps.py "$(TEXT_FILES)" $(OUT_DIR) site: $(pages) $(indices) -$(page_folders): +# $(text_folders) may be missing some intermediate folders since it +# only contains folders that hold some text files. Rely on the full +# list of HTML pages and indices. +$(call dirnames,$(pages) $(indices)): mkdir -p $@ $(pages): @@ -30,8 +32,8 @@ $(pages): # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html. -$(indices): $(OUT_DIR)%/index.html: $(TOP_DIR)% generate-index.py | $(OUT_DIR)% - python3 generate-index.py "$(TEXT_FILES)" "$<" $@ +$(indices): $(OUT_DIR)/%index.html: + ./generate-index.py "$(TEXT_FILES)" "$(patsubst %/,%,$*)" $@ clean: -rm $(dependencies) diff --git a/repo/www/TODO b/repo/www/TODO @@ -1,4 +1,3 @@ -- generate indices for folders containing only subfolders - set HTML title to "${blog_title} - ${folder}" - compute "leak count" on toplevel index - autogenerate nav @@ -6,4 +5,4 @@ - get stylin' - pandoc template - tufte css? at least sidenotes rather than footnotes -- do something with "tags" +- use tags somehow diff --git a/repo/www/generate-deps.py b/repo/www/generate-deps.py @@ -5,11 +5,17 @@ We want to compute: - a list of leaf pages, -- a list of auto-generated indices, -- dependencies for leaf pages: + +- a list of indices, + +- dependencies for leaf pages (READMEs excluded): OUTPUT/foo/bar.html: foo/bar.txt | OUTPUT/foo - - special case for READMEs: - OUTPUT/foo/index.html: foo/README.txt foo | OUTPUT/foo + +- dependencies for READMEs: + OUTPUT/foo/index.html: foo/README.txt foo | OUTPUT/foo + +- dependencies for autogenerated indices: + OUTPUT/foo/index.html: foo | OUTPUT/foo """ from os import path @@ -36,7 +42,8 @@ def pjoin(directory, item): def write_dependencies(deps_file, directories, top_dir, out_dir): - pages = list() + pages = [] + readmes = {} for dpath, d in directories.items(): src_dir = pjoin(top_dir, dpath) @@ -47,8 +54,7 @@ def write_dependencies(deps_file, directories, top_dir, out_dir): name, _ = path.splitext(f) if name == 'README': - html_path = path.join(html_dir, 'index.html') - print(f'{html_path}: {src_path}', file=deps_file) + readmes[dpath] = f continue html_path = path.join(html_dir, name+'.html') @@ -56,8 +62,26 @@ def write_dependencies(deps_file, directories, top_dir, out_dir): pages.append(html_path) print(file=deps_file) + + for dpath in directories: + src_dir = pjoin(top_dir, dpath) + html_dir = pjoin(out_dir, dpath) + html_path = path.join(html_dir, 'index.html') + + if dpath in readmes: + src_path = path.join(src_dir, readmes[dpath]) + print(f'{html_path}: {src_path} {src_dir} | {html_dir}', file=deps_file) + continue + + print(f'{html_path}: {src_dir} | {html_dir}', file=deps_file) + + print(file=deps_file) + print(f'pages = {" ".join(pages)}', file=deps_file) + indices = (path.join(out_dir, dpath, 'index.html') for dpath in directories) + print(f'indices = {" ".join(indices)}', file=deps_file) + def main(arguments): extensions, out_dir = parse_arguments(arguments) diff --git a/repo/www/generate-index.py b/repo/www/generate-index.py @@ -16,7 +16,7 @@ def parse_arguments(): help='File extensions to consider when recording pages.' ) parser.add_argument( - 'target', help='Folder to generate an index for.' + 'target', help='Pathspec to generate an index for.' ) parser.add_argument( 'output', help='Path to the output file.' @@ -61,13 +61,9 @@ def convert_page(content, output): def main(arguments): repo = Repo(search_parent_directories=True) - target_path = arguments.target + target = arguments.target extensions = arguments.extensions - target = path.relpath(target_path, repo.working_dir) - if target == '.': - target ='' - folders, files = list_files(extensions, target, repo) names = []