MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

Lib/tarfile.py:3037–3133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3035
3036
3037def main():
3038 import argparse
3039
3040 description = 'A simple command-line interface for tarfile module.'
3041 parser = argparse.ArgumentParser(description=description, color=True)
3042 parser.add_argument('-v', '--verbose', action='store_true', default=False,
3043 help='Verbose output')
3044 parser.add_argument('--filter', metavar='<filtername>',
3045 choices=_NAMED_FILTERS,
3046 help='Filter for extraction')
3047
3048 group = parser.add_mutually_exclusive_group(required=True)
3049 group.add_argument('-l', '--list', metavar='<tarfile>',
3050 help='Show listing of a tarfile')
3051 group.add_argument('-e', '--extract', nargs='+',
3052 metavar=('<tarfile>', '<output_dir>'),
3053 help='Extract tarfile into target dir')
3054 group.add_argument('-c', '--create', nargs='+',
3055 metavar=('<name>', '<file>'),
3056 help='Create tarfile from sources')
3057 group.add_argument('-t', '--test', metavar='<tarfile>',
3058 help='Test if a tarfile is valid')
3059
3060 args = parser.parse_args()
3061
3062 if args.filter and args.extract is None:
3063 parser.exit(1, '--filter is only valid for extraction\n')
3064
3065 if args.test is not None:
3066 src = args.test
3067 if is_tarfile(src):
3068 with open(src, 'r') as tar:
3069 tar.getmembers()
3070 print(tar.getmembers(), file=sys.stderr)
3071 if args.verbose:
3072 print('{!r} is a tar archive.'.format(src))
3073 else:
3074 parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
3075
3076 elif args.list is not None:
3077 src = args.list
3078 if is_tarfile(src):
3079 with TarFile.open(src, 'r:*') as tf:
3080 tf.list(verbose=args.verbose)
3081 else:
3082 parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
3083
3084 elif args.extract is not None:
3085 if len(args.extract) == 1:
3086 src = args.extract[0]
3087 curdir = os.curdir
3088 elif len(args.extract) == 2:
3089 src, curdir = args.extract
3090 else:
3091 parser.exit(1, parser.format_help())
3092
3093 if is_tarfile(src):
3094 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
lenFunction · 0.85
getmembersMethod · 0.80
splitextMethod · 0.80
openFunction · 0.70
printFunction · 0.50
add_argumentMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected