aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDafydd Harries <daf@rhydd.org>2013-03-20 21:14:17 -0400
committerDafydd Harries <daf@rhydd.org>2013-03-20 21:14:17 -0400
commita7b02c8875d5b26d8979c50bbfd5a81c19a9be26 (patch)
tree4d5f24b8d70df995219a6b3d9ce07a26725701dd
parent87517ba05cfe0535e36b7aec54262db5f5eb8a27 (diff)
factor out multi-file output
-rw-r--r--export.py40
1 files changed, 25 insertions, 15 deletions
diff --git a/export.py b/export.py
index 1198f82..c891cc3 100644
--- a/export.py
+++ b/export.py
@@ -290,6 +290,21 @@ def output(path, xs):
for x in xs:
f.write(str(x) + '\n')
+def output_multi(path, xs):
+ index = {}
+
+ if not os.path.exists(path):
+ os.makedirs(path)
+
+ for (name, templates) in xs:
+ fname = filename(name)
+ fpath = os.path.join(path, fname)
+ index[fname] = {'page': name, 'file': fname}
+ output(fpath, templates)
+
+ fpath = os.path.join(path, 'index.json')
+ json.dump(index, file(fpath, 'w'))
+
def uname_srcpkgs(data, name):
pkg_cps = data.cps[data.cps['Upstream-Name'] == name]
srcpkg_names = list(pkg_cps['_srcpkg'])
@@ -325,24 +340,19 @@ def export_all(data):
yield (name, templates)
def export_all_to_directory(data, outputdir):
- index = {}
-
- if not os.path.exists(outputdir):
- os.makedirs(outputdir)
+ def _export():
+ for (name, templates) in export_all(data):
+ print (name.encode('utf8') if isinstance(name, unicode) else name)
- for (name, templates) in export_all(data):
- print (name.encode('utf8') if isinstance(name, unicode) else name)
- fname = filename(name)
- path = os.path.join(outputdir, fname)
- index[fname] = {'page': name, 'file': fname}
+ try:
+ # Force errors.
+ templates = list(templates)
+ except ExportFailure, e:
+ warn('export failed: %s: %s' % (name, e.message))
- try:
- output(path, templates)
- except ExportFailure, e:
- warn('export failed: %s: %s' % (name, e.message))
+ yield(name, templates)
- path = os.path.join(outputdir, 'index.json')
- json.dump(index, file(path, 'w'))
+ output_multi(outputdir, _export())
def main():
data = PkgData()