Coverage for python/lsst/daf/butler/cli/opt/options.py : 70%

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# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
23import click
24from functools import partial
26from ..utils import MWOptionDecorator, split_commas, split_kv, unwrap, yaml_presets
27from lsst.daf.butler.registry import CollectionType
30class CollectionTypeCallback:
32 collectionTypes = dict(CHAINED=CollectionType.CHAINED,
33 RUN=CollectionType.RUN,
34 TAGGED=CollectionType.TAGGED)
36 @staticmethod
37 def makeCollectionType(context, param, value):
38 if value is None:
39 return value
40 try:
41 return CollectionTypeCallback.collectionTypes[value.upper()]
42 except KeyError:
43 raise ValueError(f"Invalid collection type: {value}")
46collection_type_option = MWOptionDecorator("--collection-type",
47 callback=CollectionTypeCallback.makeCollectionType,
48 help="If provided, only list collections of this type.",
49 type=click.Choice(CollectionTypeCallback.collectionTypes,
50 case_sensitive=False))
52config_option = MWOptionDecorator("-c", "--config",
53 callback=split_kv,
54 help="Config override, as a key-value pair.",
55 multiple=True)
58config_file_option = MWOptionDecorator("-C", "--config-file",
59 help=unwrap("""Path to a pex config override to be included after the
60 Instrument config overrides are applied."""))
63dataset_type_option = MWOptionDecorator("-d", "--dataset-type",
64 callback=split_commas,
65 help="Specific DatasetType(s) to validate.",
66 multiple=True)
69logLevelChoices = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
70log_level_option = MWOptionDecorator("--log-level",
71 callback=partial(split_kv,
72 choice=click.Choice(logLevelChoices,
73 case_sensitive=False),
74 normalize=True,
75 unseparated_okay=True),
76 help="The logging level. "
77 f"Supported levels are [{'|'.join(logLevelChoices)}]",
78 is_eager=True,
79 metavar="LEVEL|COMPONENT=LEVEL",
80 multiple=True)
83long_log_option = MWOptionDecorator("--long-log",
84 help="Make log messages appear in long format.",
85 is_flag=True)
88regex_option = MWOptionDecorator("--regex")
91run_option = MWOptionDecorator("--output-run",
92 help="The name of the run datasets should be output to.")
95transfer_option = MWOptionDecorator("-t", "--transfer",
96 default="auto", # set to `None` if using `required=True`
97 help="The external data transfer mode.",
98 type=click.Choice(["auto", "link", "symlink", "hardlink", "copy", "move",
99 "relsymlink"],
100 case_sensitive=False))
103verbose_option = MWOptionDecorator("-v", "--verbose",
104 help="Increase verbosity.",
105 is_flag=True)
108options_file_option = MWOptionDecorator("--options-file", "-@",
109 expose_value=False, # This option should not be forwarded
110 help=unwrap("""URI to YAML file containing overrides
111 of command line options. The YAML should be organized
112 as a hierarchy with subcommand names at the top
113 level options for that subcommand below."""),
114 callback=yaml_presets)