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

43 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-31 04:05 -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/>. 

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 Use the remove-runs subcommand to remove RUN collections. 

55 """ 

56 confirm = kwargs.pop("confirm") 

57 result = script.removeCollections(**kwargs) 

58 canRemoveCollections = len(result.removeCollectionsTable) 

59 doContinue = canRemoveCollections 

60 if confirm: 

61 if canRemoveCollections: 

62 print("\n" + willRemoveCollectionMsg) 

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

64 else: 

65 print("\n" + noNonRunCollectionsMsg) 

66 if len(result.runsTable): 

67 print("\n" + canNotRemoveFoundRuns) 

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

69 print() 

70 if canRemoveCollections: 

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

72 if doContinue: 

73 result.onConfirmation() 

74 if confirm: 

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

76 else: 

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

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

79 if len(result.runsTable): 

80 print("\n" + didNotRemoveFoundRuns) 

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

82 print() 

83 elif canRemoveCollections and not doContinue: 

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