File: info.py

package info (click to toggle)
python-asdf 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,940 kB
  • sloc: python: 23,812; makefile: 123
file content (53 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Commands for displaying summaries of ASDF trees
"""

import asdf

from .main import Command

__all__ = ["info"]


class Info(Command):
    @classmethod
    def setup_arguments(cls, subparsers):
        parser = subparsers.add_parser(
            "info",
            help="Print a rendering of an ASDF tree.",
            description="""Show the contents of an ASDF file by rendering tree contents as text.
            For large files max-rows and max-cols can be used to truncate the output to improve
            readability. When a file contains more lines to display than max-rows the
            deepest parts of the tree will be hidden with a message saying how many
            rows are hidden.""",
        )

        parser.add_argument("filename", help="ASDF file to render")
        parser.add_argument(
            "--max-rows", type=int, help="Maximum number of lines to print. If not provided all lines will be shown."
        )
        parser.add_argument(
            "--max-cols", type=int, help="Maximum length of line. If not provided lines will have no length limit."
        )

        parser.add_argument(
            "--show-values",
            dest="show_values",
            action="store_true",
            help="Display primitive values in the rendered tree (by default, enabled).",
        )
        parser.add_argument("--no-show-values", dest="show_values", action="store_false")
        parser.set_defaults(show_values=True)

        parser.set_defaults(func=cls.run)

        return parser

    @classmethod
    def run(cls, args):
        info(args.filename, args.max_rows, args.max_cols, args.show_values)


def info(filename, max_rows, max_cols, show_values):
    with asdf.open(filename) as af:
        af.info(max_rows, max_cols, show_values)