mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Export API
This commit is contained in:
6 files changed
+108
-1
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user