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 ... import script 

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

27from ..utils import ButlerCommand 

28 

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

30# tests. 

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

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

33removedCollectionsMsg = "Removed collections" 

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

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

36abortedMsg = "Aborted." 

37 

38 

39@click.command(cls=ButlerCommand) 

40@repo_argument(required=True) 

41@collection_argument( 

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

43) 

44@confirm_option() 

45@options_file_option() 

46def remove_collections(**kwargs): 

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

48 

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

50 collections are found when searching for collections (and the --no-confirm 

51 flag is not used), then they will be shown in a separate table during 

52 confirmation, but they will not be removed. 

53 """ 

54 confirm = kwargs.pop("confirm") 

55 result = script.removeCollections(**kwargs) 

56 canRemoveCollections = len(result.removeCollectionsTable) 

57 doContinue = canRemoveCollections 

58 if confirm: 

59 if canRemoveCollections: 

60 print("\n" + willRemoveCollectionMsg) 

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

62 else: 

63 print("\n" + noNonRunCollectionsMsg) 

64 if len(result.runsTable): 

65 print("\n" + canNotRemoveFoundRuns) 

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

67 print() 

68 if canRemoveCollections: 

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

70 if doContinue: 

71 result.onConfirmation() 

72 if confirm: 

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

74 else: 

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

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

77 if len(result.runsTable): 

78 print("\n" + didNotRemoveFoundRuns) 

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

80 print() 

81 elif canRemoveCollections and not doContinue: 

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