Coverage for python/lsst/daf/butler/script/validateButlerConfiguration.py : 18%

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
28from lsst.daf.butler import Butler, ValidationError
31def processCommas(arg):
32 """Given a list that might contain strings with commas, return expanded
33 list.
35 Parameters
36 ----------
37 arg : iterable of `str`
38 Values read from command line.
40 Returns
41 -------
42 expanded : `list` of `str`
43 List where any items with commas are expanded into multiple entries.
44 """
45 expanded = []
46 if arg is None:
47 return expanded
48 for item in arg:
49 expanded.extend(item.split(","))
50 return expanded
53def build_argparser():
54 """Construct an argument parser for the ``validateButlerConfiguration``
55 script.
57 Returns
58 -------
59 argparser : `argparse.ArgumentParser`
60 The argument parser that defines the script
61 command-line interface.
62 """
63 parser = argparse.ArgumentParser(description="Validate the configuration files for a "
64 "Gen3 Butler repository.")
65 parser.add_argument("root",
66 help="Filesystem path for an existing Butler repository.")
67 parser.add_argument("--quiet", "-q", action="store_true",
68 help="Do not report individual failures.")
69 parser.add_argument("--datasettype", "-d", action="append", type=str,
70 help="Specific DatasetType(s) to validate (can be comma-separated)")
71 parser.add_argument("--ignore", "-i", action="append", type=str,
72 help="DatasetType(s) to ignore for validation (can be comma-separated)")
74 return parser
77def validateButlerConfiguration(root, datasetTypes=None, ignore=None, quiet=False):
78 """Validate a bulter configuration.
80 Parameters
81 ----------
82 root : `str`
83 Butler root to validate.
84 datasetTypes : `list` of `str`
85 Dataset types to specifically check.
86 ignore : `list` of `str`
87 Dataset types to ignore.
88 quiet : `bool`, optional
89 If `True` report pass/fail but not details.
91 Returns
92 -------
93 validates : `bool`
94 `True` if everything looks okay, `False` if there is a problem.
95 """
96 logFailures = not quiet
97 butler = Butler(config=root)
98 try:
99 butler.validateConfiguration(logFailures=logFailures, datasetTypeNames=datasetTypes,
100 ignore=ignore)
101 except ValidationError:
102 return False
104 return True
107def main():
108 args = build_argparser().parse_args()
110 # Process any commas in dataset type or ignore list
111 ignore = processCommas(args.ignore)
112 datasetTypes = processCommas(args.datasettype)
114 valid = validateButlerConfiguration(args.root, datasetTypes, ignore, args.quiet)
116 if valid:
117 print("No problems encountered with configuration.")
118 return 0
119 else:
120 return 1