diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-09-19 23:49:43 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-09-22 20:02:22 +0200 |
commit | b4bd5581e5e1eaaf616980fac73334125a9daac2 (patch) | |
tree | 22fb673189b80fb6673b212f505be6a88c8e2182 | |
parent | 74e6f5180952b90f59056fade3100e287e847867 (diff) | |
download | clufter-b4bd5581e5e1eaaf616980fac73334125a9daac2.tar.gz clufter-b4bd5581e5e1eaaf616980fac73334125a9daac2.tar.xz clufter-b4bd5581e5e1eaaf616980fac73334125a9daac2.zip |
filters/ccs2ccsflat+ccs_flatten: nothing to do -> return orig. dump
This way, we do not have to bother with stdin and/or magic file
descriptors. At the cons' side, the equality check is little bit
complicated with a need to normalize both before-after variants,
but this only affects tests anyway (that are accommodating this
change as of now).
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r-- | __root__/ccs-flatten/flatten.c | 11 | ||||
-rw-r--r-- | filters/ccs2ccsflat.py | 9 | ||||
-rw-r--r-- | tests/filter_manager.py | 11 |
3 files changed, 16 insertions, 15 deletions
diff --git a/__root__/ccs-flatten/flatten.c b/__root__/ccs-flatten/flatten.c index 9e4940f..08eb283 100644 --- a/__root__/ccs-flatten/flatten.c +++ b/__root__/ccs-flatten/flatten.c @@ -150,14 +150,17 @@ flatten(int argc, char **argv) } while (rawmetadata); if (!rulelist) { fprintf(stderr, "No resource rules available\n"); - goto out; + if (rm) + goto out; + else + goto out_print; } load_resources(&reslist, &rulelist); build_resource_tree(&tree, &rulelist, &reslist); if (!tree) { fprintf(stderr, "No resource trees defined; nothing to do\n"); - goto out; + goto out_print; } #ifdef DEBUG fprintf(stderr, "Resources %p tree %p\n", reslist, tree); @@ -195,11 +198,13 @@ flatten(int argc, char **argv) xmlAddChild(rm, new_rb); } + out_print: xmlDocFormatDump(f, d, 1); + + out: if (f != stdout) fclose(f); - out: conf_close(); destroy_resource_tree(&tree); destroy_resources(&reslist); diff --git a/filters/ccs2ccsflat.py b/filters/ccs2ccsflat.py index 3d850ca..3ecf6c2 100644 --- a/filters/ccs2ccsflat.py +++ b/filters/ccs2ccsflat.py @@ -42,14 +42,7 @@ def ccs2ccsflat(flt_ctxt, in_obj): except OSError: raise FilterError(self, "ccs_flatten binary seems unavailable") out, err = proc.communicate() - if proc.returncode != 0: + if proc.returncode != 0 or out == '' and err != '': raise FilterError(self, "ccs_flatten exit code: {0}\n\t{1}", proc.returncode, err) - elif out == '': - # "No resource trees defined; nothing to do" - try: - with file(in_file, 'r') as f: - out = f.read() - except IOError, e: - raise FilterError(self, e.strerror + ": {0}", e.filename) return ('bytestring', out) diff --git a/tests/filter_manager.py b/tests/filter_manager.py index 85f9635..b72af44 100644 --- a/tests/filter_manager.py +++ b/tests/filter_manager.py @@ -11,6 +11,8 @@ import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) from unittest import TestCase from os.path import dirname, join +from lxml.doctestcompare import norm_whitespace + from .format_manager import FormatManager from .format import formats formats = formats.plugins @@ -52,7 +54,7 @@ class Default(FilterManagerTestCase): # XXX print result # CHECK the externalized representation matches the original with file(testfile) as f: - self.assertEqual(result, f.read()) + self.assertEqual(norm_whitespace(result), norm_whitespace(f.read())) class CompositeFormatIO(FilterManagerTestCase): @@ -84,11 +86,12 @@ class CompositeFormatIO(FilterManagerTestCase): # externalize outputs results = out_objs(('composite', ('bytestring', 'bytestring'))) # XXX print results - # CHECK resulting externalized reprezentation is, however, tha same - self.assertEqual(*results) + # CHECK resulting externalized representation is, however, tha same + self.assertEqual(*tuple(norm_whitespace for r in results)) # CHECK picked externalized representation matches the original with file(testfile) as f: - self.assertEqual(results[0], f.read()) + self.assertEqual(norm_whitespace(results[0]), + norm_whitespace(f.read())) execfile(op.join(op.dirname(__file__), '_bootstart.py')) |