From 90c1263d59989363ce47468adbc288d4b1a44d27 Mon Sep 17 00:00:00 2001
From: Anatoli Babenia
Date: Jun 05 2021 19:59:33 +0000
Subject: [PATCH 1/10] Add progress bar to repo fetcher
---
diff --git a/Dockerfile b/Dockerfile
index 74f8976..0c76849 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,6 +10,7 @@ RUN dnf -y upgrade \
python3-requests \
python3-jinja2 \
python3-defusedxml \
+ python3-tqdm \
npm \
rsync
diff --git a/README.md b/README.md
index 5757296..97638d8 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ The scripts contained in this repository depend on:
* `python3-requests`
* `python3-jinja2`
* `python3-defusedxml`
+* `python3-tqdm`
## Usage
diff --git a/bin/fetch-repository-dbs.py b/bin/fetch-repository-dbs.py
index d891360..faf25a9 100755
--- a/bin/fetch-repository-dbs.py
+++ b/bin/fetch-repository-dbs.py
@@ -9,6 +9,7 @@ import os
import argparse
import hashlib
import sys
+import tqdm
repomd_xml_namespace = {
'repo': 'http://linux.duke.edu/metadata/repo',
@@ -47,10 +48,15 @@ def needs_update(local_file, remote_sha, sha_type):
def download_db(name, repomd_url, archive):
print(f'{name.ljust(padding)} Downloading file: {repomd_url} to {archive}')
- response = requests.get(repomd_url, verify=DL_VERIFY)
+ response = requests.get(repomd_url, verify=DL_VERIFY, stream=True)
response.raise_for_status()
- with open(archive, 'wb') as stream:
- stream.write(response.content)
+ with tqdm.tqdm.wrapattr(
+ open(archive, 'wb'),
+ "write",
+ desc=repomd_url.split('/')[-1],
+ total=int(response.headers.get('content-length', 0))) as stream:
+ for chunk in response.iter_content(chunk_size=1024*1024):
+ stream.write(chunk)
def decompress_db(name, archive, location):
''' Decompress the given XZ archive at the specified location. '''
From 2256d42d25cc00cbec2547dfe44934a696cfa9aa Mon Sep 17 00:00:00 2001
From: Anatoli Babenia
Date: Jun 05 2021 19:59:33 +0000
Subject: [PATCH 2/10] Add static html index for packages
---
diff --git a/bin/generate-html.py b/bin/generate-html.py
index 785ce87..0b72d43 100755
--- a/bin/generate-html.py
+++ b/bin/generate-html.py
@@ -242,19 +242,33 @@ def main():
pkg.parent_not_exist = True
print(">>> {} packages have been extracted.".format(len(packages)))
+
# Generate main user entrypoint.
- print("Generating generic pages...")
+ pkgs_list = sorted(packages.keys())
+ print("Generating index pages...")
+
+ # {"aa": ["aaargh", ...]}
+ prefix_index = {}
+ for pkg_name in pkgs_list:
+ prefix_index.setdefault(pkg_name[:2].lower(), []).append(pkg_name)
+
search = env.get_template('search.html.j2')
- search_html = search.render(date=date.today().isoformat(), package_count=len(packages))
+ search_html = search.render(date=date.today().isoformat(),
+ package_count=len(packages),
+ prefix_index=prefix_index)
save_to(os.path.join(output_dir, 'index.html'), search_html)
- # Import assets.
+ index_tpl = env.get_template('index-prefix.html.j2')
+ for prefix, names in prefix_index.items():
+ html = index_tpl.render(prefix=prefix, packages=names)
+ save_to(os.path.join(output_dir, f'index-{prefix}.html'), html)
+
+ # Copy styles and images.
assets_output = os.path.join(output_dir, 'assets')
- if not os.path.exists(assets_output):
- shutil.copytree(ASSETS_DIR, os.path.join(output_dir, 'assets'))
+ shutil.rmtree(assets_output, ignore_errors=True)
+ shutil.copytree(ASSETS_DIR, assets_output)
# Generate sitemaps
- pkgs_list = list(packages.keys())
sitemap_list = []
sitemap_dir = os.path.join(output_dir, 'sitemaps')
shutil.rmtree(sitemap_dir, ignore_errors=True)
diff --git a/templates/index-prefix.html.j2 b/templates/index-prefix.html.j2
new file mode 100644
index 0000000..9febb7e
--- /dev/null
+++ b/templates/index-prefix.html.j2
@@ -0,0 +1,41 @@
+
+
+Fedora packages
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back to the packages index ↵
+
+
+
Packages that start with "{{ prefix }}".
+
+
+
+
+
+
+
diff --git a/templates/search.html.j2 b/templates/search.html.j2
index 91d7641..93e47a1 100644
--- a/templates/search.html.j2
+++ b/templates/search.html.j2
@@ -28,10 +28,16 @@
Back to the application index ↵
-
- Last refreshed on {{ date }} ({{ package_count }} packages). Sources on
- Pagure .
+
+ {% for prefix in prefix_index %}
+ {{ prefix }}
+ {% endfor %}
+
+
+
Last refreshed on {{ date }} ({{ package_count }} packages).
+
+