Use ZODBConnection class instead of ZEOConnection to handle any ZODB storage for medias converter
authorThierry Florac <thierry.florac@onf.fr>
Thu, 11 Jan 2018 17:14:45 +0100
changeset 65 d38220c1116e
parent 64 73d618e60b73
child 66 6f502c50ef09
Use ZODBConnection class instead of ZEOConnection to handle any ZODB storage for medias converter
src/pyams_media/include.py
src/pyams_media/interfaces/__init__.py
src/pyams_media/process.py
src/pyams_media/utility.py
src/pyams_media/zmi/__init__.py
--- a/src/pyams_media/include.py	Thu Jan 11 17:12:00 2018 +0100
+++ b/src/pyams_media/include.py	Thu Jan 11 17:14:45 2018 +0100
@@ -80,6 +80,8 @@
                     process.start()
                     if process.is_alive():
                         atexit.register(process_exit_func, process=process)
+                        logger.debug('Started medias conversion process {0!r} with PID {1}...'.format(process,
+                                                                                                      process.pid))
             finally:
                 if process and not process.is_alive():
                     process.terminate()
--- a/src/pyams_media/interfaces/__init__.py	Thu Jan 11 17:12:00 2018 +0100
+++ b/src/pyams_media/interfaces/__init__.py	Thu Jan 11 17:14:45 2018 +0100
@@ -175,10 +175,11 @@
 class IMediaConversionUtility(Interface):
     """Media conversion client interface"""
 
-    zeo_connection = Choice(title=_("ZEO connection name"),
-                            description=_("Name of ZEO connection utility defining converter connection"),
-                            required=False,
-                            vocabulary="PyAMS ZEO connections")
+    zodb_name = Choice(title=_("ZODB connection name"),
+                       description=_("Name of ZODB connection defining converter connection"),
+                       required=False,
+                       default='',
+                       vocabulary="PyAMS ZODB connections")
 
     # Video conversions attributes
     video_formats = List(title=_("Video formats conversions"),
--- a/src/pyams_media/process.py	Thu Jan 11 17:12:00 2018 +0100
+++ b/src/pyams_media/process.py	Thu Jan 11 17:14:45 2018 +0100
@@ -31,7 +31,7 @@
 
 # import packages
 from pyams_utils.registry import set_local_registry, get_utility
-from pyams_utils.zodb import ZEOConnection
+from pyams_utils.zodb import ZODBConnection
 from pyams_zmq.handler import ZMQMessageHandler
 from pyams_zmq.process import ZMQProcess
 from pyramid.threadlocal import manager as threadlocal_manager
@@ -56,24 +56,22 @@
         # Check settings
         settings = self.settings
         logger.debug("Checking conversion parameters: {0}".format(str(settings)))
-        zeo_settings = settings.get('zeo')
         media_id = settings.get('media')
         media_format = settings.get('format')
-        if not (zeo_settings and media_id and media_format):
+        if not (media_id and media_format):
             logger.warning('Bad conversion request: {0}'.format(str(settings)))
             return
         converter = registry.queryUtility(IMediaConverter, media_format)
         if converter is None:
             logger.warning('Missing media converter: {0}'.format(media_format))
             return
-        # Open ZEO connection
+        # Open ZODB connection
         manager = None
-        connection_info = ZEOConnection()
-        connection_info.update(zeo_settings)
-        logger.debug("Opening ZEO connection...")
-        storage, db = connection_info.get_connection(get_storage=True)
+        zodb_name = settings.get('zodb_name')
+        logger.debug("Opening ZODB connection...")
+        zodb = ZODBConnection(name=zodb_name)
+        connection = zodb.get_connection()
         try:
-            connection = db.open()
             root = connection.root()
             logger.debug("Getting connection root {0!r}".format(root))
             application_name = registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY, PYAMS_APPLICATION_DEFAULT_NAME)
@@ -113,7 +111,6 @@
             if manager is not None:
                 manager.abort()
             connection.close()
-            storage.close()
             threadlocal_manager.pop()
 
 
--- a/src/pyams_media/utility.py	Thu Jan 11 17:12:00 2018 +0100
+++ b/src/pyams_media/utility.py	Thu Jan 11 17:14:45 2018 +0100
@@ -18,7 +18,6 @@
 # import interfaces
 from pyams_media.interfaces import IMediaConversionUtility, CONVERTER_HANDLER_KEY, CUSTOM_AUDIO_TYPES, \
     CUSTOM_VIDEO_TYPES
-from pyams_utils.interfaces.zeo import IZEOConnection
 from zope.intid.interfaces import IIntIds
 
 # import packages
@@ -35,7 +34,7 @@
 class MediaConversionUtility(Persistent, Contained):
     """Medias conversions utility"""
 
-    zeo_connection = FieldProperty(IMediaConversionUtility['zeo_connection'])
+    zodb_name = FieldProperty(IMediaConversionUtility['zodb_name'])
 
     video_formats = FieldProperty(IMediaConversionUtility['video_formats'])
     video_frame_size = FieldProperty(IMediaConversionUtility['video_frame_size'])
@@ -75,11 +74,8 @@
         socket = self._get_socket()
         if socket is None:
             return [501, "No socket handler defined in configuration file"]
-        if not self.zeo_connection:
-            return [502, "Missing ZEO connection"]
-        zeo = get_utility(IZEOConnection, self.zeo_connection)
         intids = get_utility(IIntIds)
-        settings = {'zeo': zeo.get_settings(),
+        settings = {'zodb_name': self.zodb_name,
                     'media': intids.register(media),
                     'format': format}
         socket.send_json(['convert', settings])
@@ -90,7 +86,5 @@
         socket = self._get_socket()
         if socket is None:
             return [501, "No socket handler defined in configuration file"]
-        if not self.zeo_connection:
-            return [502, "Missing ZEO connection"]
         socket.send_json(['test', {}])
         return zmq_response(socket)
--- a/src/pyams_media/zmi/__init__.py	Thu Jan 11 17:12:00 2018 +0100
+++ b/src/pyams_media/zmi/__init__.py	Thu Jan 11 17:14:45 2018 +0100
@@ -52,7 +52,7 @@
 
     legend = _("Update medias converter properties")
 
-    fields = field.Fields(IMediaConversionUtility).select('zeo_connection')
+    fields = field.Fields(IMediaConversionUtility).select('zodb_name')
     label_css_class = 'control-label col-md-4'
     input_css_class = 'col-md-8'