Coverage for python/lsst/daf/butler/script/dumpButlerConfig.py : 27%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3# This file is part of daf_butler.
4#
5# Developed for the LSST Data Management System.
6# This product includes software developed by the LSST Project
7# (http://www.lsst.org).
8# See the COPYRIGHT file at the top-level directory of this distribution
9# for details of code ownership.
10#
11# This program is free software: you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation, either version 3 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program. If not, see <http://www.gnu.org/licenses/>.
24__all__ = ("main",)
26import argparse
27import sys
28import logging
30from lsst.daf.butler import ButlerConfig
33def build_argparser():
34 """Construct an argument parser for the ``dumpButlerConfig`` script.
36 Returns
37 -------
38 argparser : `argparse.ArgumentParser`
39 The argument parser that defines the script
40 command-line interface.
41 """
43 parser = argparse.ArgumentParser(description="Dump either a subset or full Butler configuration to "
44 "standard output.")
45 parser.add_argument("root",
46 help="Filesystem path for an existing Butler repository or path to config file.")
47 parser.add_argument("--subset", "-s", default=None, type=str,
48 help="Subset of a configuration to report. This can be any key in the"
49 " hierarchy such as '.datastore.root' where the leading '.' specified"
50 " the delimiter for the hierarchy.")
51 parser.add_argument("--searchpath", "-p", action="append", type=str,
52 help="Additional search paths to use for configuration overrides")
53 parser.add_argument("--verbose", "-v", action="store_true",
54 help="Turn on debug reporting.")
56 return parser
59def dumpButlerConfig(root, searchPath=None, subset=None, outfh=sys.stdout):
60 """Dump a config or subset to the specified file handle.
62 Parameters
63 ----------
64 root : `str`
65 Location of butler configuration. Can be a path to a YAML
66 file or a directory containing the configuration file.
67 searchPath : `list` of `str`
68 Directory paths for resolving the locations of configuration
69 file lookups.
70 subset : `str` or `tuple` of `str`
71 Key into a subset of the configuration. If a string it should use
72 the standard notation of supplying the relevant delimiter in the
73 first character.
74 outfh
75 File descriptor to use to write the configuration content.
76 """
78 config = ButlerConfig(root, searchPaths=searchPath)
80 if subset is not None:
81 config = config[subset]
83 try:
84 config.dump(outfh)
85 except AttributeError:
86 print(config, file=outfh)
89def main():
90 args = build_argparser().parse_args()
92 if args.verbose:
93 logging.basicConfig(level=logging.DEBUG)
95 dumpButlerConfig(args.root, args.searchpath, args.subset, sys.stdout)
96 return 0