Coverage for python/lsst/daf/butler/cli/opt/options.py: 84%
Shortcuts 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
Shortcuts 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/>.
23from functools import partial
25import click
26from lsst.daf.butler.registry import CollectionType
28from ..utils import MWOptionDecorator, MWPath, split_commas, split_kv, unwrap, yaml_presets
31class CollectionTypeCallback:
33 collectionTypes = tuple(collectionType.name for collectionType in CollectionType.all())
35 @staticmethod
36 def makeCollectionTypes(context, param, value):
37 if not value:
38 # Click seems to demand that the default be an empty tuple, rather
39 # than a sentinal like None. The behavior that we want is that
40 # not passing this option at all passes all collection types, while
41 # passing it uses only the passed collection types. That works
42 # fine for now, since there's no command-line option to subtract
43 # collection types, and hence the only way to get an empty tuple
44 # is as the default.
45 return tuple(CollectionType.all())
47 return tuple(CollectionType.from_name(item) for item in split_commas(context, param, value))
50collection_type_option = MWOptionDecorator(
51 "--collection-type",
52 callback=CollectionTypeCallback.makeCollectionTypes,
53 multiple=True,
54 help="If provided, only list collections of this type.",
55 type=click.Choice(CollectionTypeCallback.collectionTypes, case_sensitive=False),
56)
59collections_option = MWOptionDecorator(
60 "--collections",
61 help=unwrap(
62 """One or more expressions that fully or partially identify
63 the collections to search for datasets. If not provided all
64 datasets are returned."""
65 ),
66 multiple=True,
67 callback=split_commas,
68)
71components_option = MWOptionDecorator(
72 "--components/--no-components",
73 default=None,
74 help=unwrap(
75 """For --components, apply all expression patterns to
76 component dataset type names as well. For --no-components,
77 never apply patterns to components. Default (where neither
78 is specified) is to apply patterns to components only if
79 their parent datasets were not matched by the expression.
80 Fully-specified component datasets (`str` or `DatasetType`
81 instances) are always included."""
82 ),
83)
86config_option = MWOptionDecorator(
87 "-c",
88 "--config",
89 callback=split_kv,
90 help="Config override, as a key-value pair.",
91 metavar="TEXT=TEXT",
92 multiple=True,
93)
96config_file_option = MWOptionDecorator(
97 "-C",
98 "--config-file",
99 help=unwrap(
100 """Path to a pex config override to be included after the
101 Instrument config overrides are applied."""
102 ),
103)
106confirm_option = MWOptionDecorator(
107 "--confirm/--no-confirm",
108 default=True,
109 help="Print expected action and a confirmation prompt before executing. Default is --confirm.",
110)
113dataset_type_option = MWOptionDecorator(
114 "-d", "--dataset-type", callback=split_commas, help="Specific DatasetType(s) to validate.", multiple=True
115)
118datasets_option = MWOptionDecorator("--datasets")
121logLevelChoices = ["CRITICAL", "ERROR", "WARNING", "INFO", "VERBOSE", "DEBUG"]
122log_level_option = MWOptionDecorator(
123 "--log-level",
124 callback=partial(
125 split_kv,
126 choice=click.Choice(logLevelChoices, case_sensitive=False),
127 normalize=True,
128 unseparated_okay=True,
129 add_to_default=True,
130 ),
131 help=f"The logging level. Supported levels are [{'|'.join(logLevelChoices)}]",
132 is_eager=True,
133 metavar="LEVEL|COMPONENT=LEVEL",
134 multiple=True,
135)
138long_log_option = MWOptionDecorator(
139 "--long-log", help="Make log messages appear in long format.", is_flag=True
140)
142log_file_option = MWOptionDecorator(
143 "--log-file",
144 default=None,
145 multiple=True,
146 callback=split_commas,
147 type=MWPath(file_okay=True, dir_okay=False, writable=True),
148 help="File(s) to write log messages. If the path ends with '.json' then"
149 " JSON log records will be written, else formatted text log records"
150 " will be written. This file can exist and records will be appended.",
151)
153log_label_option = MWOptionDecorator(
154 "--log-label",
155 default=None,
156 multiple=True,
157 callback=split_kv,
158 type=str,
159 help="Keyword=value pairs to add to MDC of log records.",
160)
162log_tty_option = MWOptionDecorator(
163 "--log-tty/--no-log-tty",
164 default=True,
165 help="Log to terminal (default). If false logging to terminal is disabled.",
166)
168options_file_option = MWOptionDecorator(
169 "--options-file",
170 "-@",
171 expose_value=False, # This option should not be forwarded
172 help=unwrap(
173 """URI to YAML file containing overrides
174 of command line options. The YAML should be organized
175 as a hierarchy with subcommand names at the top
176 level options for that subcommand below."""
177 ),
178 callback=yaml_presets,
179)
182processes_option = MWOptionDecorator(
183 "-j", "--processes", default=1, help="Number of processes to use.", type=click.IntRange(min=1)
184)
187regex_option = MWOptionDecorator("--regex")
190register_dataset_types_option = MWOptionDecorator(
191 "--register-dataset-types",
192 help=unwrap(
193 """Register DatasetTypes that do not already
194 exist in the Registry."""
195 ),
196 is_flag=True,
197)
199run_option = MWOptionDecorator("--output-run", help="The name of the run datasets should be output to.")
202transfer_option = MWOptionDecorator(
203 "-t",
204 "--transfer",
205 default="auto", # set to `None` if using `required=True`
206 help="The external data transfer mode.",
207 type=click.Choice(
208 ["auto", "link", "symlink", "hardlink", "copy", "move", "relsymlink", "direct"], case_sensitive=False
209 ),
210)
213verbose_option = MWOptionDecorator("-v", "--verbose", help="Increase verbosity.", is_flag=True)
216where_option = MWOptionDecorator("--where", help="A string expression similar to a SQL WHERE clause.")
219order_by_option = MWOptionDecorator(
220 "--order-by",
221 help=unwrap(
222 """One or more comma-separated names used to order records. Names can be dimension names,
223 metadata names optionally prefixed by a dimension name and dot, or
224 timestamp_begin/timestamp_end (with optional dimension name). To reverse ordering for a name
225 prefix it with a minus sign."""
226 ),
227 multiple=True,
228 callback=split_commas,
229)
232limit_option = MWOptionDecorator(
233 "--limit",
234 help=unwrap("Limit the number of records, by default all records are shown."),
235 type=int,
236 default=0,
237)
239offset_option = MWOptionDecorator(
240 "--offset",
241 help=unwrap("Skip initial number of records, only used when --limit is specified."),
242 type=int,
243 default=0,
244)