|
19 | 19 | ''' |
20 | 20 |
|
21 | 21 | import sys, json, os, sys, re, fnmatch |
| 22 | +import argparse |
22 | 23 | import lxml.etree as e |
23 | 24 | import lxml.html as html |
24 | 25 |
|
@@ -409,29 +410,30 @@ def process_identifier(out, redirects, root, link, item_ident, item_type, |
409 | 410 | out.write(line) |
410 | 411 |
|
411 | 412 | def main(): |
412 | | - if len(sys.argv) != 3 and not (len(sys.argv) > 2 and sys.argv[2] == 'debug'): |
413 | | - print('''Please provide the file name of the index as the first argument |
414 | | - and the file name of the output as the second ''') |
415 | | - sys.exit(1) |
416 | 413 |
|
417 | | - MAX_CODE_LINES = 6 |
| 414 | + parser = argparse.ArgumentParser(prog='index2ddg.py') |
| 415 | + parser.add_argument('index', type=str, |
| 416 | + help='The path to the XML index containing identifier data') |
| 417 | + parser.add_argument('output', type=str, |
| 418 | + help='The path to destination output.txt file') |
| 419 | + parser.add_argument('--debug', action='store_true', default=False, |
| 420 | + help='Enables debug mode.') |
| 421 | + parser.add_argument('--debug_ident', type=str, default=None, |
| 422 | + help='Processes only the identifiers that match debug_ident') |
| 423 | + args = parser.parse_args() |
418 | 424 |
|
419 | 425 | # If a the second argument is 'debug', the program switches to debug mode and |
420 | 426 | # prints everything to stdout. If the third argument is provided, the program |
421 | 427 | # processes only the identifiers that match the provided string |
422 | 428 |
|
423 | | - debug = False |
424 | | - debug_ident = None |
425 | | - if len(sys.argv) > 2 and sys.argv[2] == 'debug': |
426 | | - debug = True |
427 | | - if len(sys.argv) > 3: |
428 | | - debug_ident = sys.argv[3] |
| 429 | + debug = args.debug |
| 430 | + debug_ident = args.debug_ident |
429 | 431 |
|
430 | 432 | # track the statistics of number of lines used by the entries |
431 | 433 | debug_num_lines = [0 for i in range(40)] |
432 | 434 |
|
433 | | - index_file = sys.argv[1] |
434 | | - output_file = sys.argv[2] |
| 435 | + index_file = args.index |
| 436 | + output_file = args.output |
435 | 437 |
|
436 | 438 | # a map that stores information about location and type of identifiers |
437 | 439 | # it's two level map: full_link maps to a dict that has full_name map to |
|
0 commit comments