Coverage for python/lsst/daf/butler/cli/cmd/_remove_runs.py: 41%

Shortcuts 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

38 statements  

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 

23from typing import Mapping, Sequence 

24 

25import click 

26 

27from ... import script 

28from ..opt import collection_argument, confirm_option, options_file_option, repo_argument 

29from ..utils import ButlerCommand 

30 

31# messages emitted by remove-runs, defined separately for use in unit 

32# tests. 

33noRunCollectionsMsg = "No RUN collections were found." 

34willRemoveRunsMsg = "The following RUN collections will be removed:" 

35willRemoveDatasetsMsg = "The following datasets will be removed:" 

36didRemoveRunsMsg = "The following RUN collections were removed:" 

37didRemoveDatasetsMsg = "The following datasets were removed:" 

38removedRunsMsg = "Removed collections" 

39abortedMsg = "Aborted." 

40 

41 

42def _print_remove(will: bool, runs: Sequence[str], datasets: Mapping[str, int]): 

43 """Print the formatted remove statement. 

44 

45 Parameters 

46 ---------- 

47 will : bool 

48 True if remove "will" happen, False if the remove "did" happen. 

49 runs : Sequence[str] 

50 The RUNs that will be or were removed. 

51 datasets : Mapping[str, int] 

52 The dataset types & count that will be or were removed. 

53 """ 

54 print(willRemoveRunsMsg if will else didRemoveRunsMsg) 

55 print(", ".join(runs)) 

56 print(willRemoveDatasetsMsg if will else didRemoveDatasetsMsg) 

57 print(", ".join([f"{i[0]}({i[1]})" for i in datasets.items()])) 

58 

59 

60@click.command(cls=ButlerCommand) 

61@repo_argument(required=True) 

62@collection_argument( 

63 help="COLLECTION is a glob-style expression that identifies the RUN collection(s) to remove." 

64) 

65@confirm_option() 

66@options_file_option() 

67def remove_runs(**kwargs): 

68 """Remove one or more RUN collections. 

69 

70 This command can be used to remove RUN collections and the datasets within 

71 them. 

72 """ 

73 confirm = kwargs.pop("confirm") 

74 result = script.removeRuns(**kwargs) 

75 canRemoveRuns = len(result.runs) 

76 if not canRemoveRuns: 

77 print(noRunCollectionsMsg) 

78 return 

79 if confirm: 

80 _print_remove(True, result.runs, result.datasets) 

81 doContinue = click.confirm("Continue?", default=False) 

82 if doContinue: 

83 result.onConfirmation() 

84 print(removedRunsMsg) 

85 else: 

86 print(abortedMsg) 

87 else: 

88 result.onConfirmation() 

89 _print_remove(False, result.runs, result.datasets)