upload_docs_4.py 690 B

1234567891011121314151617
  1. def create_zipfile(self, filename):
  2. zip_file = zipfile.ZipFile(filename, "w")
  3. try:
  4. self.mkpath(self.target_dir) # just in case
  5. for root, dirs, files in os.walk(self.target_dir):
  6. if root == self.target_dir and not files:
  7. raise DistutilsOptionError(
  8. "no files found in upload directory '%s'"
  9. % self.target_dir)
  10. for name in files:
  11. full = os.path.join(root, name)
  12. relative = root[len(self.target_dir):].lstrip(os.path.sep)
  13. dest = os.path.join(relative, name)
  14. zip_file.write(full, dest)
  15. finally:
  16. zip_file.close()