diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2015-11-29 15:13:11 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2015-11-29 15:13:11 -0800 |
commit | a88756a60a04f469139077268338c10af29e85df (patch) | |
tree | f7462e6ee33af2f9fa7ac0191f1a21190e309469 /gen-report-whitelist-xml.py | |
download | mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.tar.gz mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.tar.bz2 mastermirror-scripts-a88756a60a04f469139077268338c10af29e85df.zip |
Initial commit.
Copied from git+ssh://git@git.gentoo.org/infra/cfengine.git repo as:
timestamp 2015-11-29T21:57:00Z
commit 3b63da8fbbb848d5a1f7e7cd7c6989638ed0d817
No passwords, passphrases or key material is contained herein, but it
may reference the pathes to such.
Reviewed-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'gen-report-whitelist-xml.py')
-rwxr-xr-x | gen-report-whitelist-xml.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/gen-report-whitelist-xml.py b/gen-report-whitelist-xml.py new file mode 100755 index 0000000..8997e53 --- /dev/null +++ b/gen-report-whitelist-xml.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +from __future__ import unicode_literals + +import io +import os +import sys +import time +from xml.sax.saxutils import escape as escape_xml + +def grab_whitelists(whitelists_dir): + whitelists = {} + for x in os.listdir(whitelists_dir): + if x[:1] == ".": + continue + x = os.path.join(whitelists_dir, x) + if not os.path.isfile(x): + continue + whitelists[x] = [] + with io.open(x, mode='r', encoding='utf_8') as f: + for entry in f: + entry = entry.lstrip().rstrip() + if len(entry) == 0 or entry.startswith("#"): + continue + whitelists[x].append(entry.lstrip().rstrip()) + + if not whitelists[x]: + del whitelists[x] + return whitelists + +def write_report(whitelists, outf): + outf.write("""<?xml version='1.0'?> + <?xml-stylesheet href="/xsl/guide.xsl" type="text/xsl"?> + <guide link="failure.xml"> + <title>Distfiles Mirroring Whitelist Report</title> + <version>1.0</version> + <date>"""+time.asctime(time.localtime())+"""</date> + """) + outf.write("<chapter><title>White Lists</title>") + if not whitelists: + outf.write("<section><body><p>No whitelists.</p></body></section>") + for x in sorted(whitelists): + outf.write("<section><title>%s</title><body><ul>\n" % os.path.basename(x)) + whitelists[x].sort() + for y in whitelists[x]: + outf.write(" <li>%s</li>\n" % escape_xml(y)) + outf.write("</ul></body></section>\n") + outf.write("</chapter></guide>") + outf.close() + +def usage(): + sys.stderr.write("usage: %s <whitelists dir> <output file>\n" % \ + os.path.basename(sys.argv[0])) + sys.stderr.flush() + +def main(argv): + if len(argv) != 3 or \ + not os.path.isdir(argv[1]) or \ + not os.path.isdir(os.path.dirname(argv[2])) or \ + not os.access(os.path.dirname(argv[2]), os.W_OK): + usage() + return 1 + with io.open(argv[2], mode='w', encoding="utf_8") as outf: + whitelists = grab_whitelists(argv[1]) + write_report(whitelists, outf) + return os.EX_OK + +if __name__ == "__main__": + sys.exit(main(sys.argv)) |