127 filename = os.path.realpath(directory +
".zip")
128 log = logging.getLogger(
"zipdir")
129 if not os.path.isdir(directory):
130 log.warning(
'directory %s missing, creating empty .zip file', directory)
131 open(filename,
"ab").close()
133 msg =
"Zipping directory '%s'" 135 msg +=
" (without pre-compilation)" 136 log.info(msg, directory)
139 if os.path.exists(filename):
140 zipFile = open(filename,
"r+b")
145 zipFile = open(filename,
"ab")
148 if zipfile.is_zipfile(filename):
149 infolist = zipfile.ZipFile(filename).infolist()
152 (added, modified, untouched, removed) =
_zipChanges(directory, infolist)
153 if added
or modified
or removed:
155 z = zipfile.PyZipFile(tempBuf,
"w", zipfile.ZIP_DEFLATED)
156 for f
in added + modified + untouched:
157 src = os.path.join(directory, f)
160 log.debug(
"adding '%s'", f)
164 if os.path.exists(src +
'c'):
165 log.debug(
"removing old .pyc for '%s'", f)
167 log.debug(
"adding '%s'", f)
168 z.writepy(src, os.path.dirname(f))
171 zipFile.write(tempBuf.getvalue())
173 log.info(
"File '%s' closed", filename)
175 log.info(
"Nothing to do on '%s'", filename)
176 except UnicodeDecodeError, x:
177 log.error(
"Wrong encoding in file '%s':", src)
179 log.error(
"Probably you forgot the line '# -*- coding: utf-8 -*-'")
def checkEncoding(fileObj)
def _zipChanges(directory, infolist)
def zipdir(directory, no_pyc=False)