Hide keyboard shortcuts

Hot-keys 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

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 

24from functools import partial 

25 

26from ..utils import MWOptionDecorator, split_commas, split_kv, unwrap, yaml_presets 

27from lsst.daf.butler.registry import CollectionType 

28 

29 

30class CollectionTypeCallback: 

31 

32 collectionTypes = CollectionType.__members__.keys() 

33 

34 @staticmethod 

35 def makeCollectionTypes(context, param, value): 

36 if not value: 

37 # Click seems to demand that the default be an empty tuple, rather 

38 # than a sentinal like None. The behavior that we want is that 

39 # not passing this option at all passes all collection types, while 

40 # passing it uses only the passed collection types. That works 

41 # fine for now, since there's no command-line option to subtract 

42 # collection types, and hence the only way to get an empty tuple 

43 # is as the default. 

44 return tuple(CollectionType.all()) 

45 result = [] 

46 for item in split_commas(context, param, value): 

47 item = item.upper() 

48 try: 

49 result.append(CollectionType.__members__[item]) 

50 except KeyError: 

51 raise KeyError(f"{item} is not a valid CollectionType.") from None 

52 return tuple(result) 

53 

54 

55collection_type_option = MWOptionDecorator("--collection-type", 

56 callback=CollectionTypeCallback.makeCollectionTypes, 

57 multiple=True, 

58 help="If provided, only list collections of this type.", 

59 type=click.Choice(CollectionTypeCallback.collectionTypes, 

60 case_sensitive=False)) 

61 

62 

63collections_option = MWOptionDecorator("--collections", 

64 help=unwrap("""One or more expressions that fully or partially identify 

65 the collections to search for datasets.If not provided all 

66 datasets are returned."""), 

67 multiple=True, 

68 callback=split_commas) 

69 

70 

71config_option = MWOptionDecorator("-c", "--config", 

72 callback=split_kv, 

73 help="Config override, as a key-value pair.", 

74 multiple=True) 

75 

76 

77config_file_option = MWOptionDecorator("-C", "--config-file", 

78 help=unwrap("""Path to a pex config override to be included after the 

79 Instrument config overrides are applied.""")) 

80 

81 

82dataset_type_option = MWOptionDecorator("-d", "--dataset-type", 

83 callback=split_commas, 

84 help="Specific DatasetType(s) to validate.", 

85 multiple=True) 

86 

87 

88datasets_option = MWOptionDecorator("--datasets") 

89 

90 

91logLevelChoices = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"] 

92log_level_option = MWOptionDecorator("--log-level", 

93 callback=partial(split_kv, 

94 choice=click.Choice(logLevelChoices, 

95 case_sensitive=False), 

96 normalize=True, 

97 unseparated_okay=True), 

98 help="The logging level. " 

99 f"Supported levels are [{'|'.join(logLevelChoices)}]", 

100 is_eager=True, 

101 metavar="LEVEL|COMPONENT=LEVEL", 

102 multiple=True) 

103 

104 

105long_log_option = MWOptionDecorator("--long-log", 

106 help="Make log messages appear in long format.", 

107 is_flag=True) 

108 

109 

110options_file_option = MWOptionDecorator("--options-file", "-@", 

111 expose_value=False, # This option should not be forwarded 

112 help=unwrap("""URI to YAML file containing overrides 

113 of command line options. The YAML should be organized 

114 as a hierarchy with subcommand names at the top 

115 level options for that subcommand below."""), 

116 callback=yaml_presets) 

117 

118 

119processes_option = MWOptionDecorator("-j", "--processes", 

120 default=1, 

121 help="Number of processes to use.", 

122 type=click.IntRange(min=1)) 

123 

124 

125regex_option = MWOptionDecorator("--regex") 

126 

127 

128run_option = MWOptionDecorator("--output-run", 

129 help="The name of the run datasets should be output to.") 

130 

131 

132transfer_option = MWOptionDecorator("-t", "--transfer", 

133 default="auto", # set to `None` if using `required=True` 

134 help="The external data transfer mode.", 

135 type=click.Choice(["auto", "link", "symlink", "hardlink", "copy", "move", 

136 "relsymlink", "direct"], 

137 case_sensitive=False)) 

138 

139 

140verbose_option = MWOptionDecorator("-v", "--verbose", 

141 help="Increase verbosity.", 

142 is_flag=True) 

143 

144 

145where_option = MWOptionDecorator("--where", 

146 help="A string expression similar to a SQL WHERE clause.")