Coverage for python/lsst/daf/butler/script/makeButlerRepo.py : 28%

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 logging
29from lsst.daf.butler import Butler, Config
32def build_argparser():
33 """Construct an argument parser for the ``makeButlerRepo`` script.
35 Returns
36 -------
37 argparser : `argparse.ArgumentParser`
38 The argument parser that defines the script
39 command-line interface.
40 """
41 parser = argparse.ArgumentParser(description="Create an empty Gen3 Butler repository.")
42 parser.add_argument("root",
43 help=("Filesystem path for the new repository. "
44 "Will be created if it does not exist."))
45 parser.add_argument("-c", "--config",
46 help=("Path to an existing YAML config file to apply (on top of defaults)."))
47 parser.add_argument("--standalone", action="store_true", default=False,
48 help=("Include all defaults in the config file in the repo, insulating "
49 "the repo from changes in package defaults."))
50 parser.add_argument("--outfile", "-f", default=None, type=str,
51 help="Name of output file to receive repository configuration."
52 " Default is to write butler.yaml into the specified root.")
53 parser.add_argument("--verbose", "-v", action="store_true",
54 help="Turn on debug reporting.")
55 parser.add_argument("--override", "-o", action="store_true",
56 help="Allow values in the supplied config to override any root settings.")
58 return parser
61def makeButlerRepo(root, config=None, standalone=False, override=False, outfile=None):
62 """Make a new Butler repository.
64 Parameters
65 ----------
66 root : `str`
67 Location to seed a butler repository.
68 config : `str`, optional
69 Configuration to seed the repository.
70 standalone : `bool`, optional
71 If `True` a fully expanded configuration will be written.
72 override : `bool`, optional
73 If `True` a root provided in the supplied config will not be
74 overwritten.
75 outfile : `str`, optional
76 Path to output configuration. This can be left `None`
77 if the configuration is to be written to ``root``.
78 """
79 forceConfigRoot = not override
80 config = Config(config) if config is not None else None
81 Butler.makeRepo(root, config=config, standalone=standalone, forceConfigRoot=forceConfigRoot,
82 outfile=outfile)
85def main():
86 args = build_argparser().parse_args()
88 if args.verbose:
89 logging.basicConfig(level=logging.DEBUG)
91 makeButlerRepo(args.root, args.config, args.standalone, args.override, args.outfile)
92 return 0