Optimize storage of drawing

If the drawing contain an image we extract it

Fix #591
This commit is contained in:
Julien Duponchelle committed 2016-07-13 16:18:22 +02:00
1 parent 3dccfbb852
commit 8be1e77a2e
6 files changed
+244 -6

No files matched your search

+26 -1
View File
@@ -125,12 +125,21 @@ class Project:
@property
def captures_directory(self):
"""
Location of the captures file
Location of the captures files
"""
path = os.path.join(self._path, "project-files", "captures")
os.makedirs(path, exist_ok=True)
return path
@property
def pictures_directory(self):
"""
Location of the images files
"""
path = os.path.join(self._path, "project-files", "images")
os.makedirs(path, exist_ok=True)
return path
@property
def computes(self):
"""
@@ -352,9 +361,25 @@ class Project:
def close(self):
for compute in self._project_created_on_compute:
yield from compute.post("/projects/{}/close".format(self._id))
self._cleanPictures()
self.reset()
self._status = "closed"
def _cleanPictures(self):
"""
Delete unused images
"""
try:
pictures = set(os.listdir(self.pictures_directory))
for drawing in self._drawings.values():
pictures.remove(drawing.ressource_filename)
for pict in pictures:
os.remove(os.path.join(self.pictures_directory, pict))
except OSError as e:
log.warning(str(e))
@asyncio.coroutine
def delete(self):
yield from self.close()