From 441c5b3aa3fe910993dfa2f596cf9b380ec382bf Mon Sep 17 00:00:00 2001 From: Brendan Early Date: May 24 2021 20:42:21 +0000 Subject: change file tree generation code This method has only a medium performance impact when compared to the orignal method according to my profiler --- diff --git a/bin/generate-html.py b/bin/generate-html.py index 374f84a..8e763ea 100755 --- a/bin/generate-html.py +++ b/bin/generate-html.py @@ -85,6 +85,19 @@ def save_to(path, content): with open(path, 'w') as fh: fh.write(content) +def gen_file_array(dir_representation, data=None): + if not data: + data = [] + for dir in sorted(dir_representation): + if type(dir_representation[dir]) is str: + data.append({ "name": dir, "control": "file" }) + else: + data.append({ "name": dir, "control": "dir" }) + data = gen_file_array(dir_representation[dir], data) + + data.append({ "control": "exit-list" }) + return data + def main(): # Handle command-line arguments. parser = argparse.ArgumentParser( @@ -315,6 +328,7 @@ def main(): } # Generate files page for pkg. + # Create a nested object to represent the file tree files = {} for entry in filelist.execute('SELECT * FROM filelist WHERE pkgKey = ?', (pkg_key,)): filenames = entry["filenames"].split('/') @@ -338,6 +352,8 @@ def main(): current[filename] = filetype filetype_index += 1 + # Flatten and sort the files structure for jinja + files = gen_file_array(files) # Generate changelog page for pkg. changelog = [] diff --git a/templates/package-details.html.j2 b/templates/package-details.html.j2 index 8cca2c1..2a85f6b 100644 --- a/templates/package-details.html.j2 +++ b/templates/package-details.html.j2 @@ -117,24 +117,19 @@ {% if files|length != 0 %} - {% macro gentree(files) -%} - - {%- endmacro %}

Files

- {{ gentree(files) }} +
{% endif %}