Skip to content

Commit

Permalink
filters/ccs2ccsflat+ccs_flatten: nothing to do -> return orig. dump
Browse files Browse the repository at this point in the history
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ý <[email protected]>
  • Loading branch information
jnpkrn committed Sep 22, 2014
1 parent 16b7d90 commit cd23454
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 8 additions & 3 deletions __root__/ccs-flatten/flatten.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions filters/ccs2ccsflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 7 additions & 4 deletions tests/filter_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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
Expand Down Expand Up @@ -52,7 +54,7 @@ def test_run_ccs2ccsflat(self):
# 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):
Expand Down Expand Up @@ -84,11 +86,12 @@ def test_run_double_ccs2ccsflat(self):
# 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'))

0 comments on commit cd23454

Please sign in to comment.