Coverage for python/lsst/daf/butler/cli/cmd/commands.py: 56%
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/>.
22__all__ = ()
24import click
25from deprecated.sphinx import deprecated
27from ... import script
28from ..opt import (
29 collection_argument,
30 collection_type_option,
31 collections_argument,
32 collections_option,
33 components_option,
34 confirm_option,
35 dataset_type_option,
36 datasets_option,
37 destination_argument,
38 dimensions_argument,
39 directory_argument,
40 element_argument,
41 glob_argument,
42 limit_option,
43 offset_option,
44 options_file_option,
45 order_by_option,
46 query_datasets_options,
47 register_dataset_types_option,
48 repo_argument,
49 transfer_option,
50 verbose_option,
51 where_option,
52)
53from ..utils import (
54 ButlerCommand,
55 MWOptionDecorator,
56 option_section,
57 printAstropyTables,
58 split_commas,
59 to_upper,
60 typeStrAcceptsMultiple,
61 unwrap,
62 where_help,
63)
65willCreateRepoHelp = "REPO is the URI or path to the new repository. Will be created if it does not exist."
66existingRepoHelp = "REPO is the URI or path to an existing data repository root or configuration file."
69@click.command(cls=ButlerCommand, short_help="Add existing datasets to a tagged collection.")
70@repo_argument(required=True)
71@collection_argument(help="COLLECTION is the collection the datasets should be associated with.")
72@query_datasets_options(repo=False, showUri=False, useArguments=False)
73@options_file_option()
74def associate(**kwargs):
75 """Add existing datasets to a tagged collection; searches for datasets with
76 the options and adds them to the named COLLECTION.
77 """
78 script.associate(**kwargs)
81# The conversion from the import command name to the butler_import function
82# name for subcommand lookup is implemented in the cli/butler.py, in
83# funcNameToCmdName and cmdNameToFuncName. If name changes are made here they
84# must be reflected in that location. If this becomes a common pattern a better
85# mechanism should be implemented.
86@click.command("import", cls=ButlerCommand)
87@repo_argument(required=True, help=willCreateRepoHelp)
88@directory_argument(required=True)
89@transfer_option()
90@click.option(
91 "--export-file",
92 help="Name for the file that contains database information associated with the exported "
93 "datasets. If this is not an absolute path, does not exist in the current working "
94 "directory, and --dir is provided, it is assumed to be in that directory. Defaults "
95 'to "export.yaml".',
96 type=click.File("r"),
97)
98@click.option(
99 "--skip-dimensions",
100 "-s",
101 type=str,
102 multiple=True,
103 callback=split_commas,
104 metavar=typeStrAcceptsMultiple,
105 help="Dimensions that should be skipped during import",
106)
107@click.option("--reuse-ids", is_flag=True, help="Force re-use of imported dataset IDs for integer IDs.")
108@options_file_option()
109def butler_import(*args, **kwargs):
110 """Import data into a butler repository."""
111 script.butlerImport(*args, **kwargs)
114@click.command(cls=ButlerCommand)
115@repo_argument(required=True, help=willCreateRepoHelp)
116@click.option("--seed-config", help="Path to an existing YAML config file to apply (on top of defaults).")
117@click.option("--dimension-config", help="Path to an existing YAML config file with dimension configuration.")
118@click.option(
119 "--standalone",
120 is_flag=True,
121 help="Include all defaults in the config file in the repo, "
122 "insulating the repo from changes in package defaults.",
123)
124@click.option(
125 "--override", is_flag=True, help="Allow values in the supplied config to override all repo settings."
126)
127@click.option(
128 "--outfile",
129 "-f",
130 default=None,
131 type=str,
132 help="Name of output file to receive repository "
133 "configuration. Default is to write butler.yaml into the specified repo.",
134)
135@options_file_option()
136def create(*args, **kwargs):
137 """Create an empty Gen3 Butler repository."""
138 script.createRepo(*args, **kwargs)
141@click.command(short_help="Dump butler config to stdout.", cls=ButlerCommand)
142@repo_argument(required=True, help=existingRepoHelp)
143@click.option(
144 "--subset",
145 "-s",
146 type=str,
147 help="Subset of a configuration to report. This can be any key in the hierarchy such as "
148 "'.datastore.root' where the leading '.' specified the delimiter for the hierarchy.",
149)
150@click.option(
151 "--searchpath",
152 "-p",
153 type=str,
154 multiple=True,
155 callback=split_commas,
156 metavar=typeStrAcceptsMultiple,
157 help="Additional search paths to use for configuration overrides",
158)
159@click.option(
160 "--file",
161 "outfile",
162 type=click.File("w"),
163 default="-",
164 help="Print the (possibly-expanded) configuration for a repository to a file, or to stdout "
165 "by default.",
166)
167@options_file_option()
168def config_dump(*args, **kwargs):
169 """Dump either a subset or full Butler configuration to standard output."""
170 script.configDump(*args, **kwargs)
173@click.command(short_help="Validate the configuration files.", cls=ButlerCommand)
174@repo_argument(required=True, help=existingRepoHelp)
175@click.option("--quiet", "-q", is_flag=True, help="Do not report individual failures.")
176@dataset_type_option(help="Specific DatasetType(s) to validate.", multiple=True)
177@click.option(
178 "--ignore",
179 "-i",
180 type=str,
181 multiple=True,
182 callback=split_commas,
183 metavar=typeStrAcceptsMultiple,
184 help="DatasetType(s) to ignore for validation.",
185)
186@options_file_option()
187def config_validate(*args, **kwargs):
188 """Validate the configuration files for a Gen3 Butler repository."""
189 is_good = script.configValidate(*args, **kwargs)
190 if not is_good:
191 raise click.exceptions.Exit(1)
194@click.command(cls=ButlerCommand)
195@repo_argument(required=True)
196@collection_argument(
197 help=unwrap(
198 """COLLECTION is the Name of the collection to remove. If this is a tagged or
199 chained collection, datasets within the collection are not modified unless --unstore
200 is passed. If this is a run collection, --purge and --unstore must be passed, and
201 all datasets in it are fully removed from the data repository."""
202 )
203)
204@click.option(
205 "--purge",
206 help=unwrap(
207 """Permit RUN collections to be removed, fully removing datasets within them.
208 Requires --unstore as an added precaution against accidental deletion. Must not be
209 passed if the collection is not a RUN."""
210 ),
211 is_flag=True,
212)
213@click.option(
214 "--unstore",
215 help=("""Remove all datasets in the collection from all datastores in which they appear."""),
216 is_flag=True,
217)
218@click.option(
219 "--unlink",
220 help="Before removing the given `collection` unlink it from from this parent collection.",
221 multiple=True,
222 callback=split_commas,
223)
224@confirm_option()
225@options_file_option()
226@deprecated(
227 reason="Please consider using remove-collections or remove-runs instead. Will be removed after v24.",
228 version="v24.0",
229 category=FutureWarning,
230)
231def prune_collection(**kwargs):
232 """Remove a collection and possibly prune datasets within it."""
233 result = script.pruneCollection(**kwargs)
234 if result.confirm:
235 print("The following collections will be removed:")
236 result.removeTable.pprint_all(align="<")
237 doContinue = click.confirm("Continue?", default=False)
238 else:
239 doContinue = True
240 if doContinue:
241 result.onConfirmation()
242 print("Removed collections.")
243 else:
244 print("Aborted.")
247pruneDatasets_wouldRemoveMsg = unwrap(
248 """The following datasets will be removed from any datastores in which
249 they are present:"""
250)
251pruneDatasets_wouldDisassociateMsg = unwrap(
252 """The following datasets will be disassociated from {collections}
253 if they are currently present in it (which is not checked):"""
254)
255pruneDatasets_wouldDisassociateAndRemoveMsg = unwrap(
256 """The following datasets will be disassociated from
257 {collections} if they are currently present in it (which is
258 not checked), and removed from any datastores in which they
259 are present."""
260)
261pruneDatasets_willRemoveMsg = "The following datasets will be removed:"
262pruneDatasets_askContinueMsg = "Continue?"
263pruneDatasets_didRemoveAforementioned = "The datasets were removed."
264pruneDatasets_didNotRemoveAforementioned = "Did not remove the datasets."
265pruneDatasets_didRemoveMsg = "Removed the following datasets:"
266pruneDatasets_noDatasetsFound = "Did not find any datasets."
267pruneDatasets_errPurgeAndDisassociate = unwrap(
268 """"--disassociate and --purge may not be used together: --disassociate purges from just the passed TAGged
269 collections, but --purge forces disassociation from all of them. """
270)
271pruneDatasets_errQuietWithDryRun = "Can not use --quiet and --dry-run together."
272pruneDatasets_errNoCollectionRestriction = unwrap(
273 """Must indicate collections from which to prune datasets by passing COLLETION arguments (select all
274 collections by passing '*', or consider using 'butler prune-collections'), by using --purge to pass a run
275 collection, or by using --disassociate to select a tagged collection."""
276)
277pruneDatasets_errPruneOnNotRun = "Can not prune a collection that is not a RUN collection: {collection}"
278pruneDatasets_errNoOp = "No operation: one of --purge, --unstore, or --disassociate must be provided."
280disassociate_option = MWOptionDecorator(
281 "--disassociate",
282 "disassociate_tags",
283 help=unwrap(
284 """Disassociate pruned datasets from the given tagged collections. May not be used with
285 --purge."""
286 ),
287 multiple=True,
288 callback=split_commas,
289 metavar="TAG",
290)
293purge_option = MWOptionDecorator(
294 "--purge",
295 "purge_run",
296 help=unwrap(
297 """Completely remove the dataset from the given RUN in the Registry. May not be used with
298 --disassociate. Note, this may remove provenance information from datasets other than those
299 provided, and should be used with extreme care."""
300 ),
301 metavar="RUN",
302)
305find_all_option = MWOptionDecorator(
306 "--find-all",
307 is_flag=True,
308 help=unwrap(
309 """Purge the dataset results from all of the collections in which a dataset of that dataset
310 type + data id combination appear. (By default only the first found dataset type + data id is
311 purged, according to the order of COLLECTIONS passed in)."""
312 ),
313)
316unstore_option = MWOptionDecorator(
317 "--unstore",
318 is_flag=True,
319 help=unwrap(
320 """Remove these datasets from all datastores configured with this data repository. If
321 --disassociate and --purge are not used then --unstore will be used by default. Note that
322 --unstore will make it impossible to retrieve these datasets even via other collections.
323 Datasets that are already not stored are ignored by this option."""
324 ),
325)
328dry_run_option = MWOptionDecorator(
329 "--dry-run",
330 is_flag=True,
331 help=unwrap(
332 """Display the datasets that would be removed but do not remove them.
334 Note that a dataset can be in collections other than its RUN-type collection, and removing it
335 will remove it from all of them, even though the only one this will show is its RUN
336 collection."""
337 ),
338)
341quiet_option = MWOptionDecorator(
342 "--quiet",
343 is_flag=True,
344 help=unwrap("""Makes output quiet. Implies --no-confirm. Requires --dry-run not be passed."""),
345)
348@click.command(cls=ButlerCommand, short_help="Remove datasets.")
349@repo_argument(required=True)
350@collections_argument(
351 help=unwrap(
352 """COLLECTIONS is or more expressions that identify the collections to
353 search for datasets. Glob-style expressions may be used but only if the
354 --find-all flag is also passed."""
355 )
356)
357@option_section("Query Datasets Options:")
358@datasets_option(
359 help="One or more glob-style expressions that identify the dataset types to be pruned.",
360 multiple=True,
361 callback=split_commas,
362)
363@find_all_option()
364@where_option(help=where_help)
365@option_section("Prune Options:")
366@disassociate_option()
367@purge_option()
368@unstore_option()
369@option_section("Execution Options:")
370@dry_run_option()
371@confirm_option()
372@quiet_option()
373@option_section("Other Options:")
374@options_file_option()
375def prune_datasets(**kwargs):
376 """Query for and remove one or more datasets from a collection and/or
377 storage.
378 """
379 quiet = kwargs.pop("quiet", False)
380 if quiet:
381 if kwargs["dry_run"]:
382 raise click.ClickException(pruneDatasets_errQuietWithDryRun)
383 kwargs["confirm"] = False
385 result = script.pruneDatasets(**kwargs)
387 if result.errPurgeAndDisassociate:
388 raise click.ClickException(pruneDatasets_errPurgeAndDisassociate)
389 return
390 if result.errNoCollectionRestriction:
391 raise click.ClickException(pruneDatasets_errNoCollectionRestriction)
392 if result.errPruneOnNotRun:
393 raise click.ClickException(pruneDatasets_errPruneOnNotRun.format(**result.errDict))
394 if result.errNoOp:
395 raise click.ClickException(pruneDatasets_errNoOp)
396 if result.dryRun:
397 if result.action["disassociate"] and result.action["unstore"]:
398 msg = pruneDatasets_wouldDisassociateAndRemoveMsg
399 elif result.action["disassociate"]:
400 msg = pruneDatasets_wouldDisassociateMsg
401 else:
402 msg = pruneDatasets_wouldRemoveMsg
403 print(msg.format(**result.action))
404 printAstropyTables(result.tables)
405 return
406 if result.confirm:
407 if not result.tables:
408 print(pruneDatasets_noDatasetsFound)
409 return
410 print(pruneDatasets_willRemoveMsg)
411 printAstropyTables(result.tables)
412 doContinue = click.confirm(pruneDatasets_askContinueMsg, default=False)
413 if doContinue:
414 result.onConfirmation()
415 print(pruneDatasets_didRemoveAforementioned)
416 else:
417 print(pruneDatasets_didNotRemoveAforementioned)
418 return
419 if result.finished:
420 if not quiet:
421 print(pruneDatasets_didRemoveMsg)
422 printAstropyTables(result.tables)
423 return
426@click.command(short_help="Search for collections.", cls=ButlerCommand)
427@repo_argument(required=True)
428@glob_argument(
429 help="GLOB is one or more glob-style expressions that fully or partially identify the "
430 "collections to return."
431)
432@collection_type_option()
433@click.option(
434 "--chains",
435 default="table",
436 help=unwrap(
437 """Affects how results are presented. TABLE lists each dataset in a row with
438 chained datasets' children listed in a Definition column. TREE lists children below
439 their parent in tree form. FLATTEN lists all datasets, including child datasets in
440 one list.Defaults to TABLE. """
441 ),
442 callback=to_upper,
443 type=click.Choice(("TABLE", "TREE", "FLATTEN"), case_sensitive=False),
444)
445@options_file_option()
446def query_collections(*args, **kwargs):
447 """Get the collections whose names match an expression."""
448 table = script.queryCollections(*args, **kwargs)
449 # The unit test that mocks script.queryCollections does not return a table
450 # so we need the following `if`.
451 if table:
452 # When chains==TREE, the children of chained datasets are indented
453 # relative to their parents. For this to work properly the table must
454 # be left-aligned.
455 table.pprint_all(align="<")
458@click.command(cls=ButlerCommand)
459@repo_argument(required=True)
460@glob_argument(
461 help="GLOB is one or more glob-style expressions that fully or partially identify the "
462 "dataset types to return."
463)
464@verbose_option(help="Include dataset type name, dimensions, and storage class in output.")
465@components_option()
466@options_file_option()
467def query_dataset_types(*args, **kwargs):
468 """Get the dataset types in a repository."""
469 table = script.queryDatasetTypes(*args, **kwargs)
470 if table:
471 table.pprint_all()
472 else:
473 print("No results. Try --help for more information.")
476@click.command(cls=ButlerCommand)
477@repo_argument(required=True)
478@click.argument("dataset-type-name", nargs=1)
479def remove_dataset_type(*args, **kwargs):
480 """Remove a dataset type definition from a repository."""
481 script.removeDatasetType(*args, **kwargs)
484@click.command(cls=ButlerCommand)
485@query_datasets_options()
486@options_file_option()
487def query_datasets(**kwargs):
488 """List the datasets in a repository."""
489 for table in script.QueryDatasets(**kwargs).getTables():
490 print("")
491 table.pprint_all()
492 print("")
495@click.command(cls=ButlerCommand)
496@repo_argument(required=True)
497@click.argument("input-collection")
498@click.argument("output-collection")
499@click.argument("dataset-type-name")
500@click.option(
501 "--begin-date",
502 type=str,
503 default=None,
504 help=unwrap(
505 """ISO-8601 datetime (TAI) of the beginning of the validity range for the
506 certified calibrations."""
507 ),
508)
509@click.option(
510 "--end-date",
511 type=str,
512 default=None,
513 help=unwrap(
514 """ISO-8601 datetime (TAI) of the end of the validity range for the
515 certified calibrations."""
516 ),
517)
518@click.option(
519 "--search-all-inputs",
520 is_flag=True,
521 default=False,
522 help=unwrap(
523 """Search all children of the inputCollection if it is a CHAINED collection,
524 instead of just the most recent one."""
525 ),
526)
527@options_file_option()
528def certify_calibrations(*args, **kwargs):
529 """Certify calibrations in a repository."""
530 script.certifyCalibrations(*args, **kwargs)
533@click.command(cls=ButlerCommand)
534@repo_argument(required=True)
535@dimensions_argument(
536 help=unwrap(
537 """DIMENSIONS are the keys of the data IDs to yield, such as exposure,
538 instrument, or tract. Will be expanded to include any dependencies."""
539 )
540)
541@collections_option(help=collections_option.help + " May only be used with --datasets.")
542@datasets_option(
543 help=unwrap(
544 """An expression that fully or partially identifies dataset types that should
545 constrain the yielded data IDs. For example, including "raw" here would
546 constrain the yielded "instrument", "exposure", "detector", and
547 "physical_filter" values to only those for which at least one "raw" dataset
548 exists in "collections". Requires --collections."""
549 )
550)
551@where_option(help=where_help)
552@order_by_option()
553@limit_option()
554@offset_option()
555@options_file_option()
556def query_data_ids(**kwargs):
557 """List the data IDs in a repository."""
558 table = script.queryDataIds(**kwargs)
559 if table:
560 table.pprint_all()
561 else:
562 if not kwargs.get("dimensions") and not kwargs.get("datasets"):
563 print("No results. Try requesting some dimensions or datasets, see --help for more information.")
564 else:
565 print("No results. Try --help for more information.")
568@click.command(cls=ButlerCommand)
569@repo_argument(required=True)
570@element_argument(required=True)
571@datasets_option(
572 help=unwrap(
573 """An expression that fully or partially identifies dataset types that should
574 constrain the yielded records. May only be used with
575 --collections."""
576 )
577)
578@collections_option(help=collections_option.help + " May only be used with --datasets.")
579@where_option(help=where_help)
580@order_by_option()
581@limit_option()
582@offset_option()
583@click.option(
584 "--no-check",
585 is_flag=True,
586 help=unwrap(
587 """Don't check the query before execution. By default the query is checked before it
588 executed, this may reject some valid queries that resemble common mistakes."""
589 ),
590)
591@options_file_option()
592def query_dimension_records(**kwargs):
593 """Query for dimension information."""
594 table = script.queryDimensionRecords(**kwargs)
595 if table:
596 table.pprint_all()
597 else:
598 print("No results. Try --help for more information.")
601@click.command(cls=ButlerCommand)
602@repo_argument(required=True)
603@query_datasets_options(showUri=False, useArguments=False, repo=False)
604@destination_argument(help="Destination URI of folder to receive file artifacts.")
605@transfer_option()
606@verbose_option(help="Report destination location of all transferred artifacts.")
607@click.option(
608 "--preserve-path/--no-preserve-path",
609 is_flag=True,
610 default=True,
611 help="Preserve the datastore path to the artifact at the destination.",
612)
613@click.option(
614 "--clobber/--no-clobber",
615 is_flag=True,
616 default=False,
617 help="If clobber, overwrite files if they exist locally.",
618)
619@options_file_option()
620def retrieve_artifacts(**kwargs):
621 """Retrieve file artifacts associated with datasets in a repository."""
622 verbose = kwargs.pop("verbose")
623 transferred = script.retrieveArtifacts(**kwargs)
624 if verbose and transferred:
625 print(f"Transferred the following to {kwargs['destination']}:")
626 for uri in transferred:
627 print(uri)
628 print()
629 print(f"Number of artifacts retrieved into destination {kwargs['destination']}: {len(transferred)}")
632@click.command(cls=ButlerCommand)
633@click.argument("source", required=True)
634@click.argument("dest", required=True)
635@query_datasets_options(showUri=False, useArguments=False, repo=False)
636@transfer_option()
637@register_dataset_types_option()
638@options_file_option()
639def transfer_datasets(**kwargs):
640 """Transfer datasets from a source butler to a destination butler.
642 SOURCE is a URI to the Butler repository containing the RUN dataset.
644 DEST is a URI to the Butler repository that will receive copies of the
645 datasets.
646 """
647 number = script.transferDatasets(**kwargs)
648 print(f"Number of datasets transferred: {number}")
651@click.command(cls=ButlerCommand)
652@repo_argument(required=True)
653@click.argument("parent", required=True, nargs=1)
654@click.argument("children", required=False, nargs=-1, callback=split_commas)
655@click.option(
656 "--doc",
657 default="",
658 help="Documentation string associated with this collection. "
659 "Only relevant if the collection is newly created.",
660)
661@click.option(
662 "--flatten/--no-flatten",
663 default=False,
664 help="If `True` recursively flatten out any nested chained collections in children first.",
665)
666@click.option(
667 "--mode",
668 type=click.Choice(["redefine", "extend", "remove", "prepend", "pop"]),
669 default="redefine",
670 help="Update mode: "
671 "'redefine': Create new chain or redefine existing chain with the supplied CHILDREN. "
672 "'remove': Modify existing chain to remove the supplied CHILDREN. "
673 "'pop': Pop a numbered element off the chain. Defaults to popping "
674 "the first element (0). ``children`` must be integers if given. "
675 "'prepend': Modify existing chain to prepend the supplied CHILDREN to the front. "
676 "'extend': Modify existing chain to extend it with the supplied CHILDREN.",
677)
678def collection_chain(**kwargs):
679 """Define a collection chain.
681 PARENT is the name of the chained collection to create or modify. If the
682 collection already exists the chain associated with it will be updated.
684 CHILDREN are the collections to be used to modify the chain. The supplied
685 values will be split on comma. The exact usage depends on the MODE option.
686 For example,
688 $ butler collection-chain REPO PARENT child1,child2 child3
690 will result in three children being included in the chain.
692 When the MODE is 'pop' the CHILDREN should be integer indices indicating
693 collections to be removed from the current chain.
694 MODE 'pop' can take negative integers to indicate removal relative to the
695 end of the chain, but when doing that '--' must be given to indicate the
696 end of the options specification.
698 $ butler collection-chain REPO --mode=pop PARENT -- -1
700 Will remove the final collection from the chain.
701 """
702 chain = script.collectionChain(**kwargs)
703 print(f"[{', '.join(chain)}]")
706@click.command(cls=ButlerCommand)
707@repo_argument(required=True)
708@click.argument("dataset_type", required=True)
709@click.argument("run", required=True)
710@click.argument("table_file", required=True)
711@click.option(
712 "--formatter",
713 type=str,
714 help="Fully-qualified python class to use as the Formatter. If not specified the formatter"
715 " will be determined from the dataset type and datastore configuration.",
716)
717@click.option(
718 "--id-generation-mode",
719 default="UNIQUE",
720 help="Mode to use for generating dataset IDs. The default creates a unique ID. Other options"
721 " are: 'DATAID_TYPE' for creating a reproducible ID from the dataID and dataset type;"
722 " 'DATAID_TYPE_RUN' for creating a reproducible ID from the dataID, dataset type and run."
723 " The latter is usually used for 'raw'-type data that will be ingested in multiple."
724 " repositories.",
725 callback=to_upper,
726 type=click.Choice(("UNIQUE", "DATAID_TYPE", "DATAID_TYPE_RUN"), case_sensitive=False),
727)
728@click.option(
729 "--data-id",
730 type=str,
731 multiple=True,
732 callback=split_commas,
733 help="Keyword=value string with an additional dataId value that is fixed for all ingested"
734 " files. This can be used to simplify the table file by removing repeated entries that are"
735 " fixed for all files to be ingested. Multiple key/values can be given either by using"
736 " comma separation or multiple command line options.",
737)
738@click.option(
739 "--prefix",
740 type=str,
741 help="For relative paths in the table file, specify a prefix to use. The default is to"
742 " use the current working directory.",
743)
744@transfer_option()
745def ingest_files(**kwargs):
746 """Ingest files from table file.
748 DATASET_TYPE is the name of the dataset type to be associated with these
749 files. This dataset type must already exist and will not be created by
750 this command. There can only be one dataset type per invocation of this
751 command.
753 RUN is the run to use for the file ingest.
755 TABLE_FILE refers to a file that can be read by astropy.table with
756 columns of:
758 file URI, dimension1, dimension2, ..., dimensionN
760 where the first column is the URI to the file to be ingested and the
761 remaining columns define the dataId to associate with that file.
762 The column names should match the dimensions for the specified dataset
763 type. Relative file URI by default is assumed to be relative to the
764 current working directory but can be overridden using the ``--prefix``
765 option.
767 This command does not create dimension records and so any records must
768 be created by other means. This command should not be used to ingest
769 raw camera exposures.
770 """
771 script.ingest_files(**kwargs)
774@click.command(cls=ButlerCommand)
775@repo_argument(required=True)
776@click.argument("dataset_type", required=True)
777@click.argument("storage_class", required=True)
778@click.argument("dimensions", required=False, nargs=-1)
779@click.option(
780 "--is-calibration/--no-is-calibration",
781 is_flag=True,
782 default=False,
783 help="Indicate that this dataset type can be part of a calibration collection.",
784)
785def register_dataset_type(**kwargs):
786 """Register a new dataset type with this butler repository.
788 DATASET_TYPE is the name of the dataset type.
790 STORAGE_CLASS is the name of the StorageClass to be associated with
791 this dataset type.
793 DIMENSIONS is a list of all the dimensions relevant to this
794 dataset type. It can be an empty list.
796 A component dataset type (such as "something.component") is not a
797 real dataset type and so can not be defined by this command. They are
798 automatically derived from the composite dataset type when a composite
799 storage class is specified.
800 """
801 inserted = script.register_dataset_type(**kwargs)
802 if inserted:
803 print("Dataset type successfully registered.")
804 else:
805 print("Dataset type already existed in identical form.")
808@click.command(cls=ButlerCommand)
809@repo_argument(required=True)
810@directory_argument(required=True)
811@collections_argument(help="COLLECTIONS are the collection to export calibrations from.")
812def export_calibs(*args, **kwargs):
813 """Export calibrations from the butler for import elsewhere."""
814 table = script.exportCalibs(*args, **kwargs)
815 if table:
816 table.pprint_all(align="<")