#!/usr/bin/env python
# Copyright 2014-2015 Gentoo Authors; Distributed under the GPL v2
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("""
Distfiles Mirroring Whitelist Report
1.0
"""+time.asctime(time.localtime())+"""
""")
outf.write("White Lists")
if not whitelists:
outf.write("")
for x in sorted(whitelists):
outf.write("%s\n" % os.path.basename(x))
whitelists[x].sort()
for y in whitelists[x]:
outf.write(" - %s
\n" % escape_xml(y))
outf.write("
\n")
outf.write("")
outf.close()
def usage():
sys.stderr.write("usage: %s