view sword2-libraries-pyinstaller-compatible/tests/testzip.py @ 16:8b69bba225c9

Added pyinstaller compatible sword2 python libraries
author Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk>
date Tue, 29 May 2012 12:42:49 +0100
parents
children
line wrap: on
line source
import zipfile,os

data = './footest/'

if zipfile.is_zipfile(data):
	zipf = data
elif os.path.isfile(data): # This is a single file
	dataname = os.path.basename(data)
	zipf = os.path.splitext(dataname)[0]+".zip"
	myzip = zipfile.ZipFile(zipf, "w")
	myzip.write(data)
	myzip.close()
elif os.path.isdir(data): # This is a directory, zip all the files and maintain the structure!
	dataname = os.path.basename(os.path.normpath(data))
	zipf = dataname+".zip"
	myzip = zipfile.ZipFile(zipf, "w")
	# get the os.walk
	for root, dirs, files in os.walk(data):
		for name in files:
			myzip.write(os.path.join(root,name))
	myzip.close()