From 5116d66561f188a7098be0f9b99b8ddb71ae0fc5 Mon Sep 17 00:00:00 2001 From: Dafydd Harries Date: Wed, 20 Mar 2013 19:36:31 -0400 Subject: refactor export_all() Make file output separate, so that we can output to different formats. --- export.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/export.py b/export.py index 9adfd62..1198f82 100644 --- a/export.py +++ b/export.py @@ -296,12 +296,6 @@ def uname_srcpkgs(data, name): return srcpkg_names def export_all(data): - outputdir = 'output' - index = {} - - if not os.path.exists(outputdir): - os.makedirs(outputdir) - # First, find all upstream names and the source packages corresponding # to them. @@ -326,12 +320,21 @@ def export_all(data): warn('bad name: %r' % name) continue + # Generator; exceptions are delayed. + templates = export_srcpkgs(data, name, srcpkgs) + yield (name, templates) + +def export_all_to_directory(data, outputdir): + index = {} + + if not os.path.exists(outputdir): + os.makedirs(outputdir) + + 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} - # Generator; exceptions are delayed. - templates = export_srcpkgs(data, name, srcpkgs) try: output(path, templates) @@ -346,7 +349,7 @@ def main(): args = sys.argv[1:] if len(args) == 0: - export_all(data) + export_all_to_directory(data, 'output') elif len(args) == 1: # XXX: assumes argument is an upstream name uname = args[0] -- cgit v1.2.3