-
Notifications
You must be signed in to change notification settings - Fork 15
/
parser.py
198 lines (147 loc) · 5.36 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""
Command line parser for HDF5 MANIPULATOR
"""
import argparse
def get_args_split():
"""parse arguments for split"""
parser = argparse.ArgumentParser(
description="HDF5 MANIPULATOR (split)",
usage="./split.py <options>"
)
parser.add_argument(
"--prefix", action="store", dest="prefix",
metavar="[path/to/filename_base]", default=None,
help="prefix for splitted files (base on input file if not defined)"
)
parser.add_argument(
"--filelist", action="store", dest="filelist",
metavar="[path/to/filelist]", default=None,
help="save output files list in txt file"
)
required = parser.add_argument_group("required arguments")
required.add_argument(
"--input", action="store", dest="input",
metavar="[path/to/input_file]", required=True,
help="path to input hdf5 file"
)
required.add_argument(
"--size", action="store", dest="size", metavar="[int]", required=True,
help="number of entries per file"
)
return parser.parse_args()
def get_args_merge():
"""parse arguments for merge"""
parser = argparse.ArgumentParser(
description="HDF5 MANIPULATOR (merge)",
usage="./merge.py <options>"
)
required = parser.add_argument_group("required arguments")
required.add_argument(
"--input", action="store", dest="input_files",
metavar="[list of input files]", required=True,
help="path to input hdf5 files to merge ('file1, file2,...' \
will look for all files starts with file1 and file2 \
and ends with .hdf5)"
)
required.add_argument(
"--output", action="store", dest="output",
metavar="[path/to/filename]", required=True,
help="path to output hdf5 file"
)
return parser.parse_args()
def get_args_extract():
"""parse arguments for extract"""
parser = argparse.ArgumentParser(
description="HDF5 MANIPULATOR (extract)",
usage="./extract.py <options>"
)
required = parser.add_argument_group("required arguments")
required.add_argument(
"--input", action="store", dest="input",
metavar="[path/to/filename]", required=True,
help="path to input hdf5 file"
)
required.add_argument(
"--output", action="store", dest="output",
metavar="[path/to/filename]", required=True,
help="path to output hdf5 file"
)
required.add_argument(
"--keys", action="store", dest="keys", metavar="['key1, key2, ...']",
required=True,
help="list of datasets to be saved in the output file"
)
return parser.parse_args()
def get_args_combine():
"""parse arguments for combine"""
parser = argparse.ArgumentParser(
description="HDF5 MANIPULATOR (combine)",
usage="./combine.py <options>"
)
parser.add_argument(
"--keys1", action="store", dest="keys1", metavar="['key1, key2, ...']",
default=None,
help="list of datasets to be extracted from the first input file \
(use all if not defined)"
)
parser.add_argument(
"--keys2", action="store", dest="keys2", metavar="['key1, key2, ...']",
default=None,
help="list of datasets to be extracted from the second input file \
(use all if not defined)"
)
parser.add_argument(
"--do-not-warn", action="store_false", dest="print_warnings",
default=True,
help="if supplied, don't print warnings during combination"
)
parser.add_argument(
"--show-progress", action="store_true", dest="show_progress",
default=True,
help="if supplied, give an event indicator every 100 events"
)
required = parser.add_argument_group("required arguments")
required.add_argument(
"--input1", action="store", dest="input1",
metavar="[path/to/filename1]", required=True,
help="path to first input hdf5 file"
)
required.add_argument(
"--input2", action="store", dest="input2",
metavar="[path/to/filename2]", required=True,
help="path to second input hdf5 file"
)
required.add_argument(
"--output", action="store", dest="output",
metavar="[path/to/filename]", required=True,
help="path to output hdf5 file"
)
required.add_argument(
"--match", action="store", dest="match", metavar="[key]",
required=True,
help="the common key use to order data"
)
return parser.parse_args()
def get_args_rename():
"""parse arguments for rename"""
parser = argparse.ArgumentParser(
description="HDF5 MANIPULATOR (rename)",
usage="./rename_dataset.py <options>"
)
required = parser.add_argument_group("required arguments")
required.add_argument(
"--input", action="store", dest="input",
metavar="[path/to/filename]", required=True,
help="path to input hdf5 file"
)
required.add_argument(
"--dataset", action="store", dest="dataset",
metavar="[old name]", required=True,
help="name of dataset to be changed"
)
required.add_argument(
"--name", action="store", dest="name", metavar="[new name]",
required=True,
help="new name of dataset"
)
return parser.parse_args()