def convertOld(name): with ZipFile('%s.zip' % name, 'w') as zip: zone = Zone() ofiles = readS3D(file('eqdata/%s_obj.s3d' % name, 'rb')) zfiles = readS3D(file('eqdata/%s.s3d' % name, 'rb')) ofiles, zfiles = s3dFallback(ofiles, zfiles) Wld(ofiles['%s_obj.wld' % name], ofiles).convertObjects(zone) Wld(zfiles['objects.wld'], zfiles).convertObjects(zone) Wld(zfiles['%s.wld' % name], zfiles).convertZone(zone) zone.output(zip)
def convertNew(name): with ZipFile('%s.zip' % name, 'w') as zip: zone = Zone() zfiles = readS3D(file(eqPath('%s.eqg' % name), 'rb')) #for fn, data in zfiles.items(): # file('s3data/%s' % fn, 'wb').write(data) if '%s.zon' % name in zfiles: readZon(zfiles['%s.zon' % name], zone, zfiles) else: readZon(file(eqPath('%s.zon' % name), 'rb').read(), zone, zfiles) zone.output(zip)
def convertOld(name): with ZipFile('%s.zip' % name, 'w') as zip: zone = Zone() objfiles = {} for fn in glob(eqPath('%s_obj*.s3d' % name)): objfiles[fn.split('/')[-1][:-4]] = readS3D(file(fn, 'rb')) zfiles = readS3D(file(eqPath('%s.s3d' % name), 'rb')) flists = objfiles.values() + [zfiles] flists = s3dFallback(*flists) for i, fn in enumerate(objfiles.keys()): objfiles[fn] = flists[i] zfiles = flists[-1] for fn, sf in objfiles.items(): print fn Wld(sf['%s.wld' % fn], sf).convertObjects(zone) Wld(zfiles['objects.wld'], zfiles).convertObjects(zone) Wld(zfiles['lights.wld'], zfiles).convertLights(zone) Wld(zfiles['%s.wld' % name], zfiles).convertZone(zone) zone.output(zip)
def main(): parser = argparse.ArgumentParser(description='Decompress S3D/EQG files') parser.add_argument('file', type=unicode, help='file to decompress') parser.add_argument( '-o', '--outdir', nargs='?', dest='outdir', help= 'output directory (default: make a new subdirectory with the same name)' ) parser.add_argument('-v', dest='verbose', action='store_true', help='show all files written') args = parser.parse_args() try: files = s3d.readS3D(file(args.file)) except: print >> sys.stderr, 'Could not open file:', args.file return 1 if args.outdir is None: args.outdir = '_'.join(args.file.rsplit('.', 1)) try: os.mkdir(args.outdir) except: pass for fn, data in files.items(): if args.verbose: print fn try: with file('%s/%s' % (args.outdir, fn), 'wb') as fp: fp.write(data) except: print >> sys.stderr, 'Could not open file for writing:', '%s/%s' % ( args.outdir, fn) return 1 return 0
def convertChr(name): name = name[:-4] files = readS3D(file(eqPath('%s_chr.s3d' % name), 'rb')) with ZipFile('%s_chr.zip' % name, 'w') as zip: Wld(files['%s_chr.wld' % name], files).convertCharacters(zip)
def convertChr(name): name = name[:-4] files = readS3D(file('eqdata/%s_chr.s3d' % name, 'rb')) Wld(files['%s_chr.wld' % name], files).convertCharacters()