[elbe-devel] [PATCH 5/6] elbe: updated: convert soaplib to spyne

Kurt Kanzenbach kurt at linutronix.de
Thu Mar 23 13:45:46 CET 2017


Soaplib is deprecated and got removed in Debian stretch.

Signed-off-by: Kurt Kanzenbach <kurt at linutronix.de>
---
 debian/control               |  2 +-
 elbepack/commands/updated.py | 15 +++++++++++++--
 elbepack/updated.py          | 36 ++++++++++++++++++------------------
 test/updated.py              | 23 ++++++++++++-----------
 4 files changed, 44 insertions(+), 32 deletions(-)

diff --git a/debian/control b/debian/control
index ddc2591..8a3b288 100644
--- a/debian/control
+++ b/debian/control
@@ -154,7 +154,7 @@ Depends: ${misc:Depends},
   python-pyinotify,
   python-apt,
   python-suds,
-  python-soaplib,
+  python-spyne,
   lsb-base (>= 3.0-6)
 Suggests: python-pyudev,
   usbmount
diff --git a/elbepack/commands/updated.py b/elbepack/commands/updated.py
index 6030f52..0eb25b6 100644
--- a/elbepack/commands/updated.py
+++ b/elbepack/commands/updated.py
@@ -26,7 +26,10 @@ import sys
 from optparse import OptionParser
 from wsgiref.simple_server import make_server
 
-from elbepack.updated import UpdateStatus, UpdateService
+from spyne.protocol.soap import Soap11
+from spyne.server.wsgi import WsgiApplication
+
+from elbepack.updated import UpdateStatus, UpdateService, UpdateApplication
 from elbepack.updated_monitors import FileMonitor
 try:
     from elbepack.updated_monitors import USBMonitor
@@ -109,8 +112,16 @@ def run_command (argv):
     for mon in status.monitors:
         mon.start()
 
+    application = UpdateApplication([UpdateService], 'update',
+                                    in_protocol=Soap11(validator='lxml'),
+                                    out_protocol=Soap11())
+    application.status = status
+
+    wsgi_application = WsgiApplication(application)
+
     status.soapserver = make_server (opt.host, int (opt.port),
-                                     UpdateService (status))
+                                     wsgi_application)
+
     try:
         status.soapserver.serve_forever ()
     except:
diff --git a/elbepack/updated.py b/elbepack/updated.py
index aded2ea..6b2a966 100644
--- a/elbepack/updated.py
+++ b/elbepack/updated.py
@@ -29,9 +29,10 @@ import threading
 
 from multiprocessing import Process
 from shutil import copyfile, rmtree, copy
-from soaplib.service import soapmethod
-from soaplib.wsgi_soap import SimpleWSGISoapApp
-from soaplib.serializers.primitive import String
+from spyne import Application
+from spyne.service import ServiceBase
+from spyne.decorator import rpc
+from spyne.model.primitive import String
 from suds.client import Client
 from syslog import syslog
 from zipfile import (ZipFile, BadZipfile)
@@ -101,14 +102,13 @@ class UpdateStatus:
         if self.verbose:
             print msg
 
+class UpdateApplication (Application):
+    def __init__(self, *args, **kargs):
+        Application.__init__(self, *args, **kargs)
+        self.status = UpdateStatus ()
 
-class UpdateService (SimpleWSGISoapApp):
-
-    def __init__ (self, status):
-        SimpleWSGISoapApp.__init__ (self)
-        self.status = status
-
-    @soapmethod (_returns=String)
+class UpdateService (ServiceBase):
+    @rpc (_returns=String)
     def list_snapshots (self):
         # use comma seperated string because array of string triggers a bug in
         # python suds :(
@@ -124,27 +124,27 @@ class UpdateService (SimpleWSGISoapApp):
 
         return snapshots
 
-    @soapmethod (String, _returns=String)
+    @rpc (String, _returns=String)
     def apply_snapshot (self, version):
         if version == "base_version":
             fname = "/etc/elbe_base.xml"
         else:
-            fname = self.status.repo_dir + "/" + version + "/new.xml"
+            fname = self.app.status.repo_dir + "/" + version + "/new.xml"
 
         try:
-            apply_update (fname, self.status)
+            apply_update (fname, self.app.status)
         except Exception, err:
             print Exception, err
-            self.status.set_finished ('error')
+            self.app.status.set_finished ('error')
             return "apply snapshot %s failed" % version
 
-        self.status.set_finished ('OK')
+        self.app.status.set_finished ('OK')
         return "snapshot %s applied" % version
 
-    @soapmethod (String)
+    @rpc (String)
     def register_monitor (self, wsdl_url):
-        self.status.monitor = Client (wsdl_url)
-        self.status.log ("connection established")
+        self.app.status.monitor = Client (wsdl_url)
+        self.app.status.log ("connection established")
 
 class rw_access_file:
     def __init__ (self, filename, status):
diff --git a/test/updated.py b/test/updated.py
index f1ec7fd..1072966 100755
--- a/test/updated.py
+++ b/test/updated.py
@@ -1,8 +1,4 @@
-#!/usr/bin/env python
-
-# there are warnings raised by python-soaplib
-import warnings
-warnings.filterwarnings("ignore", category=FutureWarning)
+#!/usr/bin/env python2
 
 import soaplib
 import sys
@@ -10,14 +6,15 @@ import threading
 import time
 
 from optparse import OptionParser
-from soaplib.service import soapmethod
-from soaplib.wsgi_soap import SimpleWSGISoapApp
-from soaplib.serializers.primitive import String, Array
+from spyne.model.primitive import String
+from spyne import Application, rpc, ServiceBase
+from spyne.protocol.soap import Soap11
+from spyne.server.wsgi import WsgiApplication
 from suds.client import Client
 from wsgiref.simple_server import make_server
 
-class MonitorService (SimpleWSGISoapApp):
-    @soapmethod (String)
+class MonitorService (ServiceBase):
+    @rpc (String)
     def msg (self, m):
         print m
 
@@ -29,7 +26,11 @@ class MonitorThread (threading.Thread):
 
     def run (self):
         print "monitor ready :%s" % (self.port)
-        self.server = make_server ("", int(self.port), MonitorService())
+        application = Application([MonitorService], 'monitor',
+                                  in_protocol=Soap11(validator='lxml'),
+                                  out_protocol=Soap11())
+        wsgi_application = WsgiApplication(application)
+        self.server = make_server ("", int(self.port), wsgi_application)
         self.server.serve_forever ()
 
 def shutdown (monitor):
-- 
2.1.4





More information about the elbe-devel mailing list