Coverage for python/lsst/daf/butler/script/transferDatasets.py: 37%
17 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-27 01:57 -0700
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-27 01:57 -0700
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__ = ("transferDatasets",)
24import logging
25from typing import Tuple
27from .._butler import Butler
28from ..registry.queries import DatasetQueryResults
30log = logging.getLogger(__name__)
33def transferDatasets(
34 source: str,
35 dest: str,
36 dataset_type: Tuple[str, ...],
37 collections: Tuple[str, ...],
38 where: str,
39 find_first: bool,
40 transfer: str,
41 register_dataset_types: bool,
42 transfer_dimensions: bool = True,
43) -> int:
44 """Transfer datasets from run in source to dest.
46 Parameters
47 ----------
48 source : `str`
49 URI string of the source Butler repo.
50 dest : `str`
51 URI string of the destination Butler repo.
52 dataset_type : `tuple` of `str`
53 Dataset type names. An empty tuple implies all dataset types.
54 collections : `tuple` of `str`
55 Names of collection globs to match. An empty tuple implies all
56 collections.
57 where : `str`
58 Query modification string.
59 find_first : `bool`
60 Whether only the first match should be used.
61 transfer : `str`
62 Transfer mode to use when placing artifacts in the destination.
63 register_dataset_types : `bool`
64 Indicate whether missing dataset types should be registered.
65 transfer_dimensions : `bool`
66 Indicate whether dimensions should be transferred along with
67 datasets. It can be more efficient to disable this if it is known
68 that all dimensions exist.
69 """
70 source_butler = Butler(source, writeable=False)
71 dest_butler = Butler(dest, writeable=True)
73 dataset_type_expr = ... if not dataset_type else dataset_type
74 collections_expr = ... if not collections else collections
76 source_refs = source_butler.registry.queryDatasets(
77 datasetType=dataset_type_expr, collections=collections_expr, where=where, findFirst=find_first
78 )
80 # Might need expanded results if datastore records have to be derived.
81 # Not all registries return the same form for results.
82 if isinstance(source_refs, DatasetQueryResults):
83 source_refs = source_refs.expanded()
85 # Place results in a set to remove duplicates
86 source_refs_set = set(source_refs)
88 transferred = dest_butler.transfer_from(
89 source_butler,
90 source_refs_set,
91 transfer=transfer,
92 register_dataset_types=register_dataset_types,
93 transfer_dimensions=transfer_dimensions,
94 )
95 return len(transferred)