diff --git a/glymur/command_line.py b/glymur/command_line.py index 62b9057..bf96293 100644 --- a/glymur/command_line.py +++ b/glymur/command_line.py @@ -2,9 +2,11 @@ Entry point for console script jp2dump. """ import argparse +import os import sys import warnings -from . import Jp2k, set_printoptions + +from . import Jp2k, set_printoptions, lib def main(): """ @@ -55,11 +57,13 @@ def main(): # JP2 metadata can be extensive, so don't print any warnings until we # are done with the metadata. - j = Jp2k(filename) - if print_full_codestream: - print(j.get_codestream(header_only=False)) + jp2 = Jp2k(filename) + if jp2._codec_format == lib.openjp2.CODEC_J2K and codestream_level == 0: + print('File: {0}'.format(os.path.basename(filename))) + elif print_full_codestream: + print(jp2.get_codestream(header_only=False)) else: - print(j) + print(jp2) # Re-emit any warnings that may have been suppressed. if len(wctx) > 0: diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index b6eca2f..73ded9c 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -1102,3 +1102,12 @@ class TestJp2dump(unittest.TestCase): actual = self.run_jp2dump(['', '-x', self.jp2file]) self.assertEqual(actual, fixtures.nemo_dump_no_codestream_no_xml) + + def test_codestream_0_with_j2k_file(self): + """-c 0 should print just a single line when used on a codestream.""" + sys.argv = ['', '-c', '0', self.j2kfile] + with patch('sys.stdout', new=StringIO()) as fake_out: + command_line.main() + actual = fake_out.getvalue().strip() + self.assertRegex(actual, "File: .*") +