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

18 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-15 02:02 -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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <http://www.gnu.org/licenses/>. 

27from __future__ import annotations 

28 

29__all__ = ("transferDatasets",) 

30 

31import logging 

32from types import EllipsisType 

33 

34from .._butler import Butler 

35from ..registry.queries import DatasetQueryResults 

36 

37log = logging.getLogger(__name__) 

38 

39 

40def transferDatasets( 

41 source: str, 

42 dest: str, 

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

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

45 where: str, 

46 find_first: bool, 

47 transfer: str, 

48 register_dataset_types: bool, 

49 transfer_dimensions: bool = True, 

50) -> int: 

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

52 

53 Parameters 

54 ---------- 

55 source : `str` 

56 URI string of the source Butler repo. 

57 dest : `str` 

58 URI string of the destination Butler repo. 

59 dataset_type : `tuple` of `str` 

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

61 collections : `tuple` of `str` 

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

63 collections. 

64 where : `str` 

65 Query modification string. 

66 find_first : `bool` 

67 Whether only the first match should be used. 

68 transfer : `str` 

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

70 register_dataset_types : `bool` 

71 Indicate whether missing dataset types should be registered. 

72 transfer_dimensions : `bool` 

73 Indicate whether dimensions should be transferred along with 

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

75 that all dimensions exist. 

76 """ 

77 source_butler = Butler.from_config(source, writeable=False) 

78 dest_butler = Butler.from_config(dest, writeable=True) 

79 

80 dataset_type_expr = dataset_type or ... 

81 collections_expr: tuple[str, ...] | EllipsisType = collections or ... 

82 

83 source_refs = source_butler.registry.queryDatasets( 

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

85 ) 

86 

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

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

89 if isinstance(source_refs, DatasetQueryResults): 

90 source_refs = source_refs.expanded() 

91 

92 # Place results in a set to remove duplicates 

93 source_refs_set = set(source_refs) 

94 

95 transferred = dest_butler.transfer_from( 

96 source_butler, 

97 source_refs_set, 

98 transfer=transfer, 

99 register_dataset_types=register_dataset_types, 

100 transfer_dimensions=transfer_dimensions, 

101 ) 

102 return len(transferred)