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