Coverage for python/lsst/daf/butler/script/transferDatasets.py: 40%

18 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-06 02:33 -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/>. 

21from __future__ import annotations 

22 

23__all__ = ("transferDatasets",) 

24 

25import logging 

26from types import EllipsisType 

27 

28from .._butler import Butler 

29from ..registry.queries import DatasetQueryResults 

30 

31log = logging.getLogger(__name__) 

32 

33 

34def transferDatasets( 

35 source: str, 

36 dest: str, 

37 dataset_type: tuple[str, ...], 

38 collections: tuple[str, ...], 

39 where: str, 

40 find_first: bool, 

41 transfer: str, 

42 register_dataset_types: bool, 

43 transfer_dimensions: bool = True, 

44) -> int: 

45 """Transfer datasets from run in source to dest. 

46 

47 Parameters 

48 ---------- 

49 source : `str` 

50 URI string of the source Butler repo. 

51 dest : `str` 

52 URI string of the destination Butler repo. 

53 dataset_type : `tuple` of `str` 

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

55 collections : `tuple` of `str` 

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

57 collections. 

58 where : `str` 

59 Query modification string. 

60 find_first : `bool` 

61 Whether only the first match should be used. 

62 transfer : `str` 

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

64 register_dataset_types : `bool` 

65 Indicate whether missing dataset types should be registered. 

66 transfer_dimensions : `bool` 

67 Indicate whether dimensions should be transferred along with 

68 datasets. It can be more efficient to disable this if it is known 

69 that all dimensions exist. 

70 """ 

71 source_butler = Butler(source, writeable=False) 

72 dest_butler = Butler(dest, writeable=True) 

73 

74 dataset_type_expr = ... if not dataset_type else dataset_type 

75 collections_expr: tuple[str, ...] | EllipsisType = ... if not collections else collections 

76 

77 source_refs = source_butler.registry.queryDatasets( 

78 datasetType=dataset_type_expr, collections=collections_expr, where=where, findFirst=find_first 

79 ) 

80 

81 # Might need expanded results if datastore records have to be derived. 

82 # Not all registries return the same form for results. 

83 if isinstance(source_refs, DatasetQueryResults): 

84 source_refs = source_refs.expanded() 

85 

86 # Place results in a set to remove duplicates 

87 source_refs_set = set(source_refs) 

88 

89 transferred = dest_butler.transfer_from( 

90 source_butler, 

91 source_refs_set, 

92 transfer=transfer, 

93 register_dataset_types=register_dataset_types, 

94 transfer_dimensions=transfer_dimensions, 

95 ) 

96 return len(transferred)