MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / main

Function main

tools/python-3.11.9-amd64/Lib/gzip.py:619–665  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

617
618
619def main():
620 from argparse import ArgumentParser
621 parser = ArgumentParser(description=
622 "A simple command line interface for the gzip module: act like gzip, "
623 "but do not delete the input file.")
624 group = parser.add_mutually_exclusive_group()
625 group.add_argument('--fast', action='store_true', help='compress faster')
626 group.add_argument('--best', action='store_true', help='compress better')
627 group.add_argument("-d", "--decompress", action="store_true",
628 help="act like gunzip instead of gzip")
629
630 parser.add_argument("args", nargs="*", default=["-"], metavar='file')
631 args = parser.parse_args()
632
633 compresslevel = _COMPRESS_LEVEL_TRADEOFF
634 if args.fast:
635 compresslevel = _COMPRESS_LEVEL_FAST
636 elif args.best:
637 compresslevel = _COMPRESS_LEVEL_BEST
638
639 for arg in args.args:
640 if args.decompress:
641 if arg == "-":
642 f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
643 g = sys.stdout.buffer
644 else:
645 if arg[-3:] != ".gz":
646 sys.exit(f"filename doesn't end in .gz: {arg!r}")
647 f = open(arg, "rb")
648 g = builtins.open(arg[:-3], "wb")
649 else:
650 if arg == "-":
651 f = sys.stdin.buffer
652 g = GzipFile(filename="", mode="wb", fileobj=sys.stdout.buffer,
653 compresslevel=compresslevel)
654 else:
655 f = builtins.open(arg, "rb")
656 g = open(arg + ".gz", "wb")
657 while True:
658 chunk = f.read(io.DEFAULT_BUFFER_SIZE)
659 if not chunk:
660 break
661 g.write(chunk)
662 if g is not sys.stdout.buffer:
663 g.close()
664 if f is not sys.stdin.buffer:
665 f.close()
666
667if __name__ == '__main__':
668 main()

Callers 1

gzip.pyFile · 0.70

Calls 11

parse_argsMethod · 0.95
readMethod · 0.95
writeMethod · 0.95
closeMethod · 0.95
ArgumentParserClass · 0.90
GzipFileClass · 0.85
openFunction · 0.70
add_argumentMethod · 0.45
exitMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected