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

14 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-21 02:43 -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/>. 

21 

22__all__ = ("retrieveArtifacts",) 

23 

24import logging 

25 

26from .._butler import Butler 

27 

28log = logging.getLogger(__name__) 

29 

30 

31def retrieveArtifacts( 

32 repo, destination, dataset_type, collections, where, find_first, transfer, preserve_path, clobber 

33): 

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

35 URI. 

36 

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. 

59 

60 Returns 

61 ------- 

62 transferred : `list` of `lsst.resources.ResourcePath` 

63 The destination URIs of every transferred artifact. 

64 """ 

65 if not dataset_type: 

66 dataset_type = ... 

67 

68 if not collections: 

69 collections = ... 

70 

71 butler = Butler(repo, writeable=False) 

72 

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

74 # to caller. 

75 refs = list( 

76 butler.registry.queryDatasets( 

77 datasetType=dataset_type, collections=collections, where=where, findFirst=find_first 

78 ) 

79 ) 

80 

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

82 

83 transferred = butler.retrieveArtifacts( 

84 refs, destination=destination, transfer=transfer, preserve_path=preserve_path, overwrite=clobber 

85 ) 

86 return transferred