Newer
Older

Bernhard Johannes Berger
committed
import io
import json
import http.client
import os
import os.path
import urllib.request
import xml.dom.minidom
import zipfile
# Script for generating a Gitlab Pages site that serves all existing EvoAl
# Update Sites for Eclipse.
SERVER=os.environ.get('CI_SERVER_HOST')
PROJECT=os.environ.get('CI_PROJECT_ID')
TOKEN=os.environ.get('CI_JOB_TOKEN')
BASE_URL="/api/v4/projects/%s/repository/" % (PROJECT,)
connection = http.client.HTTPSConnection(SERVER)
headers = {'JOB_TOKEN': TOKEN}
if not os.path.exists("public"):
os.makedirs("public")
branches = []
# print branches
connection.request("GET", BASE_URL + "branches", headers = headers)
response = connection.getresponse()
for branch in json.loads(response.read()):
branches.append(branch['name'])

Bernhard Johannes Berger
committed
tags = []
# print tags
connection.request("GET", BASE_URL + "tags", headers = headers)
response = connection.getresponse()
for tag in json.loads(response.read()):
tags.append(branch['name'])

Bernhard Johannes Berger
committed
releases = branches + tags
for release in releases:
path = os.path.join("public", release)
if not os.path.exists(path):
os.makedirs(path)

Bernhard Johannes Berger
committed
f = open(path + "/index.html", "w")
f.write("""<html><head><title>Update Site of %s</title></head><body><h1>Remark</h1><p>This is an Eclipse Update Site and there is nothing so see here. Please add this URL to Eclipse as an Update Site.</p></body>""" % (release,))
f.close

Bernhard Johannes Berger
committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
try:
meta_url="https://gitlab.informatik.uni-bremen.de/api/v4/projects/30380/packages/maven/%s/de/evoal/languages/de.evoal.languages.releng.site/" % (release,)
# read last artifact version
meta_version_content = urllib.request.urlopen(meta_url + "maven-metadata.xml").read()
tree = xml.dom.minidom.parseString(meta_version_content)
mvn_version = tree.getElementsByTagName("version")[0].childNodes[0].nodeValue
# read last upload version
meta_content = urllib.request.urlopen(meta_url + mvn_version + "/maven-metadata.xml").read()
tree = xml.dom.minidom.parseString(meta_content)
version = tree.getElementsByTagName("lastUpdated")[0].childNodes[0].nodeValue
for snapshotVersion in tree.getElementsByTagName("snapshotVersion"):
if snapshotVersion.getElementsByTagName("extension")[0].childNodes[0].nodeValue != "zip":
continue
if snapshotVersion.getElementsByTagName("updated")[0].childNodes[0].nodeValue != version:
continue
artifactId = tree.getElementsByTagName("artifactId")[0].childNodes[0].nodeValue
value = snapshotVersion.getElementsByTagName("value")[0].childNodes[0].nodeValue
url = meta_url + mvn_version + "/" + artifactId + "-" + value + ".zip"
zip_response = urllib.request.urlopen(url)
zip = zipfile.ZipFile(io.BytesIO(zip_response.read()))
zip.extractall(path)
except urllib.error.HTTPError:
print ("Failed to download release %s" % (release,))
continue
f = open("public/index.html", "w")
f.write("<html><head><title>EvoAl Update Sites</title></head><body><h1>Available Update Sites</h1>")
f.write("<h2>Official Releases</h2><ul>")
for release in tags:
f.write("""<li><a href="https://evoal.glpages.informatik.uni-bremen.de/source/evoal-core/%s">%s</a></li>""" % (release, release))

Bernhard Johannes Berger
committed
f.write("</ul><h2>Development Versions</h2><ul>")
for release in branches:
f.write("""<li><a href="https://evoal.glpages.informatik.uni-bremen.de/source/evoal-core/%s">%s</a></li>""" % (release, release))

Bernhard Johannes Berger
committed
f.write("</ul></body></html>")
f.close()