Hide keyboard shortcuts

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/>. 

21 

22__all__ = ("retrieveArtifacts",) 

23 

24import logging 

25 

26from .. import Butler 

27 

28log = logging.getLogger(__name__) 

29 

30 

31def retrieveArtifacts(repo, destination, dataset_type, collections, where, find_first, 

32 transfer, preserve_path, clobber): 

33 """Parameters are those required for querying datasets plus a destination 

34 URI. 

35 

36 Parameters 

37 ---------- 

38 repo : `str` 

39 URI string of the Butler repo to use. 

40 destination : `str` 

41 URI string of the directory to write the artifacts. 

42 dataset_type : `tuple` of `str` 

43 Dataset type names. An empty tuple implies all dataset types. 

44 collections : `tuple` of `str` 

45 Names of collection globs to match. An empty tuple implies all 

46 collections. 

47 where : `str` 

48 Query modification string. 

49 find_first : `bool` 

50 Whether only the first match should be used. 

51 transfer : `str` 

52 Transfer mode to use when placing artifacts in the destination. 

53 preserve_path : `bool` 

54 If `True` the full datastore path will be retained within the 

55 destination directory, else only the filename will be used. 

56 clobber : `bool` 

57 If `True` allow transfers to overwrite files at the destination. 

58 

59 Returns 

60 ------- 

61 transferred : `list` of `ButlerURI` 

62 The destination URIs of every transferred artifact. 

63 """ 

64 if not dataset_type: 

65 dataset_type = ... 

66 

67 if not collections: 

68 collections = ... 

69 

70 butler = Butler(repo, writeable=False) 

71 

72 # Need to store in list so we can count the number to give some feedback 

73 # to caller. 

74 refs = list(butler.registry.queryDatasets(datasetType=dataset_type, 

75 collections=collections, 

76 where=where, 

77 findFirst=find_first)) 

78 

79 log.info("Number of datasets matching query: %d", len(refs)) 

80 

81 transferred = butler.retrieveArtifacts(refs, destination=destination, transfer=transfer, 

82 preserve_path=preserve_path, overwrite=clobber) 

83 return transferred