comparison shasum.py @ 3:5a6ed622846c

Add comman line switches for reading in binary and text mode
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 04 Dec 2020 12:05:55 +0100
parents 5510a39a2d04
children 67d10529ce88
comparison
equal deleted inserted replaced
2:5510a39a2d04 3:5a6ed622846c
21 21
22 CHUNK_SIZE = 1024 * 1024 * 1024 22 CHUNK_SIZE = 1024 * 1024 * 1024
23 23
24 24
25 def main(argv=None): 25 def main(argv=None):
26 if argv is None:
27 argv = sys.argv[1:]
28
29 aparser = argparse.ArgumentParser( 26 aparser = argparse.ArgumentParser(
30 description="Python implementation of shasum", 27 description="Python implementation of shasum",
31 fromfile_prefix_chars='@') 28 fromfile_prefix_chars='@')
29 aparser.add_argument(
30 "--binary", "-b", action="store_false", dest="text_mode", default=False,
31 help="read in binary mode (default)")
32 aparser.add_argument(
33 "--text", "-t", action="store_true", dest="text_mode", default=False,
34 help="read in text mode (not yet supported)")
32 aparser.add_argument( 35 aparser.add_argument(
33 "files", nargs="*", metavar="FILE") 36 "files", nargs="*", metavar="FILE")
34 37
35 opts = aparser.parse_args(args=argv) 38 opts = aparser.parse_args(args=argv)
36 39
40 if opts.text_mode:
41 print("ERROR: text mode not supported", file=sys.stderr)
42 sys.exit(78) # :manpage:`sysexits(3)` EX_CONFIG
37 if not opts.files: 43 if not opts.files:
38 opts.files.append("-") 44 opts.files.append("-")
39 for fn in opts.files: 45 for fn in opts.files:
40 if fn == "-": 46 if fn == "-":
41 if PY2: 47 if PY2: