comparison bin/ix.py @ 99:d48537c4cbae

triple args checked, filename opened
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 16 Apr 2021 18:28:00 +0000
parents 1a4c5fdc2923
children f7623dbd8eb5
comparison
equal deleted inserted replaced
98:1a4c5fdc2923 99:d48537c4cbae
50 parser.add_argument('offset',type=int, 50 parser.add_argument('offset',type=int,
51 help='start position in bytes of gzipped record', 51 help='start position in bytes of gzipped record',
52 nargs='?') 52 nargs='?')
53 parser.add_argument('filename', 53 parser.add_argument('filename',
54 help='name of gzipped Common Crawl WARC-format file', 54 help='name of gzipped Common Crawl WARC-format file',
55 nargs='?') 55 nargs='?',
56 type=argparse.FileType('rb',0))
56 # Hack the order of optional and positional in the help output 57 # Hack the order of optional and positional in the help output
57 parser._action_groups.sort(key=lambda g:g.title) 58 parser._action_groups.sort(key=lambda g:g.title)
58 #parser.print_help() 59 #parser.print_help()
59 pa=parser.parse_args(sys.argv[1:]) 60 pa=parser.parse_args(sys.argv[1:])
60 # We have to enforce our own check.. 61 # We have to enforce our own check..
61 print(pa) 62 print(pa,file=sys.stderr)
63 if pa.length is not None and (
64 pa.offset is None or pa.filename is None):
65 parser.error("length, offset and filename must all be supplied together")
66
67 buf=bytearray(1024*1024)
62 68