Coverage for python/lsst/daf/butler/cli/cmd/_remove_collections.py: 27%

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

43 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 

23import click 

24 

25from ..utils import ( 

26 ButlerCommand, 

27) 

28from ..opt import ( 

29 collection_argument, 

30 confirm_option, 

31 options_file_option, 

32 repo_argument, 

33) 

34from ... import script 

35 

36 

37# messages emitted by remove-collections, defined separately for use in unit 

38# tests. 

39noNonRunCollectionsMsg = "No non-RUN collections were found." 

40willRemoveCollectionMsg = "The following collections will be removed:" 

41removedCollectionsMsg = "Removed collections" 

42canNotRemoveFoundRuns = "The following RUN collections were found but can NOT be removed by this command:" 

43didNotRemoveFoundRuns = "Found RUN collections but they can NOT be removed by this command:" 

44abortedMsg = "Aborted." 

45 

46 

47@click.command(cls=ButlerCommand) 

48@repo_argument(required=True) 

49@collection_argument( 

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

51) 

52@confirm_option() 

53@options_file_option() 

54def remove_collections(**kwargs): 

55 """Remove one or more non-RUN collections. 

56 

57This command can be used to remove only non-RUN collections. If RUN collections 

58are found when searching for collections (and the --no-confirm flag is not 

59used), then they will be shown in a separate table during confirmation, but 

60they will not be removed. 

61 """ 

62 confirm = kwargs.pop("confirm") 

63 result = script.removeCollections(**kwargs) 

64 canRemoveCollections = len(result.removeCollectionsTable) 

65 doContinue = canRemoveCollections 

66 if confirm: 

67 if canRemoveCollections: 

68 print("\n" + willRemoveCollectionMsg) 

69 result.removeCollectionsTable.pprint_all(align="<") 

70 else: 

71 print("\n" + noNonRunCollectionsMsg) 

72 if len(result.runsTable): 

73 print("\n" + canNotRemoveFoundRuns) 

74 result.runsTable.pprint_all(align="<") 

75 print() 

76 if canRemoveCollections: 

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

78 if doContinue: 

79 result.onConfirmation() 

80 if confirm: 

81 print("\n" + removedCollectionsMsg + ".\n") 

82 else: 

83 print("\n" + removedCollectionsMsg + ":\n") 

84 result.removeCollectionsTable.pprint_all(align="<") 

85 if len(result.runsTable): 

86 print("\n" + didNotRemoveFoundRuns) 

87 result.runsTable.pprint_all(align="<") 

88 print() 

89 elif canRemoveCollections and not doContinue: 

90 print("\n" + abortedMsg + "\n")