From 197323a832082991aec0c287ee6a5b1620f6067c Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sun, 14 Aug 2022 16:53:44 +0100 Subject: Remove snapshots page --- scripts/list-snapshots.py | 80 ----------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100755 scripts/list-snapshots.py (limited to 'scripts') diff --git a/scripts/list-snapshots.py b/scripts/list-snapshots.py deleted file mode 100755 index bea96fa..0000000 --- a/scripts/list-snapshots.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 - -# Requires the following environment variables: -# SNAPSHOTS_BUCKET -# AWS_ACCESS_KEY_ID -# AWS_SECRET_ACCESS_KEY - -import os -import re -import json - -import boto3 - -import jinja2 - -from functools import cmp_to_key - -bucket = os.getenv("SNAPSHOTS_BUCKET") - -def make_link(f): - f = re.sub(r'\s+', '+', f) - return "https://s3-us.vyos.io/{0}".format(f) - -def natural_sort(iterable, reverse=False): - import re - from jinja2.runtime import Undefined - - if isinstance(iterable, Undefined) or iterable is None: - return list() - - def convert(text): - return int(text) if text.isdigit() else text.lower() - def alphanum_key(key): - return [convert(c) for c in re.split('([0-9]+)', str(key))] - - return sorted(iterable, key=alphanum_key, reverse=reverse) - - -s3 = boto3.client('s3') -object_listing = s3.list_objects_v2(Bucket=bucket, Prefix='snapshot') -data = object_listing['Contents'] - -files = [] -for f in data: - files.append(f['Key']) - -snapshot_names = set(map(lambda s: re.sub(r'snapshot/(.*?)/.*', r'\1', s), files)) - -snapshots = [] - - -for name in snapshot_names: - snapshot = {} - snapshot['name'] = name - snapshot['files'] = list(filter(lambda s: re.search(name, s), files)) - - snapshot_files = list(filter(lambda s: re.search(name, s), files)) - snapshot_files = list(map(lambda f: {'name': os.path.basename(f).strip(), 'platform': os.path.basename(os.path.dirname(f)), 'link': make_link(f)}, snapshot_files)) - - # S3 listing sometimes returns dir names among file names... filter those out. - snapshot_files = list(filter(lambda f: f['name'] != "", snapshot_files)) - - snapshot['files'] = snapshot_files - - snapshots.append(snapshot) - -snapshots = natural_sort(snapshots, reverse=True) - -tmpl = jinja2.Template(""" -{% for s in snapshots %} -

# {{s.name}}

- -{% endfor %} -""") - -print(tmpl.render(snapshots=snapshots)) -- cgit v1.2.3