From 32511e9278385e2d409fe2243c27f047d23846e6 Mon Sep 17 00:00:00 2001
From: Martin Bříza <m@rtinbriza.cz>
Date: Nov 11 2016 10:44:11 +0000
Subject: [PATCH 1/4] releases.json: variant is not required


---

diff --git a/getfedora.org/build/releases-json.py b/getfedora.org/build/releases-json.py
index dbeb4f1..771eded 100644
--- a/getfedora.org/build/releases-json.py
+++ b/getfedora.org/build/releases-json.py
@@ -6,11 +6,10 @@ import json
 
 output = []
 
-def hashify(version, milestone, arch, link, variant, subvariant):
+def hashify(version, milestone, arch, link, subvariant):
     return { 'version': version
            , 'arch': arch
            , 'link': link
-           , 'variant': variant
            , 'subvariant': subvariant
            }
 
@@ -33,7 +32,6 @@ for rel in releases_to_report:
                 rel.milestone,
                 img['arch'],
                 location,
-                img['variant'],
                 img['subvariant'])
         output.append(h)
 

From 4b6bb46d219ec0661936574bb858eed08e5cf1ed Mon Sep 17 00:00:00 2001
From: Martin Bříza <m@rtinbriza.cz>
Date: Nov 11 2016 10:44:24 +0000
Subject: [PATCH 2/4] releases.json: Fetch f25 final releases too


---

diff --git a/getfedora.org/build/releases-json.py b/getfedora.org/build/releases-json.py
index 771eded..c716c19 100644
--- a/getfedora.org/build/releases-json.py
+++ b/getfedora.org/build/releases-json.py
@@ -13,8 +13,10 @@ def hashify(version, milestone, arch, link, subvariant):
            , 'subvariant': subvariant
            }
 
+#FIXME futureproof
 releases_to_report = [
-      fedfind.release.get_release(25, 'Beta')
+      fedfind.release.get_release(25)
+    , fedfind.release.get_release(25, 'Beta')
     , fedfind.release.get_release(25, 'Alpha')
     , fedfind.release.get_release(24)
     , fedfind.release.get_release(24, 'Beta')

From 560c9f7738e8a980625cc0e916160e04b367b95d Mon Sep 17 00:00:00 2001
From: Martin Bříza <m@rtinbriza.cz>
Date: Nov 12 2016 23:51:56 +0000
Subject: [PATCH 3/4] releases.json: fetch checksums for the images


---

diff --git a/README.md b/README.md
index 68eba0f..e697fb9 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ This repository contains the sources for the following Fedora Websites:
 #### 1. Setup your system
 
     sudo dnf install git gettext python-genshi python-lxml python-setuptools python-dateutil \
-    python-dogpile-cache babel python-feedparser fedfind
+    python-dogpile-cache babel python-feedparser fedfind python2-requests python-pyquery
 
     sudo dnf groups install 'Web Server'
 
diff --git a/getfedora.org/build/releases-json.py b/getfedora.org/build/releases-json.py
index c716c19..8f0758b 100644
--- a/getfedora.org/build/releases-json.py
+++ b/getfedora.org/build/releases-json.py
@@ -3,8 +3,17 @@
 import fedfind.release
 import fedfind.helpers
 import json
+import os.path
+import lxml
+import requests
+from pyquery import PyQuery
+import re
+import sys
 
 output = []
+folders = set()
+checksum_files = set()
+hashes = {}
 
 def hashify(version, milestone, arch, link, subvariant):
     return { 'version': version
@@ -36,5 +45,35 @@ for rel in releases_to_report:
                 location,
                 img['subvariant'])
         output.append(h)
+        folders.add(os.path.dirname(location))
+
+for folder in folders:
+    try:
+        pq = PyQuery(folder)
+        for link in pq.items('a'):
+            if 'CHECKSUM' in link.attr('href'):
+                checksum_files.add("/".join([folder, link.attr('href')]))
+                break
+    except lxml.etree.XMLSyntaxError:
+        pass
+    except requests.exceptions.ConnectionError:
+        print >> sys.stderr, "Couldn't fetch from: %s" % (folder)
+
+for file in checksum_files:
+    checksums = requests.get(file)
+    if checksums.status_code == 200:
+        for line in checksums.content.split('\n'):
+            m = re.search('^SHA256 \((.+)\) = (.+)$', line)
+            if m:
+                hashes[m.group(1)] = m.group(2)
+
+oldoutput = list(output)
+output = list()
+for item in oldoutput:
+    if os.path.basename(item['link']) in hashes:
+        item['sha256'] = hashes[os.path.basename(item['link'])]
+    else:
+        print >> sys.stderr, "No checksum for %s" % (item['link'])
+    output.append(item)
 
 print json.dumps(output)

From 01041bfb1e04ec5c40def80c55a91a04038eeaa1 Mon Sep 17 00:00:00 2001
From: Martin Bříza <m@rtinbriza.cz>
Date: Nov 12 2016 23:52:00 +0000
Subject: [PATCH 4/4] releases.json: Try to get the size from HTTP GET Content-Length


---

diff --git a/getfedora.org/build/releases-json.py b/getfedora.org/build/releases-json.py
index 8f0758b..34adee0 100644
--- a/getfedora.org/build/releases-json.py
+++ b/getfedora.org/build/releases-json.py
@@ -74,6 +74,11 @@ for item in oldoutput:
         item['sha256'] = hashes[os.path.basename(item['link'])]
     else:
         print >> sys.stderr, "No checksum for %s" % (item['link'])
+    head = requests.head(item['link'].replace("https://download.fedoraproject.org/pub/", "https://mirrors.nic.cz/"), allow_redirects=True)
+    if head.status_code == 200 and 'Content-Length' in head.headers:
+        item['size'] = head.headers['Content-Length']
+    else:
+        print >> sys.stderr, "No size for %s" % (item['link'])
     output.append(item)
 
 print json.dumps(output)

