diff sat/core/sat_main.py @ 3066:2cc2f65379f7

core: added imageCheck and imageResize methods: imageCheck will give a report on image, notably it will tell if it's too big and needs to be resized before a transfer. imageResize will create a new image with the requested size and return a path to it.
author Goffi <goffi@goffi.org>
date Tue, 29 Oct 2019 20:38:39 +0100
parents fee60f17ebac
children d1464548055a
line wrap: on
line diff
--- a/sat/core/sat_main.py	Tue Oct 29 20:24:29 2019 +0100
+++ b/sat/core/sat_main.py	Tue Oct 29 20:38:39 2019 +0100
@@ -40,8 +40,10 @@
 from sat.memory import encryption
 from sat.tools import async_trigger as trigger
 from sat.tools import utils
+from sat.tools import images
 from sat.tools.common import dynamic_import
 from sat.tools.common import regex
+from sat.tools.common import data_format
 from sat.stdui import ui_contact_list, ui_profile_manager
 import sat.plugins
 
@@ -161,6 +163,8 @@
         self.bridge.register_method("loadParamsTemplate", self.memory.load_xml)
         self.bridge.register_method("sessionInfosGet", self.getSessionInfos)
         self.bridge.register_method("namespacesGet", self.getNamespaces)
+        self.bridge.register_method("imageCheck", self._imageCheck)
+        self.bridge.register_method("imageResize", self._imageResize)
 
         self.memory.initialized.addCallback(self._postMemoryInit)
 
@@ -632,6 +636,17 @@
             }
         return defer.succeed(data)
 
+    # images
+
+    def _imageCheck(self, path):
+        report = images.checkImage(self, path)
+        return data_format.serialise(report)
+
+    def _imageResize(self, path, width, height):
+        d = images.resizeImage(path, (width, height))
+        d.addCallback(lambda new_image_path: str(new_image_path))
+        return d
+
     # local dirs
 
     def getLocalPath(self, client, dir_name, *extra_path, **kwargs):