Coverage for python / lsst / rucio / register / app_parser.py: 17%

27 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:42 +0000

1# This file is part of rucio_register 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import argparse 

23import logging 

24 

25_FORMAT = ( 

26 "%(levelname) -10s %(asctime)s.%(msecs)03dZ %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s" 

27) 

28 

29 

30class AppParser: 

31 """Application command line argument parser 

32 

33 Parameters 

34 ---------- 

35 argv: `list` 

36 list of program name and arguments 

37 """ 

38 

39 def __init__(self, argv): 

40 parser = argparse.ArgumentParser(prog=argv[0]) 

41 parser.add_argument( 

42 "-r", 

43 "--repo", 

44 action="store", 

45 default=None, 

46 dest="repo", 

47 help="Butler repository", 

48 type=str, 

49 required=True, 

50 ) 

51 parser.add_argument( 

52 "-c", 

53 "--collections", 

54 action="store", 

55 default=None, 

56 dest="collections", 

57 help="collections for lookup", 

58 type=str, 

59 required=True, 

60 ) 

61 

62 parser.add_argument( 

63 "-t", 

64 "--dataset-type", 

65 action="store", 

66 default=None, 

67 dest="dataset_type", 

68 help="dataset type for lookup", 

69 type=str, 

70 required=True, 

71 ) 

72 

73 parser.add_argument( 

74 "-d", 

75 "--rucio-dataset", 

76 action="store", 

77 default=None, 

78 dest="rucio_dataset", 

79 help="rucio dataset to register files to", 

80 type=str, 

81 required=True, 

82 ) 

83 parser.add_argument( 

84 "-C", 

85 "--rucio-register-config", 

86 action="store", 

87 default=None, 

88 dest="register_config", 

89 help="configuration file used for registration", 

90 type=str, 

91 required=False, 

92 ) 

93 parser.add_argument( 

94 "-s", 

95 "--chunk-size", 

96 help="number of replica requests to make at once", 

97 action="store", 

98 dest="chunks", 

99 type=int, 

100 required=False, 

101 default=30, 

102 ) 

103 # the following arguments are for logging; 

104 # defaults to WARNING 

105 # -v sets to INFO 

106 # -D sets to DEBUG 

107 

108 group = parser.add_mutually_exclusive_group() 

109 group.add_argument( 

110 "-v", 

111 "--verbose", 

112 help="set loglevel to INFO", 

113 action="store_const", 

114 dest="loglevel", 

115 const=logging.INFO, 

116 default=None, 

117 ) 

118 group.add_argument( 

119 "-D", 

120 "--debug", 

121 help="set loglevel to DEBUG", 

122 action="store_const", 

123 dest="loglevel", 

124 const=logging.DEBUG, 

125 default=None, 

126 ) 

127 

128 args = parser.parse_args(argv[1:]) 

129 

130 if args.loglevel is None: 

131 loglevel = logging.WARNING 

132 else: 

133 loglevel = args.loglevel 

134 

135 logging.basicConfig(level=loglevel, format=(_FORMAT), datefmt="%Y-%m-%d %H:%M:%S") 

136 

137 self.butler_repo = args.repo 

138 self.collections = args.collections 

139 self.dataset_type = args.dataset_type 

140 self.rucio_dataset = args.rucio_dataset 

141 self.register_config = args.register_config 

142 self.loglevel = args.loglevel 

143 self.chunks = args.chunks