diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-12 16:20:59 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-12 16:20:59 +0800 |
commit | 007df7d07a85eac30dde8018241b3e16dfac129b (patch) | |
tree | ef0d316e49034cb7ead441e76d0cc65633c9c9fa /scripts/manifest.py | |
parent | 5973ff9d9ebfc60b922ffbe5278b4c3d25695a10 (diff) | |
download | chandra-acis-analysis-007df7d07a85eac30dde8018241b3e16dfac129b.tar.bz2 |
manifest.py: Add sub-command "show" and make it the default
Diffstat (limited to 'scripts/manifest.py')
-rwxr-xr-x | scripts/manifest.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py index aba7a64..5b476f8 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -34,10 +34,16 @@ class Manifest: if self.manifest is None: self.manifest = ruamel.yaml.comments.CommentedMap() + def dump(self): + return ruamel.yaml.dump(self.manifest, + Dumper=ruamel.yaml.RoundTripDumper) + def save(self): with open(self.filepath, "w") as f: - f.write(ruamel.yaml.dump( - self.manifest, Dumper=ruamel.yaml.RoundTripDumper)) + f.write(self.dump()) + + def show(self): + print(self.dump()) def get(self, key): """ @@ -136,6 +142,13 @@ def find_manifest(filename="manifest.yaml"): raise FileNotFoundError("cannot found manifest file: %s" % filename) +def cmd_show(args, manifest): + """ + Default sub-command "show": Show manifest contents. + """ + manifest.show() + + def cmd_get(args, manifest): """ Sub-command "get": Get the value of an item in the manifest. @@ -195,6 +208,9 @@ def main(description="Manage the observation manifest (YAML format)", subparsers = parser.add_subparsers(dest="cmd_name", title="sub-commands", help="additional help") + # sub-command: show + parser_show = subparsers.add_parser("show", help="Show manifest contents") + parser_show.set_defaults(func=cmd_show) # sub-command: get parser_get = subparsers.add_parser("get", help="Get an item from manifest") parser_get.add_argument("key", help="key of the item") @@ -232,8 +248,11 @@ def main(description="Manage the observation manifest (YAML format)", manifest = Manifest(manifest_file) - # Dispatch sub-commands to call its specified function - args.func(args, manifest) + if args.cmd_name: + # Dispatch sub-commands to call its specified function + args.func(args, manifest) + else: + cmd_show(None, manifest) if __name__ == "__main__": |