summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reslspec.xsd7
-rwxr-xr-xsample-scripts/relchk.py52
-rw-r--r--samplefeed.xml25
3 files changed, 73 insertions, 11 deletions
diff --git a/reslspec.xsd b/reslspec.xsd
index d130fb5..e96fdc0 100644
--- a/reslspec.xsd
+++ b/reslspec.xsd
@@ -11,6 +11,13 @@
<xs:restriction base="xs:anyURI" />
</xs:simpleType>
</xs:element>
+ <xs:element name="ver">
+ <xs:simpleType>
+ <xs:restriction base="xs:token">
+ <xs:pattern value="[0-9]+" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
</xs:all>
</xs:complexType>
</xs:element>
diff --git a/sample-scripts/relchk.py b/sample-scripts/relchk.py
index 2a337d3..19e6424 100755
--- a/sample-scripts/relchk.py
+++ b/sample-scripts/relchk.py
@@ -1,25 +1,71 @@
#!/usr/bin/env python3
+from collections import OrderedDict
from urllib.request import urlopen
+from humanize import naturalsize # not stdlib
try:
from lxml import etree
has_lxml = True
except ImportError:
import xml.etree.ElementTree as etree
has_lxml = False
+ from io import StringIO
# Normally this'd be passed via calling the class, but this is mostly for
# demonstration purposes only so we're not too worried about it.
-feed_url = 'https://git.square-r00t.net/RelSpec/tree/samplefeed.xml'
+feed_url = 'https://git.square-r00t.net/RelSpec/plain/samplefeed.xml'
class Release(object):
def __init__(self, feed):
self.xml = etree.fromstring(feed)
+ # The namespace map.
+ # I pine for the day when the xml module is smart enough to get this from the
+ # XML declaration itself.
+ # Seriously, Python should just adopt lxml as the core XML module.
+ # AAAANNYYYWAYS, this ugly (but working!) hack is due to much thanks to:
+ # https://stackoverflow.com/a/37409050
+ if not has_lxml:
+ self.nsmap = dict(
+ [node for _, node in etree.iterparse(StringIO(feed.decode('utf-8')),
+ events = ['start-ns'])])
+ else:
+ self.nsmap = self.xml.nsmap
+ self.channels = [i for i in self.xml.findall('channel')]
- def getChannels(self):
- self.channels = []
+ def Releases(self, channel):
+ releases = OrderedDict()
+ # Returns an ordered dict (from newest to oldest) of releases,
+ # containing all specs of the item ("release") component.
+ for c in channel.findall('item'):
+ # This just saves some typing.
+ _title = c.find('title').text
+ _ver = c.find('relspec:ver', self.nsmap).text
+ _releaseDate = c.find('pubDate')
+ _description = c.find('description').text
+ _download = c.find('enclosure').attrib['url']
+ _size = naturalsize(int(c.find('enclosure').attrib['length']))
+ _mime = c.find('enclosure').attrib['type']
+ _sha512 = c.find('guid').text
+ _sig = c.find('relspec:sig', self.nsmap).text
+ _notes = c.find('link')
+ _bugs = c.find('comments')
+ releases[_ver] = {'title': _title,
+ 'released': _releaseDate,
+ 'desc': _description,
+ 'donwload': _download,
+ 'size': _size,
+ 'mime-type': _mime,
+ 'SHA512': _sha512,
+ 'signature': _sig,
+ 'release-notes': _notes,
+ 'bug-reports': _bugs}
+ return(releases)
if __name__ == '__main__':
with urlopen(feed_url) as http:
feed = Release(http.read())
+ for c in feed.channels:
+ print('\nChannel: {0}'.format(c.find('title').text))
+ for r in feed.Releases(c):
+ print(r)
diff --git a/samplefeed.xml b/samplefeed.xml
index 42805d6..37b0c9b 100644
--- a/samplefeed.xml
+++ b/samplefeed.xml
@@ -42,7 +42,7 @@
<item>
<title>Software Name v1.2.3</title>
<description>Release v1.2.3, summary/highlights of changes</description>
- <enclosure url="https://link.to/software/releases/software-1.2.3.tar.gz"
+ <enclosure url="https://link.to/software/releases/software-1.2.3.tgz"
length="1048576"
type="application/x-gtar" />
<!-- GUID must be a SHA512 checksum of the file referenced. -->
@@ -53,7 +53,13 @@
<link>https://link.to/software/releasenotes#1.2.3</link>
<comments>https://link.to/software/bugtracker</comments>
<!-- A link to the GnuPG/PGP signature. -->
- <relspec:sig>https://link.to/software/releases/software-1.2.3.tar.gz.sig</relspec:sig>
+ <relspec:sig>https://link.to/software/releases/software-1.2.3.tgz.sig</relspec:sig>
+ <!-- A version string - this should ONLY be the version string. -->
+ <!-- This MUST follow strict SemVer (semantic versioning) schema: -->
+ <!-- https://semver.org/ -->
+ <!-- e.g. "1.30" becomes "1.30.0". "1.2+1" becomes "1.2.1". Alpha/Beta/RC releases should be placed
+ in a separate channel dedicated to those types of releases. -->
+ <relspec:ver>1.2.3</relspec:ver>
<!-- RFC 822 timestamp of release of software version -->
<pubDate>Sun, 26 Nov 2017 00:15:00 GMT</pubDate>
</item>
@@ -61,14 +67,15 @@
<item>
<title>Software Name v1.2.0</title>
<description>Release v1.2.0, summary/highlights of changes</description>
- <enclosure url="https://link.to/software/releases/software-1.2.0.tar.gz"
+ <enclosure url="https://link.to/software/releases/software-1.2.0.tgz"
length="1001234"
type="application/x-gtar" />
<guid>6d201beeefb589b08ef0672dac82353d0cbd9ad99e1642c83a1601f3d647bcca003257b5e8f31bdc1d73fbec84fb085c79d6e2677b7ff927e823a54e789140d9</guid>
<author>author@subdomain.tld (Author Name)</author>
<link>https://link.to/software/releasenotes#1.2.0</link>
<comments>https://link.to/software/bugtracker</comments>
- <relspec:sig>https://link.to/software/releases/software-1.2.0.tar.gz.sig</relspec:sig>
+ <relspec:sig>https://link.to/software/releases/software-1.2.0.tgz.sig</relspec:sig>
+ <relspec:ver>1.2.0</relspec:ver>
<pubDate>Wed, 15 Nov 2017 00:20:00 GMT</pubDate>
</item>
@@ -99,28 +106,30 @@
<item>
<title>Plugins v1.0</title>
<description>Release v1.0, summary/highlights of changes</description>
- <enclosure url="https://link.to/software/releases/plugins-1.0.tar.gz"
+ <enclosure url="https://link.to/software/releases/plugins-1.0.tgz"
length="312"
type="application/x-gtar" />
<guid>cb872de2b8d2509c54344435ce9cb43b4faa27f97d486ff4de35af03e4919fb4ec53267caf8def06ef177d69fe0abab3c12fbdc2f267d895fd07c36a62bff4bf</guid>
<author>author@subdomain.tld (Author Name)</author>
<link>https://link.to/plugin/releasenotes/1.0</link>
<comments>https://link.to/software/bugtracker?id=plugins</comments>
- <relspec:sig>https://link.to/software/releases/plugins-1.0.tar.gz.sig</relspec:sig>
+ <relspec:sig>https://link.to/software/releases/plugins-1.0.tgz.sig</relspec:sig>
+ <relspec:ver>1.0.0</relspec:ver>
<pubDate>Sun, 26 Nov 2017 00:15:00 GMT</pubDate>
</item>
<item>
<title>Plugins v0.5</title>
<description>Release v0.5, summary/highlights of changes</description>
- <enclosure url="https://link.to/software/releases/plugins-0.5.tar.gz"
+ <enclosure url="https://link.to/software/releases/plugins-0.5.tgz"
length="128"
type="application/x-gtar" />
<guid>2257aab44b42813142aa8ac4767116ad5bd41e94a79aa0672cc962128ed4809f50ed38d35ba945a80799976c9efa9b686f28d18036134bc2bb0ac2de96ec6280</guid>
<author>author@subdomain.tld (Author Name)</author>
<link>https://link.to/plugin/releasenotes/1.0</link>
<comments>https://link.to/software/bugtracker?id=plugins</comments>
- <relspec:sig>https://link.to/software/releases/plugins-1.0.tar.gz.sig</relspec:sig>
+ <relspec:sig>https://link.to/software/releases/plugins-1.0.tgz.sig</relspec:sig>
+ <relspec:ver>0.5.0</relspec:ver>
<pubDate>Wed, 15 Nov 2017 00:20:00 GMT</pubDate>
</item>