diff options
-rwxr-xr-x | scripts/list-nightly-builds.py | 68 | ||||
-rw-r--r-- | soupault.conf | 40 |
2 files changed, 78 insertions, 30 deletions
diff --git a/scripts/list-nightly-builds.py b/scripts/list-nightly-builds.py index e75fdde..078b599 100755 --- a/scripts/list-nightly-builds.py +++ b/scripts/list-nightly-builds.py @@ -9,6 +9,7 @@ import os import re +import sys import json import boto3 @@ -17,11 +18,9 @@ import jinja2 from functools import cmp_to_key -bucket = os.getenv("SNAPSHOTS_BUCKET") - -def make_link(s, f): - f = re.sub(r'\s+', '+', f) - return "https://s3.amazonaws.com/{0}/rolling/current/{1}".format(bucket, f) +def make_link(bucket, prefix, file): + f = re.sub(r'\s+', '+', file) + return "https://s3.amazonaws.com/{0}/{1}/{2}".format(bucket, prefix, file) def compare(l, r): try: @@ -38,30 +37,47 @@ def compare(l, r): return(-1) -s3 = boto3.client('s3') -object_listing = s3.list_objects_v2(Bucket=bucket, Prefix='rolling/current') -data = object_listing['Contents'] +def list_image_files(bucket, prefix): + s3 = boto3.client('s3') + object_listing = s3.list_objects_v2(Bucket=bucket, Prefix=prefix) + data = object_listing['Contents'] + + files = [] + for f in data: + files.append(f['Key']) + + return files + +def render_image_list(bucket, prefix, files): + file_names = list(set(map(lambda s: re.sub(r'rolling/current/(.*?)', r'\1', s), files))) + file_names.sort(reverse=True, key=cmp_to_key(compare)) -files = [] -for f in data: - files.append(f['Key']) + builds = [] -file_names = list(set(map(lambda s: re.sub(r'rolling/current/(.*?)', r'\1', s), files))) -file_names.sort(reverse=True, key=cmp_to_key(compare)) + for name in file_names: + build = {} + build['file'] = name + build['link'] = make_link(bucket, prefix, name) -builds = [] + builds.append(build) -for name in file_names: - build = {} - build['file'] = name - build['link'] = make_link('rolling', name) + tmpl = jinja2.Template(""" + <ul> + {% for b in builds %} + <li><a href="{{b.link}}">{{b.file}}</a></li> + {% endfor %} + </ul> + """) + print(tmpl.render(builds=builds)) - builds.append(build) +if __name__ == '__main__': + bucket = os.getenv("SNAPSHOTS_BUCKET") + + try: + prefix = sys.argv[1] + except: + print("Please specify directory prefix!", file=sys.stderr) + sys.exit(1) -tmpl = jinja2.Template(""" -<ul> -{% for b in builds %} - <li><a href="{{b.link}}">{{b.file}}</a></li> -{% endfor %} -</ul> -""") + files = list_image_files(bucket, prefix) + render_image_list(bucket, prefix, files) diff --git a/soupault.conf b/soupault.conf index c4059dc..4c1143a 100644 --- a/soupault.conf +++ b/soupault.conf @@ -52,13 +52,45 @@ page = "get/snapshots.md" profile = "live" -# Generates a list of nightly builds from S3 -[widgets.list-nightly-builds] - widget = "exec" - command = "scripts/list-nightly-builds.py" +## Nightly build image listing generator ## + +# Inserts containers for current and equuleus lists +# This is done here rather than inside the page so that +# we can change the branches by editing just the config. +[widgets.insert-nightly-build-containers] + widget = "insert_html" + html = """ + <div id="rolling-current"> + <h3>Current/sagitta (future 1.4.0)</h3> + </div> + <div id="rolling-equuleus"> + <h3>Equuleus (upcoming 1.3.0)</h3> + </div> + """ selector = "div#content" action = "append_child" + page = "get/nightly-builds.md" + +# Generates a list of the "current" branch builds from S3 +[widgets.list-nightly-builds-current] + widget = "exec" + command = "scripts/list-nightly-builds.py rolling/current" + selector = "div#rolling-current" + action = "append_child" page = "get/nightly-builds.md" + after = "insert-nightly-build-containers" profile = "live" +# Generates a list of the "equuleus" branch builds from S3 +[widgets.list-nightly-builds-equuleus] + widget = "exec" + command = "scripts/list-nightly-builds.py rolling/equuleus" + selector = "div#rolling-equuleus" + action = "append_child" + + page = "get/nightly-builds.md" + after = "insert-nightly-build-containers" + profile = "live" + + |