diff options
author | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2012-10-24 07:57:44 -0700 |
---|---|---|
committer | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2012-10-24 07:57:44 -0700 |
commit | 2361f5735493f445bce553db84ece4efab0c9d63 (patch) | |
tree | c9cac8470d04f3058da459003a637481f07249e8 | |
download | rel-html-2361f5735493f445bce553db84ece4efab0c9d63.tar.gz |
rel-html: add initial code
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
-rw-r--r-- | rel-html.cfg | 6 | ||||
-rwxr-xr-x | rel-html.py | 126 |
2 files changed, 132 insertions, 0 deletions
diff --git a/rel-html.cfg b/rel-html.cfg new file mode 100644 index 0000000..72d8d82 --- /dev/null +++ b/rel-html.cfg @@ -0,0 +1,6 @@ +[project] +rel_html_proj = compat-drivers +rel_html_stable = v3.7-rc1 +rel_html_next = next-20121008 +rel_html_url_stable = http://www.kernel.org/pub/linux/kernel/projects/backports/stable +rel_html_url_next = http://www.kernel.org/pub/linux/kernel/projects/backports diff --git a/rel-html.py b/rel-html.py new file mode 100755 index 0000000..ddf59ce --- /dev/null +++ b/rel-html.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python + +# Provided an index URL and a few project hints page this +# will spit out a shiny HTML 5 W3C compliant releases page. + +# Copyright (C) 2012 Luis R. Rodriguez <mcgrof@do-not-panic.com> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import urllib, sgmllib +import ConfigParser +import re + +class index_parser(sgmllib.SGMLParser): + "HTML index parser for software releases class." + def parse(self, s): + "Parse the given string 's'." + self.feed(s) + self.close() + + def __init__(self, verbose=0): + "Initialise an object, passing 'verbose' to the superclass." + + self.config = ConfigParser.SafeConfigParser({'rel_html_proj': 'linux', 'rel_html_url_stable': 'kernel.org'}) + self.config.read('rel-html.cfg') + self.rel_html_proj = self.config.get("project", "rel_html_proj") + self.rel_html_stable = self.config.get("project", "rel_html_stable") + self.rel_html_stable_short = self.rel_html_stable.replace('v', '') + self.rel_html_next = self.config.get("project", "rel_html_next") + self.rel_html_url_stable = self.config.get("project", "rel_html_url_stable") + '/' + self.rel_html_stable + self.rel_html_url_next = self.config.get("project", "rel_html_url_next") + sgmllib.SGMLParser.__init__(self, verbose) + self.hyperlinks = [] + self.rels = [] + self.signed = False + self.changelog = '' + self.signed_changelog = False + + def start_a(self, attributes): + "Process a hyperlink and its 'attributes'." + for name, value in attributes: + if (not value.startswith(self.rel_html_proj) and + not value.startswith('ChangeLog')): + continue + if name == "href": + self.hyperlinks.append(value) + + def get_hyperlinks(self): + "Return the list of hyperlinks." + + rel_target = self.rel_html_proj + '-' + self.rel_html_stable_short + rel_changelog = 'ChangeLog-' + self.rel_html_stable + + rels = [] + changelog = '' + latest_rel_num = 0 + rel_num = 0 + + for url in self.hyperlinks: + if (url.startswith(rel_target)): + m = re.search('(?<=' + rel_target + '-)\d+', url) + rel_num = m.group(0) + if (int(rel_num) > latest_rel_num): + latest_rel_num = int(rel_num) + + rel_target = rel_target + '-' + str(latest_rel_num) + rel_changelog = rel_changelog + '-' + str(latest_rel_num) + + for url in self.hyperlinks: + if (url.startswith(rel_target) and + url.endswith('tar.bz2')): + self.rels.append(url) + continue + + if (url.startswith(rel_target) and + url.endswith('tar.sign')): + self.signed = True + continue + + if (url.startswith(rel_target) and + url.endswith('tar.sign')): + self.signed = True + continue + + if (url.startswith(rel_changelog) and + url.endswith('.sign')): + self.signed_changelog = True + continue + + if (url.startswith(rel_changelog)): + self.changelog = url + + +def main(): + + parser = index_parser() + + f = urllib.urlopen(parser.rel_html_url_stable) + s = f.read() + + parser.parse(s) + parser.get_hyperlinks() + + if (not parser.signed): + print "No signed release found!" + + if (not parser.signed_changelog): + print "No signed release ChangeLog found!" + + # Write HTML5 base page + for rel in parser.rels: + print rel + print parser.changelog + +if __name__ == "__main__": + main() |