|
19 | 19 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 | 20 | # |
21 | 21 |
|
| 22 | +from argparse import ArgumentParser |
22 | 23 | from collections import OrderedDict |
23 | 24 | from io import BytesIO |
24 | | -from optparse import OptionParser |
25 | 25 | import os |
26 | 26 | from threading import Lock |
27 | 27 |
|
@@ -200,87 +200,88 @@ def __init__(self, relpath): |
200 | 200 |
|
201 | 201 |
|
202 | 202 | if __name__ == '__main__': |
203 | | - parser = OptionParser(usage='Usage: %prog [options] [slide-directory]') |
204 | | - parser.add_option( |
| 203 | + parser = ArgumentParser(usage='%(prog)s [options] [SLIDE-DIRECTORY]') |
| 204 | + parser.add_argument( |
205 | 205 | '-B', |
206 | 206 | '--ignore-bounds', |
207 | 207 | dest='DEEPZOOM_LIMIT_BOUNDS', |
208 | 208 | default=True, |
209 | 209 | action='store_false', |
210 | 210 | help='display entire scan area', |
211 | 211 | ) |
212 | | - parser.add_option( |
| 212 | + parser.add_argument( |
213 | 213 | '-c', '--config', metavar='FILE', dest='config', help='config file' |
214 | 214 | ) |
215 | | - parser.add_option( |
| 215 | + parser.add_argument( |
216 | 216 | '-d', |
217 | 217 | '--debug', |
218 | 218 | dest='DEBUG', |
219 | 219 | action='store_true', |
220 | 220 | help='run in debugging mode (insecure)', |
221 | 221 | ) |
222 | | - parser.add_option( |
| 222 | + parser.add_argument( |
223 | 223 | '-e', |
224 | 224 | '--overlap', |
225 | 225 | metavar='PIXELS', |
226 | 226 | dest='DEEPZOOM_OVERLAP', |
227 | | - type='int', |
| 227 | + type=int, |
228 | 228 | help='overlap of adjacent tiles [1]', |
229 | 229 | ) |
230 | | - parser.add_option( |
| 230 | + parser.add_argument( |
231 | 231 | '-f', |
232 | 232 | '--format', |
233 | 233 | metavar='{jpeg|png}', |
234 | 234 | dest='DEEPZOOM_FORMAT', |
235 | 235 | help='image format for tiles [jpeg]', |
236 | 236 | ) |
237 | | - parser.add_option( |
| 237 | + parser.add_argument( |
238 | 238 | '-l', |
239 | 239 | '--listen', |
240 | 240 | metavar='ADDRESS', |
241 | 241 | dest='host', |
242 | 242 | default='127.0.0.1', |
243 | 243 | help='address to listen on [127.0.0.1]', |
244 | 244 | ) |
245 | | - parser.add_option( |
| 245 | + parser.add_argument( |
246 | 246 | '-p', |
247 | 247 | '--port', |
248 | 248 | metavar='PORT', |
249 | 249 | dest='port', |
250 | | - type='int', |
| 250 | + type=int, |
251 | 251 | default=5000, |
252 | 252 | help='port to listen on [5000]', |
253 | 253 | ) |
254 | | - parser.add_option( |
| 254 | + parser.add_argument( |
255 | 255 | '-Q', |
256 | 256 | '--quality', |
257 | 257 | metavar='QUALITY', |
258 | 258 | dest='DEEPZOOM_TILE_QUALITY', |
259 | | - type='int', |
| 259 | + type=int, |
260 | 260 | help='JPEG compression quality [75]', |
261 | 261 | ) |
262 | | - parser.add_option( |
| 262 | + parser.add_argument( |
263 | 263 | '-s', |
264 | 264 | '--size', |
265 | 265 | metavar='PIXELS', |
266 | 266 | dest='DEEPZOOM_TILE_SIZE', |
267 | | - type='int', |
| 267 | + type=int, |
268 | 268 | help='tile size [254]', |
269 | 269 | ) |
| 270 | + parser.add_argument( |
| 271 | + 'SLIDE_DIR', |
| 272 | + metavar='SLIDE-DIRECTORY', |
| 273 | + nargs='?', |
| 274 | + help='slide directory', |
| 275 | + ) |
270 | 276 |
|
271 | | - (opts, args) = parser.parse_args() |
| 277 | + args = parser.parse_args() |
272 | 278 | config = {} |
273 | | - config_file = opts.config |
| 279 | + config_file = args.config |
274 | 280 | # Set only those settings specified on the command line |
275 | | - for k in dir(opts): |
276 | | - v = getattr(opts, k) |
| 281 | + for k in dir(args): |
| 282 | + v = getattr(args, k) |
277 | 283 | if not k.startswith('_') and v is not None: |
278 | 284 | config[k] = v |
279 | | - # Set slide directory if specified |
280 | | - try: |
281 | | - config['SLIDE_DIR'] = args[0] |
282 | | - except IndexError: |
283 | | - pass |
284 | 285 | app = create_app(config, config_file) |
285 | 286 |
|
286 | | - app.run(host=opts.host, port=opts.port, threaded=True) |
| 287 | + app.run(host=args.host, port=args.port, threaded=True) |
0 commit comments