web/ldt/utils/zipfileext.py
author wakimd
Tue, 16 Nov 2010 14:15:07 +0100
changeset 9 22ab430e9b64
parent 1 3a30d255c235
permissions -rw-r--r--
Corrections on models and general structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
import zipfile, os, os.path
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
class ZipFileExt(zipfile.ZipFile):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
    def unzip_into_dir(self, dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
        if not os.path.exists(dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
            os.mkdir(dir, 0777)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
        for name in self.namelist():
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
            if name.endswith('/'):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
                os.mkdir(os.path.join(dir,name))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
            else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
                outfile = open(os.path.join(dir,name), 'wb')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
                outfile.write(self.read(name))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
                outfile.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14