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.orgMax has uploaded this change for review. ( https://gerrit.osmocom.org/12473
Change subject: ctrl2cgi: update shared helper
......................................................................
ctrl2cgi: update shared helper
* split hash generation into simpler functions
* move them into helper file
* split log init into separate function
This facilitates code sharing with new version of ctrl2cgi proxy in
folow-up patches.
Change-Id: Ic5c349349d2c246f934d6701435b1a2d9de77de1
Related: SYS#4399
---
M osmopy/trap_helper.py
M scripts/ctrl2cgi.py
2 files changed, 32 insertions(+), 24 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/73/12473/1
diff --git a/osmopy/trap_helper.py b/osmopy/trap_helper.py
index 3e80c6d..d942cd2 100644
--- a/osmopy/trap_helper.py
+++ b/osmopy/trap_helper.py
@@ -22,7 +22,7 @@
*/
"""
-import sys, os, datetime, signal, logging, logging.handlers
+import hashlib, sys, os, datetime, signal, logging, logging.handlers
from functools import partial
from osmopy.osmo_ipa import Ctrl
@@ -95,16 +95,39 @@
sys.argv.remove(dbg2)
os.execl(path, script, *sys.argv[1:])
+def add_keys(inp, params, l):
+ """
+ Add given list of keys to input string.
+ """
+ for key in l:
+ inp += str(params.get(key))
+ return inp
+
+def gen_hash(params, skey):
+ """
+ Make mandatory parameter for HTTP request.
+ """
+ inp = add_keys('', params, ['time_stamp', 'position_validity', 'admin_status', 'policy_status'])
+ inp += skey
+ inp = add_keys(inp, params, ['bsc_id', 'lat', 'lon', 'position_validity'])
+ m = hashlib.md5()
+ m.update(inp.encode('utf-8'))
+ return m.hexdigest()
+
+def log_init(name, is_debug):
+ """
+ Initialize stdout logging.
+ """
+ log = logging.getLogger(name)
+ log.setLevel(logging.DEBUG if is_debug else logging.INFO)
+ log.addHandler(logging.StreamHandler(sys.stdout))
+ return log
+
def debug_init(name, is_debug):
"""
Initialize signal handlers and logging
"""
- log = logging.getLogger(name)
- if is_debug:
- log.setLevel(logging.DEBUG)
- else:
- log.setLevel(logging.INFO)
- log.addHandler(logging.StreamHandler(sys.stdout))
+ log = log_init(name, is_debug)
reboot = partial(reloader, os.path.abspath(__file__), os.path.basename(__file__), log, '-d', '--debug') # keep in sync with caller's add_argument()
signal.signal(signal.SIGHUP, reboot)
diff --git a/scripts/ctrl2cgi.py b/scripts/ctrl2cgi.py
index bb5c93e..95ff788 100755
--- a/scripts/ctrl2cgi.py
+++ b/scripts/ctrl2cgi.py
@@ -22,7 +22,7 @@
*/
"""
-__version__ = "0.1.0" # bump this on every non-trivial change
+__version__ = "0.1.1" # bump this on every non-trivial change
import argparse, os, logging, logging.handlers, datetime
import hashlib
@@ -32,7 +32,7 @@
from distutils.version import StrictVersion as V
from twisted.internet import defer, reactor
from treq import post, collect
-from osmopy.trap_helper import debug_init, get_type, get_r, p_h, make_params, comm_proc
+from osmopy.trap_helper import debug_init, get_type, get_r, p_h, gen_hash, make_params, comm_proc
from osmopy.twisted_ipa import CTRL, IPAFactory, __version__ as twisted_ipa_version
from osmopy.osmo_ipa import Ctrl
@@ -57,21 +57,6 @@
log_duration(log, bid, ts, ts_http)
comm_proc(decoded.get('commands'), bid, f, log)
-def gen_hash(params, skey):
- """
- Make mandatory parameter for http request
- """
- inp = ''
- for key in ['time_stamp', 'position_validity', 'admin_status', 'policy_status']:
- inp += str(params.get(key))
- inp += skey
- for key in ['bsc_id', 'lat', 'lon', 'position_validity']:
- inp += str(params.get(key))
- m = hashlib.md5()
- m.update(inp.encode('utf-8'))
- res = m.hexdigest()
- return res
-
def make_async_req(ts, dst, par, f_write, f_log, tout):
"""
Assemble deferred request parameters and partially instantiate response handler
--
To view, visit https://gerrit.osmocom.org/12473
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: Ic5c349349d2c246f934d6701435b1a2d9de77de1
Gerrit-Change-Number: 12473
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/20190107/3b49bdf7/attachment.htm>