src/ldt/ldt/utils/zipfileext.py
author verrierj
Wed, 18 Jan 2012 16:29:02 +0100
changeset 415 4236f99104ba
parent 63 93325a5d61f0
child 1190 129d45eec68c
permissions -rw-r--r--
Annotation-types title are found in search API
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
93325a5d61f0 organize format and import
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     1
import zipfile
93325a5d61f0 organize format and import
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
     2
import os.path
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
class ZipFileExt(zipfile.ZipFile):
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    def unzip_into_dir(self, dir):
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
        if not os.path.exists(dir):
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
            os.mkdir(dir, 0777)
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
        for name in self.namelist():
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
            if name.endswith('/'):
13
97ab7b3191cf add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
                os.mkdir(os.path.join(dir, name))
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
            else:
13
97ab7b3191cf add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
                outfile = open(os.path.join(dir, name), 'wb')
0
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
                outfile.write(self.read(name))
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
                outfile.close()
bdf22b140727 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15