diff options
author | Carlo Landmeter <clandmeter@alpinelinux.org> | 2017-12-03 12:35:10 +0000 |
---|---|---|
committer | Carlo Landmeter <clandmeter@alpinelinux.org> | 2017-12-03 12:35:10 +0000 |
commit | d08df21ec13a372ce8fbb04423d6e3a62b897303 (patch) | |
tree | 3b64b3f3f88c54dc5486424b26f32669f489e635 | |
parent | 871a74bc862f8144ef736f0fed4c65b38c6a93ab (diff) | |
download | alpine-mirror-status-d08df21ec13a372ce8fbb04423d6e3a62b897303.tar.bz2 alpine-mirror-status-d08df21ec13a372ce8fbb04423d6e3a62b897303.tar.xz |
add mirrors information
-rwxr-xr-x | generate-html.lua | 37 | ||||
-rwxr-xr-x | generate-json.lua | 2 | ||||
-rw-r--r-- | index.tpl | 42 |
3 files changed, 71 insertions, 10 deletions
diff --git a/generate-html.lua b/generate-html.lua index 25d4ddd..f6d3f63 100755 --- a/generate-html.lua +++ b/generate-html.lua @@ -4,8 +4,11 @@ local json = require("cjson") local inspect = require("inspect") local lustache = require("lustache") local utils = require("utils") +local yaml = require("lyaml") +local request = require("http.request") local conf = require("config") + function get_branches(indexes) local res = {} for k,v in ipairs(indexes.master.branch) do @@ -121,12 +124,33 @@ function get_status(fm, fb, mirror, branch, repo, arch) return res end + +function get_mirrors() + local headers, stream = assert(request.new_from_uri(conf.mirrors_yaml):go()) + if headers:get(":status") ~= "200" then + error("Failed to get mirrors yaml!") + end + local y = assert(stream:get_body_as_string()) + local mirrors = yaml.load(y) + for a,mirror in pairs(mirrors) do + mirrors[a].location = mirror.location or "Unknown" + mirrors[a].bandwidth = mirror.bandwidth or "Unknown" + for b,url in pairs(mirror.urls) do + local scheme = url:match("(.*)://*.") + mirrors[a].urls[b] = {url = url, scheme = scheme} + end + end + return mirrors +end + ---- -- build the html table -function build_tables(indexes) +function build_status_tables(indexes) local res = {} local fm = flip_mirrors(indexes.mirrors) local fb = flip_branches(indexes.master.branch) + local thead = get_branches(indexes) + table.insert(thead, 1, "branch/release") for idx,mirror in ipairs(indexes.mirrors) do local rows = {} for _,ra in ipairs(get_repo_arch(indexes)) do @@ -140,8 +164,8 @@ function build_tables(indexes) table.insert(rows, { row = row }) end res[idx] = { - url = mirror.url, tbody = rows, duration = mirror.duration, - count = mirror.count + url = mirror.url, thead = thead, tbody = rows, + duration = mirror.duration, count = mirror.count } end return res @@ -149,9 +173,10 @@ end local out_json = ("%s/%s"):format(conf.outdir, conf.mirrors_json) local indexes = json.decode(utils.read_file(out_json)) -local thead = get_branches(indexes) -table.insert(thead, 1, "branch/release") -local view = { lupdate = os.date("%c", indexes.date), mirrors = build_tables(indexes), thead = thead } +local status = build_status_tables(indexes) +local mirrors = get_mirrors() +local last_update = os.date("%c", indexes.date) +local view = { last_update = last_update, mirrors = mirrors, status = status } local tpl = utils.read_file("index.tpl") local out_html = ("%s/%s"):format(conf.outdir, conf.mirrors_html) utils.write_file(out_html, lustache:render(tpl, view)) diff --git a/generate-json.lua b/generate-json.lua index d2e7148..d710666 100755 --- a/generate-json.lua +++ b/generate-json.lua @@ -2,7 +2,7 @@ local inspect = require("inspect") local request = require("http.request") -local yaml = require("yaml") +local yaml = require("lyaml") local json = require("cjson") local utils = require("utils") local conf = require("config") @@ -35,6 +35,7 @@ padding: 0em 1em 2em 1em; max-width: 1080px; padding-bottom: 1em; + padding-top: 2em; } footer { background: #111; @@ -71,6 +72,9 @@ color: #8B0000; font-weight: bold; } + .mirrors table { + width: 100%; + } </style> </head> @@ -85,7 +89,39 @@ </header> <div id="content"> <div class="pure-g"> - {{#mirrors}} + <div class="pure-u-1"> + <table class="pure-table pure-table-striped"> + <thead> + <tr> + <th>Mirror name</th> + <th>Service urls</th> + <th>Location</th> + <th>Bandwidth</th> + </tr> + </thead> + <tbody> + {{#mirrors}} + <tr> + <td>{{name}}</td> + <td> + {{#urls}} + <a href="{{url}}">{{scheme}}</a> + {{/urls}} + </td> + <td> + <span>{{location}}</span> + </td> + <td> + <span>{{bandwidth}}</span> + </td> + </tr> + {{/mirrors}} + </tbody> + </table> + </div> + </div> + <div class="pure-g mirrors"> + {{#status}} <div class="pure-u-1"> <h3>{{url}}</h3> <div class="mirror-meta"> @@ -113,9 +149,9 @@ </tbody> </table> </div> - {{/mirrors}} + {{/status}} </div> - <div class="last-updated">Last updated: <span>{{lupdate}}</span> UTC</div> + <div class="last-updated">Last updated: <span>{{last_update}}</span> UTC</div> </div> <footer>© Copyright 2017 Alpine Linux Development Team all rights reserved</footer> </div> |