def _zip_directory(self): """ Recursively zip a diorectory. """ # Check if we have zlib installed -- which allows us to # compress the resulting zip file. Otherwise just # store it. if has_zlib: zmode = zipfile.ZIP_DEFLATED self._debug('Using ZIP_DEFLATED') else: zmode = zipfile.ZIP_STORED self._debug('Using ZIP_STORED') with zipfile.ZipFile(self.dest_path, 'w', zmode) as z: for f in list_files(self.src_directory): # Check ignore if self._ignored(f): self._debug('Ignoring file "{0}"'.format(f)) continue rel_path = os.path.relpath(f, self.src_directory) self._debug('Writing "{0}" to zip archive.'.format(rel_path)) z.write(f, rel_path)
def _clean_pyc(self): """ Remove all files ending in '.pyc'. """ self._debug('Cleaning out ".pyc" files') # Search for all files that end with the extension '.pyc' # and remove them. for f in list_files(self.src_directory): if f.endswith('.pyc'): self._debug('Removing "{0}"'.format(f)) os.remove(f)