INNER CODE UNIT · Python

zip

TheAssemblyArmada/Vanilla-Conquer · scripts/tgautil.py:93

def zip(args):
    if not os.path.isdir(args.directory):
        print >> sys.stderr, '\'{}\' does not exist or is not a directory\n'.format(args.directory)
        sys.exit(1)
    tga_files = [f for f in os.listdir(args.directory) if os.path.isfile(os.path.join(args.directory, f)) and os.path.splitext(f)[1].lower() == '.tga']
    if not tga_files:
        print >> sys.stderr, '\'{}\' does not contain any TGA files\n'.format(args.directory)
        sys.exit(1)
    out_file = os.path.basename(os.path.normpath(args.directory)).upper() + '.ZIP'
    if os.path.exists(out_file):
        if not os.path.isfile(out_file):
            print >> sys.stderr, '\'{}\' already exists and is not a file\n'.format(out_file)
            sys.exit(1)
        if not args.yes and not overwrite_prompt('\'{}\' already exists, overwrite?'.format(out_file)):
            sys.exit(0)
    with zipfile.ZipFile(out_file, 'w', zipfile.ZIP_DEFLATED) as zip:
        for tga_file in tga_files:
            tga_data, meta = crop(os.path.join(args.directory, tga_file))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…