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

Function main

tools/python-3.11.9-amd64/Lib/tarfile.py:2802–2895  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2800
2801
2802def main():
2803 import argparse
2804
2805 description = 'A simple command-line interface for tarfile module.'
2806 parser = argparse.ArgumentParser(description=description)
2807 parser.add_argument('-v', '--verbose', action='store_true', default=False,
2808 help='Verbose output')
2809 parser.add_argument('--filter', metavar='<filtername>',
2810 choices=_NAMED_FILTERS,
2811 help='Filter for extraction')
2812
2813 group = parser.add_mutually_exclusive_group(required=True)
2814 group.add_argument('-l', '--list', metavar='<tarfile>',
2815 help='Show listing of a tarfile')
2816 group.add_argument('-e', '--extract', nargs='+',
2817 metavar=('<tarfile>', '<output_dir>'),
2818 help='Extract tarfile into target dir')
2819 group.add_argument('-c', '--create', nargs='+',
2820 metavar=('<name>', '<file>'),
2821 help='Create tarfile from sources')
2822 group.add_argument('-t', '--test', metavar='<tarfile>',
2823 help='Test if a tarfile is valid')
2824
2825 args = parser.parse_args()
2826
2827 if args.filter and args.extract is None:
2828 parser.exit(1, '--filter is only valid for extraction\n')
2829
2830 if args.test is not None:
2831 src = args.test
2832 if is_tarfile(src):
2833 with open(src, 'r') as tar:
2834 tar.getmembers()
2835 print(tar.getmembers(), file=sys.stderr)
2836 if args.verbose:
2837 print('{!r} is a tar archive.'.format(src))
2838 else:
2839 parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
2840
2841 elif args.list is not None:
2842 src = args.list
2843 if is_tarfile(src):
2844 with TarFile.open(src, 'r:*') as tf:
2845 tf.list(verbose=args.verbose)
2846 else:
2847 parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
2848
2849 elif args.extract is not None:
2850 if len(args.extract) == 1:
2851 src = args.extract[0]
2852 curdir = os.curdir
2853 elif len(args.extract) == 2:
2854 src, curdir = args.extract
2855 else:
2856 parser.exit(1, parser.format_help())
2857
2858 if is_tarfile(src):
2859 with TarFile.open(src, 'r:*') as tf:

Callers 1

tarfile.pyFile · 0.70

Calls 15

parse_argsMethod · 0.95
exitMethod · 0.95
format_helpMethod · 0.95
is_tarfileFunction · 0.85
getmembersMethod · 0.80
splitextMethod · 0.80
openFunction · 0.70
printFunction · 0.50
add_argumentMethod · 0.45
formatMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected