mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-23 14:42:28 +00:00
Support selecting a compression type when exporting a project.
This commit is contained in:
parent
af80b0bb6e
commit
0ae66a2608
@ -96,6 +96,7 @@ class Snapshot:
|
|||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
# Do not compress the snapshots
|
||||||
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
||||||
await export_project(zstream, self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
await export_project(zstream, self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
||||||
async with aiofiles.open(self.path, 'wb') as f:
|
async with aiofiles.open(self.path, 'wb') as f:
|
||||||
|
@ -36,7 +36,7 @@ class ApplianceHandler:
|
|||||||
async def list_appliances(request, response):
|
async def list_appliances(request, response):
|
||||||
|
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
if request.query.get("update", "no") == "yes":
|
if request.query.get("update", "no").lower() == "yes":
|
||||||
await controller.appliance_manager.download_appliances()
|
await controller.appliance_manager.download_appliances()
|
||||||
controller.appliance_manager.load_appliances()
|
controller.appliance_manager.load_appliances()
|
||||||
response.json([c for c in controller.appliance_manager.appliances.values()])
|
response.json([c for c in controller.appliance_manager.appliances.values()])
|
||||||
|
@ -305,12 +305,25 @@ class ProjectHandler:
|
|||||||
|
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
project = await controller.get_loaded_project(request.match_info["project_id"])
|
project = await controller.get_loaded_project(request.match_info["project_id"])
|
||||||
|
if request.query.get("include_images", "no").lower() == "yes":
|
||||||
|
include_images = True
|
||||||
|
else:
|
||||||
|
include_images = False
|
||||||
|
compression_query = request.query.get("compression", "zip").lower()
|
||||||
|
if compression_query == "zip":
|
||||||
|
compression = zipfile.ZIP_DEFLATED
|
||||||
|
elif compression_query == "none":
|
||||||
|
compression = zipfile.ZIP_STORED
|
||||||
|
elif compression_query == "bzip2":
|
||||||
|
compression = zipfile.ZIP_BZIP2
|
||||||
|
elif compression_query == "lzma":
|
||||||
|
compression = zipfile.ZIP_LZMA
|
||||||
|
|
||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
with aiozipstream.ZipFile(compression=zipfile.ZIP_DEFLATED) as zstream:
|
with aiozipstream.ZipFile(compression=compression) as zstream:
|
||||||
await export_project(zstream, project, tmp_dir, include_images=bool(int(request.query.get("include_images", "0"))))
|
await export_project(zstream, project, tmp_dir, include_images=include_images)
|
||||||
|
|
||||||
# We need to do that now because export could failed and raise an HTTP error
|
# We need to do that now because export could failed and raise an HTTP error
|
||||||
# that why response start need to be the later possible
|
# that why response start need to be the later possible
|
||||||
@ -430,23 +443,7 @@ class ProjectHandler:
|
|||||||
raise aiohttp.web.HTTPForbidden()
|
raise aiohttp.web.HTTPForbidden()
|
||||||
path = os.path.join(project.path, path)
|
path = os.path.join(project.path, path)
|
||||||
|
|
||||||
response.content_type = "application/octet-stream"
|
await response.stream_file(path)
|
||||||
response.set_status(200)
|
|
||||||
response.enable_chunked_encoding()
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
await response.prepare(request)
|
|
||||||
while True:
|
|
||||||
data = f.read(CHUNK_SIZE)
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
await response.write(data)
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
|
||||||
raise aiohttp.web.HTTPNotFound()
|
|
||||||
except PermissionError:
|
|
||||||
raise aiohttp.web.HTTPForbidden()
|
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
r"/projects/{project_id}/files/{path:.+}",
|
r"/projects/{project_id}/files/{path:.+}",
|
||||||
@ -475,7 +472,7 @@ class ProjectHandler:
|
|||||||
response.set_status(200)
|
response.set_status(200)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, 'wb+') as f:
|
async with aiofiles.open(path, 'wb+') as f:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
chunk = await request.content.read(CHUNK_SIZE)
|
chunk = await request.content.read(CHUNK_SIZE)
|
||||||
@ -483,7 +480,7 @@ class ProjectHandler:
|
|||||||
raise aiohttp.web.HTTPRequestTimeout(text="Timeout when writing to file '{}'".format(path))
|
raise aiohttp.web.HTTPRequestTimeout(text="Timeout when writing to file '{}'".format(path))
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
f.write(chunk)
|
await f.write(chunk)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise aiohttp.web.HTTPNotFound()
|
raise aiohttp.web.HTTPNotFound()
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
Loading…
Reference in New Issue
Block a user