Change in python/osmo-python-tests[master]: Move command processing into shared function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Wed Nov 28 11:24:46 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/11974


Change subject: Move command processing into shared function
......................................................................

Move command processing into shared function

Change-Id: I4e40607a9aa5e03a7b3f5b68e4261828209a5813
---
M osmopy/trap_helper.py
M scripts/ctrl2cgi.py
M scripts/soap.py
3 files changed, 19 insertions(+), 15 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/74/11974/1

diff --git a/osmopy/trap_helper.py b/osmopy/trap_helper.py
index 6f4b95d..d07ebd3 100644
--- a/osmopy/trap_helper.py
+++ b/osmopy/trap_helper.py
@@ -24,6 +24,7 @@
 
 import sys, os, datetime, signal, logging, logging.handlers
 from functools import partial
+from osmopy.osmo_ipa import Ctrl
 from osmopy.twisted_ipa import CTRL
 from twisted.internet import defer
 
@@ -56,6 +57,17 @@
     loc = split_type(v)
     return loc[-1]
 
+def comm_proc(comm, f, log):
+    """
+    Command processor: takes function f to run for each command
+    """
+    bsc_id = comm[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
+    log.debug("BSC %s commands: %r" % (bsc_id, comm))
+    for t in comm:
+        (_, m) = Ctrl().cmd(*t.split())
+        f(m)
+    return bsc_id
+
 def make_params(bsc, data):
     """
     Make parameters for request
diff --git a/scripts/ctrl2cgi.py b/scripts/ctrl2cgi.py
index c566a7c..6818b2a 100755
--- a/scripts/ctrl2cgi.py
+++ b/scripts/ctrl2cgi.py
@@ -22,14 +22,14 @@
  */
 """
 
-__version__ = "0.0.3" # bump this on every non-trivial change
+__version__ = "0.0.4" # bump this on every non-trivial change
 
 from twisted.internet import defer, reactor
 from osmopy.twisted_ipa import CTRL, IPAFactory, __version__ as twisted_ipa_version
 from osmopy.osmo_ipa import Ctrl
 from treq import post, collect
 from functools import partial
-from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params
+from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params, comm_proc
 from distutils.version import StrictVersion as V # FIXME: use NormalizedVersion from PEP-386 when available
 import argparse, datetime, signal, sys, os, logging, logging.handlers
 import hashlib
@@ -45,11 +45,7 @@
     Reply handler: process raw CGI server response, function f to run for each command
     """
     decoded = json.loads(resp.decode('utf-8'))
-    bsc_id = decoded.get('commands')[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
-    log.debug("BSC %s commands: %r" % (bsc_id, decoded.get('commands')))
-    for t in decoded.get('commands'): # Process commands format
-        (_, m) = Ctrl().cmd(*t.split())
-        f(m)
+    comm_proc(decoded.get('commands'), f, log)
 
 def gen_hash(params, skey):
     input = ''
diff --git a/scripts/soap.py b/scripts/soap.py
index 75acd89..6bf786c 100755
--- a/scripts/soap.py
+++ b/scripts/soap.py
@@ -22,7 +22,7 @@
  */
 """
 
-__version__ = "0.7.1" # bump this on every non-trivial change
+__version__ = "0.7.2" # bump this on every non-trivial change
 
 from twisted.internet import defer, reactor
 from osmopy.twisted_ipa import CTRL, IPAFactory, __version__ as twisted_ipa_version
@@ -30,7 +30,7 @@
 from treq import post, collect
 from suds.client import Client
 from functools import partial
-from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params
+from osmopy.trap_helper import reloader, debug_init, get_type, get_r, p_h, make_params, comm_proc
 from distutils.version import StrictVersion as V # FIXME: use NormalizedVersion from PEP-386 when available
 import argparse, datetime, signal, sys, os, logging, logging.handlers
 
@@ -40,15 +40,11 @@
 
 def handle_reply(p, f, log, r):
     """
-    Reply handler: takes function p to process raw SOAP server reply r, function f to run for each command and verbosity flag v
+    Reply handler: takes function p to process raw SOAP server reply r, function f to run for each command
     """
     repl = p(r) # result is expected to have both commands[] array and error string (could be None)
-    bsc_id = repl.commands[0].split()[0].split('.')[3] # we expect 1st command to have net.0.bsc.666.bts.2.trx.1 location prefix format
+    bsc_id = comm_proc(repl.commands, f, log)
     log.info("Received SOAP response for BSC %s with %d commands, error status: %s" % (bsc_id, len(repl.commands), repl.error))
-    log.debug("BSC %s commands: %s" % (bsc_id, repl.commands))
-    for t in repl.commands: # Process OpenBscCommands format from .wsdl
-        (_, m) = Ctrl().cmd(*t.split())
-        f(m)
 
 
 class Trap(CTRL):

-- 
To view, visit https://gerrit.osmocom.org/11974
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e40607a9aa5e03a7b3f5b68e4261828209a5813
Gerrit-Change-Number: 11974
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181128/2a3b7587/attachment.htm>


More information about the gerrit-log mailing list