Export API

This commit is contained in:
Julien Duponchelle committed 2016-03-30 17:42:00 +02:00
1 parent f39af9deb7
commit 879591eaf5
6 files changed
+108 -1

No files matched your search

+29
View File
@@ -20,6 +20,8 @@ import os
import shutil
import asyncio
import hashlib
import zipstream
import zipfile
from uuid import UUID, uuid4
from .port_manager import PortManager
@@ -507,3 +509,30 @@ class Project:
break
m.update(buf)
return m.hexdigest()
def export(self):
"""
Export the project as zip. It's a ZipStream object.
The file will be read chunk by chunk when you iterate on
the zip.
It will ignore some files like snapshots and
:returns: ZipStream object
"""
z = zipstream.ZipFile()
# topdown allo to modify the list of directory in order to ignore
# directory
for root, dirs, files in os.walk(self._path, topdown=True):
# Remove snapshots
if "project-files" in root:
dirs[:] = [d for d in dirs if d != "snapshots"]
# Ignore log files and OS noise
files = [f for f in files if not f.endswith('_log.txt') and not f.endswith('.log') and f != '.DS_Store']
for file in files:
path = os.path.join(root, file)
z.write(path, os.path.relpath(path, self._path))
return z