Skip to content

Commit 9e78772

Browse files
author
James Polera
committed
Initial commit.
0 parents  commit 9e78772

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from zippy import Zip, Unzip

zippy.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from zipfile import ZipFile, ZIP_STORED
2+
from os.path import isdir
3+
from os import walk, sep
4+
5+
class Zip(ZipFile):
6+
def __init__(self, filename, noisy=False, compression=ZIP_STORED):
7+
self.file = ZipFile(filename, "w", compression)
8+
self.noisy = noisy
9+
10+
def add_files(self, files=[]):
11+
if self.noisy:
12+
print files
13+
for filename in files:
14+
if self.noisy:
15+
print "Adding file %s" % filename
16+
17+
if isdir(filename):
18+
for (dirname,dirs,filenames) in walk(filename):
19+
self.add_files(map(lambda x: "%s%s%s" % (dirname,sep,x),filenames))
20+
else:
21+
self.file.write(filename)
22+
23+
class Unzip(ZipFile):
24+
def get_contents(self):
25+
return self.namelist()
26+
contents = property(get_contents)
27+
28+
def to_path(self, path):
29+
try:
30+
self.extractall(path)
31+
return True
32+
except (IOError, WindowsError):
33+
print "Could not extract %s to %s" % (self.filename, path)
34+
return False

0 commit comments

Comments
 (0)