Coverage for python/lsst/daf/butler/script/retrieveArtifacts.py : 35%

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/>.
22__all__ = ("retrieveArtifacts",)
24import logging
26from .. import Butler
27from ..core.utils import globToRegex
29log = logging.getLogger(__name__)
32def retrieveArtifacts(repo, destination, dataset_type, collections, where, find_first,
33 transfer, preserve_path, clobber):
34 """Parameters are those required for querying datasets plus a destination
35 URI.
37 Parameters
38 ----------
39 repo : `str`
40 URI string of the Butler repo to use.
41 destination : `str`
42 URI string of the directory to write the artifacts.
43 dataset_type : `tuple` of `str`
44 Dataset type names. An empty tuple implies all dataset types.
45 collections : `tuple` of `str`
46 Names of collection globs to match. An empty tuple implies all
47 collections.
48 where : `str`
49 Query modification string.
50 find_first : `bool`
51 Whether only the first match should be used.
52 transfer : `str`
53 Transfer mode to use when placing artifacts in the destination.
54 preserve_path : `bool`
55 If `True` the full datastore path will be retained within the
56 destination directory, else only the filename will be used.
57 clobber : `bool`
58 If `True` allow transfers to overwrite files at the destination.
60 Returns
61 -------
62 transferred : `list` of `ButlerURI`
63 The destination URIs of every transferred artifact.
64 """
65 dataset = globToRegex(dataset_type)
66 if not dataset:
67 dataset = ...
69 collections = globToRegex(collections)
71 butler = Butler(repo, writeable=False)
73 # Need to store in list so we can count the number to give some feedback
74 # to caller.
75 refs = list(butler.registry.queryDatasets(datasetType=dataset,
76 collections=collections,
77 where=where,
78 findFirst=find_first))
80 log.info("Number of datasets matching query: %d", len(refs))
82 transferred = butler.retrieveArtifacts(refs, destination=destination, transfer=transfer,
83 preserve_path=preserve_path, overwrite=clobber)
84 return transferred