summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2015-03-09 16:44:22 -0700
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2015-03-09 16:44:22 -0700
commit6e5ceb3d7fcc1127af12bd76133da9d0fd4d7c04 (patch)
treecbdfffa2b2d6ce5b532164dec0b6ac7c6bdb0b47
parentd1cc3d33c53bf5c21cbdfcc7df65bff273b6f5bd (diff)
downloadrvi_core-6e5ceb3d7fcc1127af12bd76133da9d0fd4d7c04.tar.gz
Moved SOTA demo to https://github.com/PDXostc/rvi_sota_demo
-rw-r--r--packaging/sota_demo.manifest5
-rwxr-xr-xpackaging/sota_demo.spec57
-rw-r--r--rvi_sample.config2
-rw-r--r--sota_demo/README.md53
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib-0.1.3-py2.7.egg-info229
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.py232
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.pycbin7854 -> 0 bytes
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/__init__.py6
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/__init__.pycbin514 -> 0 bytes
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/config.py38
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/config.pycbin1539 -> 0 bytes
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/history.py40
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/history.pycbin1798 -> 0 bytes
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/jsonclass.py152
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/jsonclass.pycbin3747 -> 0 bytes
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/jsonrpc.py556
-rw-r--r--sota_demo/mod/lib/python/jsonrpclib/jsonrpc.pycbin21139 -> 0 bytes
-rw-r--r--sota_demo/rvi_json_rpc_server.py36
-rw-r--r--sota_demo/sota.service20
-rw-r--r--sota_demo/sota_device.py452
-rw-r--r--sota_demo/sota_server.py239
21 files changed, 1 insertions, 2116 deletions
diff --git a/packaging/sota_demo.manifest b/packaging/sota_demo.manifest
deleted file mode 100644
index 97e8c31..0000000
--- a/packaging/sota_demo.manifest
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
diff --git a/packaging/sota_demo.spec b/packaging/sota_demo.spec
deleted file mode 100755
index 2f88277..0000000
--- a/packaging/sota_demo.spec
+++ /dev/null
@@ -1,57 +0,0 @@
-Summary: Remote Vehicle Interaction - SOTA Demo packaging
-Name: sota_demo
-Version: 0.3.0
-Release: 1
-Group: App Framework/Application Communication
-License: Mozilla Public License 2.0
-Source: http://content.linuxfoundation.org/auto/downloads/sota_demo/sota_demo-0.3.0.tgz
-
-BuildRequires: make
-BuildRequires: python
-# BuildRequires: glib2-devel
-BuildRequires: rpm
-# BuildRequires: git
-
-%description
-SOTA Demo running on top of RVI
-
-
-%prep
-%setup -c sota_demo-$RPM_PACKAGE_VERSION
-
-%build
-
-%install
-# Install the code.
-
-rm -fr $RPM_BUILD_ROOT/opt/sota_demo-$RPM_PACKAGE_VERSION
-mkdir -p $RPM_BUILD_ROOT/opt/sota_demo-$RPM_PACKAGE_VERSION
-
-cp -r ./sota_demo/mod $RPM_BUILD_ROOT/opt/sota_demo-$RPM_PACKAGE_VERSION
-cp ./sota_demo/rvi_json_rpc_server.py $RPM_BUILD_ROOT/opt/sota_demo-$RPM_PACKAGE_VERSION
-cp ./sota_demo/sota_device.py $RPM_BUILD_ROOT/opt/sota_demo-$RPM_PACKAGE_VERSION
-
-# Setup systemd
-mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system/
-mkdir -p $RPM_BUILD_ROOT/etc/systemd/system/multi-user.target.wants/
-install ./sota_demo/sota.service $RPM_BUILD_ROOT/usr/lib/systemd/system/sota.service
-ln -fsr $RPM_BUILD_ROOT/usr/lib/systemd/system/sota.service $RPM_BUILD_ROOT/etc/systemd/system/multi-user.target.wants/sota.service
-###################
-
-
-
-%post
-/usr/bin/systemctl daemon-reload
-
-%postun
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%files
-%manifest packaging/sota_demo.manifest
-%defattr(-,root,root)
-/usr/lib/systemd/system/sota.service
-/etc/systemd/system/multi-user.target.wants/sota.service
-/opt/sota_demo-0.3.0
-
diff --git a/rvi_sample.config b/rvi_sample.config
index b757249..db3d22d 100644
--- a/rvi_sample.config
+++ b/rvi_sample.config
@@ -233,7 +233,7 @@
[
%% For obscure reasons, the gen_server component
%% here is just called schedule, not schedule_rpc
- { gen_server, schedule },
+ { module, schedule },
{ url, "http://127.0.0.1:8813" },
{ exo_http_opts, [ { port, 8813 } ] }
]
diff --git a/sota_demo/README.md b/sota_demo/README.md
deleted file mode 100644
index 61560e6..0000000
--- a/sota_demo/README.md
+++ /dev/null
@@ -1,53 +0,0 @@
-# SETUP INSTRUCTIONS FOR SOTA DEMO ON TIZEN BOX #
-
-**Please note that there is a bug in Tizen WRT where the
- wrt-installer regularly hangs the Tizen box when invoked to install
- the transmitted package. This will be fixed when we move to
- crosswalk.**
-
-## SETUP
-
-All files are available at rvi@rvi1.nginfotpdx.net:sota_demo/
-
-Flash the tizen image TizenIVI30_APR22_AGL_19SEP2014.raw.gz
-
-### Install RVI
-Once the new Tizen image has booted, install the RVI 0.3.0 rpm:
-
- rpm -i rvi-0.3.0-1.i686.rpm
-
-### Install SOTA demo
-The SOTA demo is provided as an RPM file:
-
- rpm -i sota_demo-0.3.0-1.i686.rpm
-
-### Set Tizen box VIN number
-Edit the RVI config file to install a VIN number.
-
- /opt/rvi-0.3.0/sys.config
-
-Append the VIN number to the end of the node_service_prefix value:
-
-Before:
-
- {node_service_prefix,"jlr.com/vin/"},
-
-After:
-
- {node_service_prefix,"jlr.com/vin/9UYA31581L000000"},
-
-Save the sys.config
-
-### Install the new home screen
-
-Install the updated home screen: intelPoc10.HomeScreen.wgt.20141025_1
-
- wrt-installer -un intelPoc10.HomeScreen
- wrt-installer -i intelPoc10.HomeScreen.wgt.20141027_1
-
-## RUNNING
-
-Reboot the Tizen box to bring up the RVI node and the SOTA demo
-
-
-
diff --git a/sota_demo/mod/lib/python/jsonrpclib-0.1.3-py2.7.egg-info b/sota_demo/mod/lib/python/jsonrpclib-0.1.3-py2.7.egg-info
deleted file mode 100644
index edbd221..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib-0.1.3-py2.7.egg-info
+++ /dev/null
@@ -1,229 +0,0 @@
-Metadata-Version: 1.0
-Name: jsonrpclib
-Version: 0.1.3
-Summary: This project is an implementation of the JSON-RPC v2.0 specification (backwards-compatible) as a client library.
-Home-page: http://github.com/joshmarshall/jsonrpclib/
-Author: Josh Marshall
-Author-email: catchjosh@gmail.com
-License: http://www.apache.org/licenses/LICENSE-2.0
-Description: JSONRPClib
- ==========
- This library is an implementation of the JSON-RPC specification.
- It supports both the original 1.0 specification, as well as the
- new (proposed) 2.0 spec, which includes batch submission, keyword
- arguments, etc.
-
- It is licensed under the Apache License, Version 2.0
- (http://www.apache.org/licenses/LICENSE-2.0.html).
-
- Communication
- -------------
- Feel free to send any questions, comments, or patches to our Google Group
- mailing list (you'll need to join to send a message):
- http://groups.google.com/group/jsonrpclib
-
- Summary
- -------
- This library implements the JSON-RPC 2.0 proposed specification in pure Python.
- It is designed to be as compatible with the syntax of xmlrpclib as possible
- (it extends where possible), so that projects using xmlrpclib could easily be
- modified to use JSON and experiment with the differences.
-
- It is backwards-compatible with the 1.0 specification, and supports all of the
- new proposed features of 2.0, including:
-
- * Batch submission (via MultiCall)
- * Keyword arguments
- * Notifications (both in a batch and 'normal')
- * Class translation using the 'jsonclass' key.
-
- I've added a "SimpleJSONRPCServer", which is intended to emulate the
- "SimpleXMLRPCServer" from the default Python distribution.
-
- Requirements
- ------------
- It supports cjson and simplejson, and looks for the parsers in that order
- (searching first for cjson, then for the "built-in" simplejson as json in 2.6+,
- and then the simplejson external library). One of these must be installed to
- use this library, although if you have a standard distribution of 2.6+, you
- should already have one. Keep in mind that cjson is supposed to be the
- quickest, I believe, so if you are going for full-on optimization you may
- want to pick it up.
-
- Installation
- ------------
- You can install this from PyPI with one of the following commands (sudo
- may be required):
-
- easy_install jsonrpclib
- pip install jsonrpclib
-
- Alternatively, you can download the source from the github repository
- at http://github.com/joshmarshall/jsonrpclib and manually install it
- with the following commands:
-
- git clone git://github.com/joshmarshall/jsonrpclib.git
- cd jsonrpclib
- python setup.py install
-
- Client Usage
- ------------
-
- This is (obviously) taken from a console session.
-
- >>> import jsonrpclib
- >>> server = jsonrpclib.Server('http://localhost:8080')
- >>> server.add(5,6)
- 11
- >>> print jsonrpclib.history.request
- {"jsonrpc": "2.0", "params": [5, 6], "id": "gb3c9g37", "method": "add"}
- >>> print jsonrpclib.history.response
- {'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}
- >>> server.add(x=5, y=10)
- 15
- >>> server._notify.add(5,6)
- # No result returned...
- >>> batch = jsonrpclib.MultiCall(server)
- >>> batch.add(5, 6)
- >>> batch.ping({'key':'value'})
- >>> batch._notify.add(4, 30)
- >>> results = batch()
- >>> for result in results:
- >>> ... print result
- 11
- {'key': 'value'}
- # Note that there are only two responses -- this is according to spec.
-
- If you need 1.0 functionality, there are a bunch of places you can pass that
- in, although the best is just to change the value on
- jsonrpclib.config.version:
-
- >>> import jsonrpclib
- >>> jsonrpclib.config.version
- 2.0
- >>> jsonrpclib.config.version = 1.0
- >>> server = jsonrpclib.Server('http://localhost:8080')
- >>> server.add(7, 10)
- 17
- >>> print jsonrpclib..history.request
- {"params": [7, 10], "id": "thes7tl2", "method": "add"}
- >>> print jsonrpclib.history.response
- {'id': 'thes7tl2', 'result': 17, 'error': None}
- >>>
-
- The equivalent loads and dumps functions also exist, although with minor
- modifications. The dumps arguments are almost identical, but it adds three
- arguments: rpcid for the 'id' key, version to specify the JSON-RPC
- compatibility, and notify if it's a request that you want to be a
- notification.
-
- Additionally, the loads method does not return the params and method like
- xmlrpclib, but instead a.) parses for errors, raising ProtocolErrors, and
- b.) returns the entire structure of the request / response for manual parsing.
-
- SimpleJSONRPCServer
- -------------------
- This is identical in usage (or should be) to the SimpleXMLRPCServer in the default Python install. Some of the differences in features are that it obviously supports notification, batch calls, class translation (if left on), etc. Note: The import line is slightly different from the regular SimpleXMLRPCServer, since the SimpleJSONRPCServer is distributed within the jsonrpclib library.
-
- from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
-
- server = SimpleJSONRPCServer(('localhost', 8080))
- server.register_function(pow)
- server.register_function(lambda x,y: x+y, 'add')
- server.register_function(lambda x: x, 'ping')
- server.serve_forever()
-
- Class Translation
- -----------------
- I've recently added "automatic" class translation support, although it is
- turned off by default. This can be devastatingly slow if improperly used, so
- the following is just a short list of things to keep in mind when using it.
-
- * Keep It (the object) Simple Stupid. (for exceptions, keep reading.)
- * Do not require init params (for exceptions, keep reading)
- * Getter properties without setters could be dangerous (read: not tested)
-
- If any of the above are issues, use the _serialize method. (see usage below)
- The server and client must BOTH have use_jsonclass configuration item on and
- they must both have access to the same libraries used by the objects for
- this to work.
-
- If you have excessively nested arguments, it would be better to turn off the
- translation and manually invoke it on specific objects using
- jsonrpclib.jsonclass.dump / jsonrpclib.jsonclass.load (since the default
- behavior recursively goes through attributes and lists / dicts / tuples).
-
- [test_obj.py]
-
- # This object is /very/ simple, and the system will look through the
- # attributes and serialize what it can.
- class TestObj(object):
- foo = 'bar'
-
- # This object requires __init__ params, so it uses the _serialize method
- # and returns a tuple of init params and attribute values (the init params
- # can be a dict or a list, but the attribute values must be a dict.)
- class TestSerial(object):
- foo = 'bar'
- def __init__(self, *args):
- self.args = args
- def _serialize(self):
- return (self.args, {'foo':self.foo,})
-
- [usage]
-
- import jsonrpclib
- import test_obj
-
- jsonrpclib.config.use_jsonclass = True
-
- testobj1 = test_obj.TestObj()
- testobj2 = test_obj.TestSerial()
- server = jsonrpclib.Server('http://localhost:8080')
- # The 'ping' just returns whatever is sent
- ping1 = server.ping(testobj1)
- ping2 = server.ping(testobj2)
- print jsonrpclib.history.request
- # {"jsonrpc": "2.0", "params": [{"__jsonclass__": ["test_obj.TestSerial", ["foo"]]}], "id": "a0l976iv", "method": "ping"}
- print jsonrpclib.history.result
- # {'jsonrpc': '2.0', 'result': <test_obj.TestSerial object at 0x2744590>, 'id': 'a0l976iv'}
-
- To turn on this behaviour, just set jsonrpclib.config.use_jsonclass to True.
- If you want to use a different method for serialization, just set
- jsonrpclib.config.serialize_method to the method name. Finally, if you are
- using classes that you have defined in the implementation (as in, not a
- separate library), you'll need to add those (on BOTH the server and the
- client) using the jsonrpclib.config.classes.add() method.
- (Examples forthcoming.)
-
- Feedback on this "feature" is very, VERY much appreciated.
-
- Why JSON-RPC?
- -------------
- In my opinion, there are several reasons to choose JSON over XML for RPC:
-
- * Much simpler to read (I suppose this is opinion, but I know I'm right. :)
- * Size / Bandwidth - Main reason, a JSON object representation is just much smaller.
- * Parsing - JSON should be much quicker to parse than XML.
- * Easy class passing with jsonclass (when enabled)
-
- In the interest of being fair, there are also a few reasons to choose XML
- over JSON:
-
- * Your server doesn't do JSON (rather obvious)
- * Wider XML-RPC support across APIs (can we change this? :))
- * Libraries are more established, i.e. more stable (Let's change this too.)
-
- TESTS
- -----
- I've dropped almost-verbatim tests from the JSON-RPC spec 2.0 page.
- You can run it with:
-
- python tests.py
-
- TODO
- ----
- * Use HTTP error codes on SimpleJSONRPCServer
- * Test, test, test and optimize
-
-Platform: UNKNOWN
diff --git a/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.py b/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.py
deleted file mode 100644
index c746f0c..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.py
+++ /dev/null
@@ -1,232 +0,0 @@
-import jsonrpclib
-from jsonrpclib import Fault
-from jsonrpclib.jsonrpc import USE_UNIX_SOCKETS
-import SimpleXMLRPCServer
-import SocketServer
-import socket
-import logging
-import os
-import types
-import traceback
-import sys
-try:
- import fcntl
-except ImportError:
- # For Windows
- fcntl = None
-
-def get_version(request):
- # must be a dict
- if 'jsonrpc' in request.keys():
- return 2.0
- if 'id' in request.keys():
- return 1.0
- return None
-
-def validate_request(request):
- if type(request) is not types.DictType:
- fault = Fault(
- -32600, 'Request must be {}, not %s.' % type(request)
- )
- return fault
- rpcid = request.get('id', None)
- version = get_version(request)
- if not version:
- fault = Fault(-32600, 'Request %s invalid.' % request, rpcid=rpcid)
- return fault
- request.setdefault('params', [])
- method = request.get('method', None)
- params = request.get('params')
- param_types = (types.ListType, types.DictType, types.TupleType)
- if not method or type(method) not in types.StringTypes or \
- type(params) not in param_types:
- fault = Fault(
- -32600, 'Invalid request parameters or method.', rpcid=rpcid
- )
- return fault
- return True
-
-class SimpleJSONRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
-
- def __init__(self, encoding=None):
- SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self,
- allow_none=True,
- encoding=encoding)
-
- def _marshaled_dispatch(self, data, dispatch_method = None):
- response = None
- try:
- request = jsonrpclib.loads(data)
- except Exception, e:
- fault = Fault(-32700, 'Request %s invalid. (%s)' % (data, e))
- response = fault.response()
- return response
- if not request:
- fault = Fault(-32600, 'Request invalid -- no request data.')
- return fault.response()
- if type(request) is types.ListType:
- # This SHOULD be a batch, by spec
- responses = []
- for req_entry in request:
- result = validate_request(req_entry)
- if type(result) is Fault:
- responses.append(result.response())
- continue
- resp_entry = self._marshaled_single_dispatch(req_entry)
- if resp_entry is not None:
- responses.append(resp_entry)
- if len(responses) > 0:
- response = '[%s]' % ','.join(responses)
- else:
- response = ''
- else:
- result = validate_request(request)
- if type(result) is Fault:
- return result.response()
- response = self._marshaled_single_dispatch(request)
- return response
-
- def _marshaled_single_dispatch(self, request):
- # TODO - Use the multiprocessing and skip the response if
- # it is a notification
- # Put in support for custom dispatcher here
- # (See SimpleXMLRPCServer._marshaled_dispatch)
- method = request.get('method')
- params = request.get('params')
- try:
- response = self._dispatch(method, params)
- except:
- exc_type, exc_value, exc_tb = sys.exc_info()
- fault = Fault(-32603, '%s:%s' % (exc_type, exc_value))
- return fault.response()
- if 'id' not in request.keys() or request['id'] == None:
- # It's a notification
- return None
- try:
- response = jsonrpclib.dumps(response,
- methodresponse=True,
- rpcid=request['id']
- )
- return response
- except:
- exc_type, exc_value, exc_tb = sys.exc_info()
- fault = Fault(-32603, '%s:%s' % (exc_type, exc_value))
- return fault.response()
-
- def _dispatch(self, method, params):
- func = None
- try:
- func = self.funcs[method]
- except KeyError:
- if self.instance is not None:
- if hasattr(self.instance, '_dispatch'):
- return self.instance._dispatch(method, params)
- else:
- try:
- func = SimpleXMLRPCServer.resolve_dotted_attribute(
- self.instance,
- method,
- True
- )
- except AttributeError:
- pass
- if func is not None:
- try:
- if type(params) is types.ListType:
- response = func(*params)
- else:
- response = func(**params)
- return response
- except TypeError:
- return Fault(-32602, 'Invalid parameters.')
- except:
- err_lines = traceback.format_exc().splitlines()
- trace_string = '%s | %s' % (err_lines[-3], err_lines[-1])
- fault = jsonrpclib.Fault(-32603, 'Server error: %s' %
- trace_string)
- return fault
- else:
- return Fault(-32601, 'Method %s not supported.' % method)
-
-class SimpleJSONRPCRequestHandler(
- SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
-
- def do_POST(self):
- if not self.is_rpc_path_valid():
- self.report_404()
- return
- try:
- max_chunk_size = 10*1024*1024
- size_remaining = int(self.headers["content-length"])
- L = []
- while size_remaining:
- chunk_size = min(size_remaining, max_chunk_size)
- L.append(self.rfile.read(chunk_size))
- size_remaining -= len(L[-1])
- data = ''.join(L)
- response = self.server._marshaled_dispatch(data)
- self.send_response(200)
- except Exception, e:
- self.send_response(500)
- err_lines = traceback.format_exc().splitlines()
- trace_string = '%s | %s' % (err_lines[-3], err_lines[-1])
- fault = jsonrpclib.Fault(-32603, 'Server error: %s' % trace_string)
- response = fault.response()
- if response == None:
- response = ''
- self.send_header("Content-type", "application/json-rpc")
- self.send_header("Content-length", str(len(response)))
- self.end_headers()
- self.wfile.write(response)
- self.wfile.flush()
- try:
- self.connection.shutdown(1)
- except:
- return
-
-class SimpleJSONRPCServer(SocketServer.TCPServer, SimpleJSONRPCDispatcher):
-
- allow_reuse_address = True
-
- def __init__(self, addr, requestHandler=SimpleJSONRPCRequestHandler,
- logRequests=True, encoding=None, bind_and_activate=True,
- address_family=socket.AF_INET):
- self.logRequests = logRequests
- SimpleJSONRPCDispatcher.__init__(self, encoding)
- # TCPServer.__init__ has an extra parameter on 2.6+, so
- # check Python version and decide on how to call it
- vi = sys.version_info
- self.address_family = address_family
- if USE_UNIX_SOCKETS and address_family == socket.AF_UNIX:
- # Unix sockets can't be bound if they already exist in the
- # filesystem. The convention of e.g. X11 is to unlink
- # before binding again.
- if os.path.exists(addr):
- try:
- os.unlink(addr)
- except OSError:
- logging.warning("Could not unlink socket %s", addr)
- # if python 2.5 and lower
- if vi[0] < 3 and vi[1] < 6:
- SocketServer.TCPServer.__init__(self, addr, requestHandler)
- else:
- SocketServer.TCPServer.__init__(self, addr, requestHandler,
- bind_and_activate)
- if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'):
- flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
- flags |= fcntl.FD_CLOEXEC
- fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags)
-
-class CGIJSONRPCRequestHandler(SimpleJSONRPCDispatcher):
-
- def __init__(self, encoding=None):
- SimpleJSONRPCDispatcher.__init__(self, encoding)
-
- def handle_jsonrpc(self, request_text):
- response = self._marshaled_dispatch(request_text)
- print 'Content-Type: application/json-rpc'
- print 'Content-Length: %d' % len(response)
- print
- sys.stdout.write(response)
-
- handle_xmlrpc = handle_jsonrpc
diff --git a/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.pyc b/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.pyc
deleted file mode 100644
index 60ea0a7..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/SimpleJSONRPCServer.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/mod/lib/python/jsonrpclib/__init__.py b/sota_demo/mod/lib/python/jsonrpclib/__init__.py
deleted file mode 100644
index 6e884b8..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/__init__.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from jsonrpclib.config import Config
-config = Config.instance()
-from jsonrpclib.history import History
-history = History.instance()
-from jsonrpclib.jsonrpc import Server, MultiCall, Fault
-from jsonrpclib.jsonrpc import ProtocolError, loads, dumps
diff --git a/sota_demo/mod/lib/python/jsonrpclib/__init__.pyc b/sota_demo/mod/lib/python/jsonrpclib/__init__.pyc
deleted file mode 100644
index 37e793b..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/__init__.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/mod/lib/python/jsonrpclib/config.py b/sota_demo/mod/lib/python/jsonrpclib/config.py
deleted file mode 100644
index 4d28f1b..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/config.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import sys
-
-class LocalClasses(dict):
- def add(self, cls):
- self[cls.__name__] = cls
-
-class Config(object):
- """
- This is pretty much used exclusively for the 'jsonclass'
- functionality... set use_jsonclass to False to turn it off.
- You can change serialize_method and ignore_attribute, or use
- the local_classes.add(class) to include "local" classes.
- """
- use_jsonclass = True
- # Change to False to keep __jsonclass__ entries raw.
- serialize_method = '_serialize'
- # The serialize_method should be a string that references the
- # method on a custom class object which is responsible for
- # returning a tuple of the constructor arguments and a dict of
- # attributes.
- ignore_attribute = '_ignore'
- # The ignore attribute should be a string that references the
- # attribute on a custom class object which holds strings and / or
- # references of the attributes the class translator should ignore.
- classes = LocalClasses()
- # The list of classes to use for jsonclass translation.
- version = 2.0
- # Version of the JSON-RPC spec to support
- user_agent = 'jsonrpclib/0.1 (Python %s)' % \
- '.'.join([str(ver) for ver in sys.version_info[0:3]])
- # User agent to use for calls.
- _instance = None
-
- @classmethod
- def instance(cls):
- if not cls._instance:
- cls._instance = cls()
- return cls._instance
diff --git a/sota_demo/mod/lib/python/jsonrpclib/config.pyc b/sota_demo/mod/lib/python/jsonrpclib/config.pyc
deleted file mode 100644
index 779d5dc..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/config.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/mod/lib/python/jsonrpclib/history.py b/sota_demo/mod/lib/python/jsonrpclib/history.py
deleted file mode 100644
index d11863d..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/history.py
+++ /dev/null
@@ -1,40 +0,0 @@
-class History(object):
- """
- This holds all the response and request objects for a
- session. A server using this should call "clear" after
- each request cycle in order to keep it from clogging
- memory.
- """
- requests = []
- responses = []
- _instance = None
-
- @classmethod
- def instance(cls):
- if not cls._instance:
- cls._instance = cls()
- return cls._instance
-
- def add_response(self, response_obj):
- self.responses.append(response_obj)
-
- def add_request(self, request_obj):
- self.requests.append(request_obj)
-
- @property
- def request(self):
- if len(self.requests) == 0:
- return None
- else:
- return self.requests[-1]
-
- @property
- def response(self):
- if len(self.responses) == 0:
- return None
- else:
- return self.responses[-1]
-
- def clear(self):
- del self.requests[:]
- del self.responses[:]
diff --git a/sota_demo/mod/lib/python/jsonrpclib/history.pyc b/sota_demo/mod/lib/python/jsonrpclib/history.pyc
deleted file mode 100644
index 55ce9f8..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/history.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/mod/lib/python/jsonrpclib/jsonclass.py b/sota_demo/mod/lib/python/jsonrpclib/jsonclass.py
deleted file mode 100644
index 1d86d5f..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/jsonclass.py
+++ /dev/null
@@ -1,152 +0,0 @@
-import types
-import inspect
-import re
-import traceback
-
-from jsonrpclib import config
-
-iter_types = [
- types.DictType,
- types.ListType,
- types.TupleType
-]
-
-string_types = [
- types.StringType,
- types.UnicodeType
-]
-
-numeric_types = [
- types.IntType,
- types.LongType,
- types.FloatType
-]
-
-value_types = [
- types.BooleanType,
- types.NoneType
-]
-
-supported_types = iter_types+string_types+numeric_types+value_types
-invalid_module_chars = r'[^a-zA-Z0-9\_\.]'
-
-class TranslationError(Exception):
- pass
-
-def dump(obj, serialize_method=None, ignore_attribute=None, ignore=[]):
- if not serialize_method:
- serialize_method = config.serialize_method
- if not ignore_attribute:
- ignore_attribute = config.ignore_attribute
- obj_type = type(obj)
- # Parse / return default "types"...
- if obj_type in numeric_types+string_types+value_types:
- return obj
- if obj_type in iter_types:
- if obj_type in (types.ListType, types.TupleType):
- new_obj = []
- for item in obj:
- new_obj.append(dump(item, serialize_method,
- ignore_attribute, ignore))
- if obj_type is types.TupleType:
- new_obj = tuple(new_obj)
- return new_obj
- # It's a dict...
- else:
- new_obj = {}
- for key, value in obj.iteritems():
- new_obj[key] = dump(value, serialize_method,
- ignore_attribute, ignore)
- return new_obj
- # It's not a standard type, so it needs __jsonclass__
- module_name = inspect.getmodule(obj).__name__
- class_name = obj.__class__.__name__
- json_class = class_name
- if module_name not in ['', '__main__']:
- json_class = '%s.%s' % (module_name, json_class)
- return_obj = {"__jsonclass__":[json_class,]}
- # If a serialization method is defined..
- if serialize_method in dir(obj):
- # Params can be a dict (keyword) or list (positional)
- # Attrs MUST be a dict.
- serialize = getattr(obj, serialize_method)
- params, attrs = serialize()
- return_obj['__jsonclass__'].append(params)
- return_obj.update(attrs)
- return return_obj
- # Otherwise, try to figure it out
- # Obviously, we can't assume to know anything about the
- # parameters passed to __init__
- return_obj['__jsonclass__'].append([])
- attrs = {}
- ignore_list = getattr(obj, ignore_attribute, [])+ignore
- for attr_name, attr_value in obj.__dict__.iteritems():
- if type(attr_value) in supported_types and \
- attr_name not in ignore_list and \
- attr_value not in ignore_list:
- attrs[attr_name] = dump(attr_value, serialize_method,
- ignore_attribute, ignore)
- return_obj.update(attrs)
- return return_obj
-
-def load(obj):
- if type(obj) in string_types+numeric_types+value_types:
- return obj
- if type(obj) is types.ListType:
- return_list = []
- for entry in obj:
- return_list.append(load(entry))
- return return_list
- # Othewise, it's a dict type
- if '__jsonclass__' not in obj.keys():
- return_dict = {}
- for key, value in obj.iteritems():
- new_value = load(value)
- return_dict[key] = new_value
- return return_dict
- # It's a dict, and it's a __jsonclass__
- orig_module_name = obj['__jsonclass__'][0]
- params = obj['__jsonclass__'][1]
- if orig_module_name == '':
- raise TranslationError('Module name empty.')
- json_module_clean = re.sub(invalid_module_chars, '', orig_module_name)
- if json_module_clean != orig_module_name:
- raise TranslationError('Module name %s has invalid characters.' %
- orig_module_name)
- json_module_parts = json_module_clean.split('.')
- json_class = None
- if len(json_module_parts) == 1:
- # Local class name -- probably means it won't work
- if json_module_parts[0] not in config.classes.keys():
- raise TranslationError('Unknown class or module %s.' %
- json_module_parts[0])
- json_class = config.classes[json_module_parts[0]]
- else:
- json_class_name = json_module_parts.pop()
- json_module_tree = '.'.join(json_module_parts)
- try:
- temp_module = __import__(json_module_tree)
- except ImportError:
- raise TranslationError('Could not import %s from module %s.' %
- (json_class_name, json_module_tree))
-
- # The returned class is the top-level module, not the one we really
- # want. (E.g., if we import a.b.c, we now have a.) Walk through other
- # path components to get to b and c.
- for i in json_module_parts[1:]:
- temp_module = getattr(temp_module, i)
-
- json_class = getattr(temp_module, json_class_name)
- # Creating the object...
- new_obj = None
- if type(params) is types.ListType:
- new_obj = json_class(*params)
- elif type(params) is types.DictType:
- new_obj = json_class(**params)
- else:
- raise TranslationError('Constructor args must be a dict or list.')
- for key, value in obj.iteritems():
- if key == '__jsonclass__':
- continue
- setattr(new_obj, key, value)
- return new_obj
diff --git a/sota_demo/mod/lib/python/jsonrpclib/jsonclass.pyc b/sota_demo/mod/lib/python/jsonrpclib/jsonclass.pyc
deleted file mode 100644
index 28baf5d..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/jsonclass.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.py b/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.py
deleted file mode 100644
index e11939a..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.py
+++ /dev/null
@@ -1,556 +0,0 @@
-"""
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-============================
-JSONRPC Library (jsonrpclib)
-============================
-
-This library is a JSON-RPC v.2 (proposed) implementation which
-follows the xmlrpclib API for portability between clients. It
-uses the same Server / ServerProxy, loads, dumps, etc. syntax,
-while providing features not present in XML-RPC like:
-
-* Keyword arguments
-* Notifications
-* Versioning
-* Batches and batch notifications
-
-Eventually, I'll add a SimpleXMLRPCServer compatible library,
-and other things to tie the thing off nicely. :)
-
-For a quick-start, just open a console and type the following,
-replacing the server address, method, and parameters
-appropriately.
->>> import jsonrpclib
->>> server = jsonrpclib.Server('http://localhost:8181')
->>> server.add(5, 6)
-11
->>> server._notify.add(5, 6)
->>> batch = jsonrpclib.MultiCall(server)
->>> batch.add(3, 50)
->>> batch.add(2, 3)
->>> batch._notify.add(3, 5)
->>> batch()
-[53, 5]
-
-See http://code.google.com/p/jsonrpclib/ for more info.
-"""
-
-import types
-import sys
-from xmlrpclib import Transport as XMLTransport
-from xmlrpclib import SafeTransport as XMLSafeTransport
-from xmlrpclib import ServerProxy as XMLServerProxy
-from xmlrpclib import _Method as XML_Method
-import time
-import string
-import random
-
-# Library includes
-import jsonrpclib
-from jsonrpclib import config
-from jsonrpclib import history
-
-# JSON library importing
-cjson = None
-json = None
-try:
- import cjson
-except ImportError:
- try:
- import json
- except ImportError:
- try:
- import simplejson as json
- except ImportError:
- raise ImportError(
- 'You must have the cjson, json, or simplejson ' +
- 'module(s) available.'
- )
-
-IDCHARS = string.ascii_lowercase+string.digits
-
-class UnixSocketMissing(Exception):
- """
- Just a properly named Exception if Unix Sockets usage is
- attempted on a platform that doesn't support them (Windows)
- """
- pass
-
-#JSON Abstractions
-
-def jdumps(obj, encoding='utf-8'):
- # Do 'serialize' test at some point for other classes
- global cjson
- if cjson:
- return cjson.encode(obj)
- else:
- return json.dumps(obj, encoding=encoding)
-
-def jloads(json_string):
- global cjson
- if cjson:
- return cjson.decode(json_string)
- else:
- return json.loads(json_string)
-
-
-# XMLRPClib re-implementations
-
-class ProtocolError(Exception):
- pass
-
-class TransportMixIn(object):
- """ Just extends the XMLRPC transport where necessary. """
- user_agent = config.user_agent
- # for Python 2.7 support
- _connection = None
-
- def send_content(self, connection, request_body):
- connection.putheader("Content-Type", "application/json-rpc")
- connection.putheader("Content-Length", str(len(request_body)))
- connection.endheaders()
- if request_body:
- connection.send(request_body)
-
- def getparser(self):
- target = JSONTarget()
- return JSONParser(target), target
-
-class JSONParser(object):
- def __init__(self, target):
- self.target = target
-
- def feed(self, data):
- self.target.feed(data)
-
- def close(self):
- pass
-
-class JSONTarget(object):
- def __init__(self):
- self.data = []
-
- def feed(self, data):
- self.data.append(data)
-
- def close(self):
- return ''.join(self.data)
-
-class Transport(TransportMixIn, XMLTransport):
- pass
-
-class SafeTransport(TransportMixIn, XMLSafeTransport):
- pass
-from httplib import HTTP, HTTPConnection
-from socket import socket
-
-USE_UNIX_SOCKETS = False
-
-try:
- from socket import AF_UNIX, SOCK_STREAM
- USE_UNIX_SOCKETS = True
-except ImportError:
- pass
-
-if (USE_UNIX_SOCKETS):
-
- class UnixHTTPConnection(HTTPConnection):
- def connect(self):
- self.sock = socket(AF_UNIX, SOCK_STREAM)
- self.sock.connect(self.host)
-
- class UnixHTTP(HTTP):
- _connection_class = UnixHTTPConnection
-
- class UnixTransport(TransportMixIn, XMLTransport):
- def make_connection(self, host):
- import httplib
- host, extra_headers, x509 = self.get_host_info(host)
- return UnixHTTP(host)
-
-
-class ServerProxy(XMLServerProxy):
- """
- Unfortunately, much more of this class has to be copied since
- so much of it does the serialization.
- """
-
- def __init__(self, uri, transport=None, encoding=None,
- verbose=0, version=None):
- import urllib
- if not version:
- version = config.version
- self.__version = version
- schema, uri = urllib.splittype(uri)
- if schema not in ('http', 'https', 'unix'):
- raise IOError('Unsupported JSON-RPC protocol.')
- if schema == 'unix':
- if not USE_UNIX_SOCKETS:
- # Don't like the "generic" Exception...
- raise UnixSocketMissing("Unix sockets not available.")
- self.__host = uri
- self.__handler = '/'
- else:
- self.__host, self.__handler = urllib.splithost(uri)
- if not self.__handler:
- # Not sure if this is in the JSON spec?
- #self.__handler = '/'
- self.__handler == '/'
- if transport is None:
- if schema == 'unix':
- transport = UnixTransport()
- elif schema == 'https':
- transport = SafeTransport()
- else:
- transport = Transport()
- self.__transport = transport
- self.__encoding = encoding
- self.__verbose = verbose
-
- def _request(self, methodname, params, rpcid=None):
- request = dumps(params, methodname, encoding=self.__encoding,
- rpcid=rpcid, version=self.__version)
- response = self._run_request(request)
- check_for_errors(response)
- return response['result']
-
- def _request_notify(self, methodname, params, rpcid=None):
- request = dumps(params, methodname, encoding=self.__encoding,
- rpcid=rpcid, version=self.__version, notify=True)
- response = self._run_request(request, notify=True)
- check_for_errors(response)
- return
-
- def _run_request(self, request, notify=None):
- history.add_request(request)
-
- response = self.__transport.request(
- self.__host,
- self.__handler,
- request,
- verbose=self.__verbose
- )
-
- # Here, the XMLRPC library translates a single list
- # response to the single value -- should we do the
- # same, and require a tuple / list to be passed to
- # the response object, or expect the Server to be
- # outputting the response appropriately?
-
- history.add_response(response)
- if not response:
- return None
- return_obj = loads(response)
- return return_obj
-
- def __getattr__(self, name):
- # Same as original, just with new _Method reference
- return _Method(self._request, name)
-
- @property
- def _notify(self):
- # Just like __getattr__, but with notify namespace.
- return _Notify(self._request_notify)
-
-
-class _Method(XML_Method):
-
- def __call__(self, *args, **kwargs):
- if len(args) > 0 and len(kwargs) > 0:
- raise ProtocolError('Cannot use both positional ' +
- 'and keyword arguments (according to JSON-RPC spec.)')
- if len(args) > 0:
- return self.__send(self.__name, args)
- else:
- return self.__send(self.__name, kwargs)
-
- def __getattr__(self, name):
- self.__name = '%s.%s' % (self.__name, name)
- return self
- # The old method returned a new instance, but this seemed wasteful.
- # The only thing that changes is the name.
- #return _Method(self.__send, "%s.%s" % (self.__name, name))
-
-class _Notify(object):
- def __init__(self, request):
- self._request = request
-
- def __getattr__(self, name):
- return _Method(self._request, name)
-
-# Batch implementation
-
-class MultiCallMethod(object):
-
- def __init__(self, method, notify=False):
- self.method = method
- self.params = []
- self.notify = notify
-
- def __call__(self, *args, **kwargs):
- if len(kwargs) > 0 and len(args) > 0:
- raise ProtocolError('JSON-RPC does not support both ' +
- 'positional and keyword arguments.')
- if len(kwargs) > 0:
- self.params = kwargs
- else:
- self.params = args
-
- def request(self, encoding=None, rpcid=None):
- return dumps(self.params, self.method, version=2.0,
- encoding=encoding, rpcid=rpcid, notify=self.notify)
-
- def __repr__(self):
- return '%s' % self.request()
-
- def __getattr__(self, method):
- new_method = '%s.%s' % (self.method, method)
- self.method = new_method
- return self
-
-class MultiCallNotify(object):
-
- def __init__(self, multicall):
- self.multicall = multicall
-
- def __getattr__(self, name):
- new_job = MultiCallMethod(name, notify=True)
- self.multicall._job_list.append(new_job)
- return new_job
-
-class MultiCallIterator(object):
-
- def __init__(self, results):
- self.results = results
-
- def __iter__(self):
- for i in range(0, len(self.results)):
- yield self[i]
- raise StopIteration
-
- def __getitem__(self, i):
- item = self.results[i]
- check_for_errors(item)
- return item['result']
-
- def __len__(self):
- return len(self.results)
-
-class MultiCall(object):
-
- def __init__(self, server):
- self._server = server
- self._job_list = []
-
- def _request(self):
- if len(self._job_list) < 1:
- # Should we alert? This /is/ pretty obvious.
- return
- request_body = '[ %s ]' % ','.join([job.request() for
- job in self._job_list])
- responses = self._server._run_request(request_body)
- del self._job_list[:]
- if not responses:
- responses = []
- return MultiCallIterator(responses)
-
- @property
- def _notify(self):
- return MultiCallNotify(self)
-
- def __getattr__(self, name):
- new_job = MultiCallMethod(name)
- self._job_list.append(new_job)
- return new_job
-
- __call__ = _request
-
-# These lines conform to xmlrpclib's "compatibility" line.
-# Not really sure if we should include these, but oh well.
-Server = ServerProxy
-
-class Fault(object):
- # JSON-RPC error class
- def __init__(self, code=-32000, message='Server error', rpcid=None):
- self.faultCode = code
- self.faultString = message
- self.rpcid = rpcid
-
- def error(self):
- return {'code':self.faultCode, 'message':self.faultString}
-
- def response(self, rpcid=None, version=None):
- if not version:
- version = config.version
- if rpcid:
- self.rpcid = rpcid
- return dumps(
- self, methodresponse=True, rpcid=self.rpcid, version=version
- )
-
- def __repr__(self):
- return '<Fault %s: %s>' % (self.faultCode, self.faultString)
-
-def random_id(length=8):
- return_id = ''
- for i in range(length):
- return_id += random.choice(IDCHARS)
- return return_id
-
-class Payload(dict):
- def __init__(self, rpcid=None, version=None):
- if not version:
- version = config.version
- self.id = rpcid
- self.version = float(version)
-
- def request(self, method, params=[]):
- if type(method) not in types.StringTypes:
- raise ValueError('Method name must be a string.')
- if not self.id:
- self.id = random_id()
- request = { 'id':self.id, 'method':method }
- if params:
- request['params'] = params
- if self.version >= 2:
- request['jsonrpc'] = str(self.version)
- return request
-
- def notify(self, method, params=[]):
- request = self.request(method, params)
- if self.version >= 2:
- del request['id']
- else:
- request['id'] = None
- return request
-
- def response(self, result=None):
- response = {'result':result, 'id':self.id}
- if self.version >= 2:
- response['jsonrpc'] = str(self.version)
- else:
- response['error'] = None
- return response
-
- def error(self, code=-32000, message='Server error.'):
- error = self.response()
- if self.version >= 2:
- del error['result']
- else:
- error['result'] = None
- error['error'] = {'code':code, 'message':message}
- return error
-
-def dumps(params=[], methodname=None, methodresponse=None,
- encoding=None, rpcid=None, version=None, notify=None):
- """
- This differs from the Python implementation in that it implements
- the rpcid argument since the 2.0 spec requires it for responses.
- """
- if not version:
- version = config.version
- valid_params = (types.TupleType, types.ListType, types.DictType)
- if methodname in types.StringTypes and \
- type(params) not in valid_params and \
- not isinstance(params, Fault):
- """
- If a method, and params are not in a listish or a Fault,
- error out.
- """
- raise TypeError('Params must be a dict, list, tuple or Fault ' +
- 'instance.')
- # Begin parsing object
- payload = Payload(rpcid=rpcid, version=version)
- if not encoding:
- encoding = 'utf-8'
- if type(params) is Fault:
- response = payload.error(params.faultCode, params.faultString)
- return jdumps(response, encoding=encoding)
- if type(methodname) not in types.StringTypes and methodresponse != True:
- raise ValueError('Method name must be a string, or methodresponse '+
- 'must be set to True.')
- if config.use_jsonclass == True:
- from jsonrpclib import jsonclass
- params = jsonclass.dump(params)
- if methodresponse is True:
- if rpcid is None:
- raise ValueError('A method response must have an rpcid.')
- response = payload.response(params)
- return jdumps(response, encoding=encoding)
- request = None
- if notify == True:
- request = payload.notify(methodname, params)
- else:
- request = payload.request(methodname, params)
- return jdumps(request, encoding=encoding)
-
-def loads(data):
- """
- This differs from the Python implementation, in that it returns
- the request structure in Dict format instead of the method, params.
- It will return a list in the case of a batch request / response.
- """
- if data == '':
- # notification
- return None
- result = jloads(data)
- # if the above raises an error, the implementing server code
- # should return something like the following:
- # { 'jsonrpc':'2.0', 'error': fault.error(), id: None }
- if config.use_jsonclass == True:
- from jsonrpclib import jsonclass
- result = jsonclass.load(result)
- return result
-
-def check_for_errors(result):
- if not result:
- # Notification
- return result
- if type(result) is not types.DictType:
- raise TypeError('Response is not a dict.')
- if 'jsonrpc' in result.keys() and float(result['jsonrpc']) > 2.0:
- raise NotImplementedError('JSON-RPC version not yet supported.')
- if 'result' not in result.keys() and 'error' not in result.keys():
- raise ValueError('Response does not have a result or error key.')
- if 'error' in result.keys() and result['error'] != None:
- code = result['error']['code']
- message = result['error']['message']
- raise ProtocolError((code, message))
- return result
-
-def isbatch(result):
- if type(result) not in (types.ListType, types.TupleType):
- return False
- if len(result) < 1:
- return False
- if type(result[0]) is not types.DictType:
- return False
- if 'jsonrpc' not in result[0].keys():
- return False
- try:
- version = float(result[0]['jsonrpc'])
- except ValueError:
- raise ProtocolError('"jsonrpc" key must be a float(able) value.')
- if version < 2:
- return False
- return True
-
-def isnotification(request):
- if 'id' not in request.keys():
- # 2.0 notification
- return True
- if request['id'] == None:
- # 1.0 notification
- return True
- return False
diff --git a/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.pyc b/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.pyc
deleted file mode 100644
index 3fc31da..0000000
--- a/sota_demo/mod/lib/python/jsonrpclib/jsonrpc.pyc
+++ /dev/null
Binary files differ
diff --git a/sota_demo/rvi_json_rpc_server.py b/sota_demo/rvi_json_rpc_server.py
deleted file mode 100644
index 6502415..0000000
--- a/sota_demo/rvi_json_rpc_server.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# Copyright (C) 2014, Jaguar Land Rover
-#
-# This program is licensed under the terms and conditions of the
-# Mozilla Public License, version 2.0. The full text of the
-# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
-#
-from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
-import jsonrpclib
-
-class RVIJSONRPCServer(SimpleJSONRPCServer):
- # Check if method is 'message', if so dispatch on
- # name 'service_name' instead.
- def _dispatch(self, method, params):
- if method == 'message':
- # print "Will dispatch message to: " + params['service_name']
- dict_param = {}
- # Extract the 'parameters' element from the top level JSON-RPC
- # 'param'.
- # Convert 'parameters' from [{'vin': 1234}, {hello: 'world'}] to
- # a regular dictionary: {'vin': 1234, hello: 'world'}
-
- # print "Parameters:", params['parameters']
- msg_params = params['parameters']
- for i in range(0, len(msg_params)):
- for j in range(0, len(msg_params[i].keys())):
- # print "params", msg_params[i].keys()[j], "=", msg_params[i].values()[j]
- dict_param[msg_params[i].keys()[j]] = msg_params[i].values()[j]
-
- # print "Parameter disctionary: ", dict_param
- # print
- # Ship the processed dispatch info upward.
- return SimpleJSONRPCServer._dispatch(self, params['service_name'], dict_param)
-
-
- return SimpleJSONRPCServer._dispatch(self,method, params)
diff --git a/sota_demo/sota.service b/sota_demo/sota.service
deleted file mode 100644
index 002b62f..0000000
--- a/sota_demo/sota.service
+++ /dev/null
@@ -1,20 +0,0 @@
-# systemd(8) setup usde by Tizen and others.
-[Unit]
-Description=Software Over The Air Service
-Wants=network-online.target rvi.service
-
-[Service]
-Environment="HOME=/opt/sota_demo-0.3.0"
-Environment="PYTHONPATH=/opt/sota_demo-0.3.0/mod/lib/python"
-WorkingDirectory=/opt/sota_demo-0.3.0
-Type=simple
-StandardOutput=journal
-StandardError=journal
-ExecStart=/bin/sh -c "sleep 10;/usr/bin/python sota_device.py http://localhost:8811"
-#ExecStart=/usr/bin/python sota_device.py http://localhost:8811
-#ExecStop=/bin/sh /opt/rvi-0.3.0/bin/rvi stop
-#ExecStopPost=/opt/rvi-0.3.0/erts-5.10.4/bin/epmd -kill
-GuessMainPID=yes
-
-[Install]
-WantedBy=graphical.target multi-user.target
diff --git a/sota_demo/sota_device.py b/sota_demo/sota_device.py
deleted file mode 100644
index 5a87c4c..0000000
--- a/sota_demo/sota_device.py
+++ /dev/null
@@ -1,452 +0,0 @@
-#!/usr/bin/python
-
-#
-# Copyright (C) 2014, Jaguar Land Rover
-#
-# This program is licensed under the terms and conditions of the
-# Mozilla Public License, version 2.0. The full text of the
-# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
-#
-
-#
-# Simple SOTA Client
-#
-import sys
-from rvi_json_rpc_server import RVIJSONRPCServer
-import jsonrpclib
-import random
-import time
-import threading
-import os
-import base64
-import struct
-import SocketServer
-from base64 import b64encode
-from hashlib import sha1
-from mimetools import Message
-from StringIO import StringIO
-import json
-from subprocess import call
-
-g_fd = -1
-g_package = ''
-g_chunk_size = 0
-g_total_size = 0
-g_chunk_index = 0
-g_retry = 0
-
-rvi_sota_prefix = "jlr.com/backend/sota"
-available_packagess = []
-
-class WebSocketsHandler(SocketServer.StreamRequestHandler):
- magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
-
- def setup(self):
- SocketServer.StreamRequestHandler.setup(self)
- print "connection established", self.client_address
- self.handshake_done = False
-
- def handle(self):
- print "Handle"
- self.active = True
- while self.active:
- if not self.handshake_done:
- self.handshake()
- else:
- self.read_next_message()
-
- def read_next_message(self):
- msg = self.rfile.read(2)
- if len(msg) < 2:
- print "Connection closed"
- self.active = False
- return
-
- length = ord(msg[1]) & 127
- if length == 126:
- length = struct.unpack(">H", self.rfile.read(2))[0]
- elif length == 127:
- length = struct.unpack(">Q", self.rfile.read(8))[0]
- masks = [ord(byte) for byte in self.rfile.read(4)]
- decoded = ""
- for char in self.rfile.read(length):
- decoded += chr(ord(char) ^ masks[len(decoded) % 4])
- self.on_message(decoded)
-
- def send_message(self, message):
- self.request.send(chr(129))
- length = len(message)
- if length <= 125:
- self.request.send(chr(length))
- elif length >= 126 and length <= 65535:
- self.request.send(chr(126))
- self.request.send(struct.pack(">H", length))
- else:
- self.request.send(chr(127))
- self.request.send(struct.pack(">Q", length))
- self.request.send(message)
-
- def handshake(self):
- data = self.request.recv(1024).strip()
- headers = Message(StringIO(data.split('\r\n', 1)[1]))
- if headers.get("Upgrade", None) != "websocket":
- return
- print 'Handshaking...'
- key = headers['Sec-WebSocket-Key']
- digest = b64encode(sha1(key + self.magic).hexdigest().decode('hex'))
- response = 'HTTP/1.1 101 Switching Protocols\r\n'
- response += 'Upgrade: websocket\r\n'
- response += 'Connection: Upgrade\r\n'
- response += 'Sec-WebSocket-Accept: %s\r\n\r\n' % digest
- self.handshake_done = self.request.send(response)
-
-
- def on_message(self, message):
- global g_fd
- global g_chunk_index
- global g_total_size
- cmd = json.loads(message)
- tid = cmd['id']
-
- if cmd['method'] == 'GetPendingUpdates':
- print "Got message", message
- self._get_pending_updates(cmd['id'])
- return
-
- if cmd['method'] == 'StartUpdate':
- print "Got StartUpdate"
- self._start_update(cmd['id'])
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': "" }))
- return
-
- if cmd['method'] == 'CancelUpdate':
- print "Got CancelUpdate"
- self._cancel_download()
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': "" }))
- return
-
- if cmd['method'] == 'GetCarSyncState':
- # Check if we have closed the given file.
- # If so, return state idle to shut down progress bar
- # in HMI.
- if g_fd == -1:
- print "File has closed. Done"
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': { 'progress': 100,
- 'state': 'Idle'} }))
- finish(1)
- return
-
- # CHeck that we have actual progress to report
- if g_fd == -1:
- print "No update in progress."
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': { 'progress': 0,
- 'state': 'Update'} }))
- return
-
- g_chunk_index = g_chunk_index + random.randrange(2,10)
- print "Chunk is now", g_chunk_index
- # Are we done faking?
- if g_chunk_index > 100:
- g_chunk_index = 100
- g_fd = -1
-
-
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': { 'progress': g_chunk_index,
- 'state': 'Update'} }))
- # Change 'state' to Idle when done
-
- return
- print "UNKNOWN MESSAGE", message
- return
-
-
- def _cancel_download(self):
- pkg = available_packagess.pop(0)
- retry = pkg['retry']
-
- print "Will cancel download of package:",pkg['uuid']
- rvi_server.message(calling_service = "/sota",
- service_name = rvi_sota_prefix + "/cancel_download",
- transaction_id = time.time(),
- timeout = int(time.time())+60,
- parameters = [{
- u'retry': retry
- }])
- return
-
- def _start_update(self, tid):
- global full_notify_service_name
- global g_retry
- global g_package
- global g_fd
- global g_chunk_index
- # Strip the last component off self's full notify
- # service name to get a destination to send over
- # to the SOTA server's initiate_download
-
- last_slash = full_notify_service_name.rfind('/')
- destination = full_notify_service_name[:last_slash]
-
- self.send_message(json.dumps({'jsonrpc': '2.0',
- 'id': tid,
- 'result': [ ] }))
-
- pkg = available_packagess.pop(0)
- package = pkg['uuid']
- g_retry = pkg['retry']
- g_fd = 1
- g_chunk_index = 0
- g_package = package
- print "Will initate download of package:",package
-# rvi_server.message(calling_service = "/sota",
-# service_name = rvi_sota_prefix + "/initiate_download",
-# transaction_id = time.time(),
-# timeout = int(time.time())+60,
-# parameters = [{
-# u'package': package,
-# u'retry': g_retry,
-# u'destination': destination
-# }])
-
- return
-
- def _get_pending_updates(self, tid):
- global available_packagess
- print "Available Packages:", available_packagess
- result = {
- 'jsonrpc': '2.0',
- 'id': tid,
- 'result': available_packagess
- }
- self.send_message(json.dumps(result))
-
-def usage():
- print "Usage:", sys.argv[0], "<rvi_url> <service_id>"
- print " <rvi_url> URL of Service Edge on a local RVI node"
- print
- print "The RVI Service Edge URL can be found in"
- print "[backend,vehicle].config as"
- print "env -> rvi -> components -> service_edge -> url"
- print
- print "The Service Edge URL is also logged as a notice when the"
- print "RVI node is started."
- sys.exit(255)
-
-
-def notify(package, retry):
- print "Available packet:", package
- available_packagess.append({
- "uuid": package,
- "retry": retry,
- "version": {
- "version_major":1,
- "version_minor":0,
- "version_build":0
- }
- })
-
-
- return {u'status': 0}
-
-def start(package, chunk_size, total_size):
- global g_fd
- global g_package
- global g_chunk_size
- global g_total_size
-
- g_package = package
- g_chunk_size = chunk_size
- g_total_size = total_size
- file_name = "/tmp/" + package
-
- print "Starting package:", file_name
- # g_fd = open(file_name, "w")
- #print "open fd = ", g_fd
- return {u'status': 0}
-
-def chunk(index, msg):
- global g_fd
- global g_package
- global g_chunk_size
- global g_chunk_index
-
- g_chunk_index = index
- decoded_msg = base64.b64decode(msg)
-
- print "Chunk:", index, " ck_sz:", g_chunk_size, " msg_sz:", len(decoded_msg), " offset:", g_chunk_index * g_chunk_size
-
- g_fd.seek(g_chunk_index * g_chunk_size)
- g_fd.write(decoded_msg)
- return {u'status': 0}
-
-
-def finish(dummy):
- global g_fd
- global g_retry
- global g_package
- global g_chunk_index
-
- print "Package:", g_package, " is complete in /tmp"
- # WE WILL FIX ALL THIS IN THE CROSSWALK PORT WHEN THE wrt-installer
- # HOPEFULLY WILL NOT CRASH THE SYSTEM
-# g_fd.close()
- g_fd = -1
- g_chunk_index = 0
-# call(["wrt-installer", "-up", "/tmp/" + g_package])
-# call(["wrt-installer", "-i", "/tmp/" + g_package])
- if g_package.find("2.0") != -1:
- print "Doing 2.0"
- call(["unzip", "-d", "/opt/usr/apps/intelPoc20/res/wgt", "-q", "-o", "/root/AudioSettings2.0.wgt"])
- else:
- print "Doing 1.0"
- call(["unzip", "-d", "/opt/usr/apps/intelPoc20/res/wgt", "-q", "-o", "/root/AudioSettings1.0.wgt"])
-
-
- print "Package:", g_package, " unzipped into /opt/usr/apps/intelPoc20/res/wgt"
-
- # Create a thread to handle incoming stuff so that we can do input
- # in order to get new values
-
- print "Sending download complete"
- rvi_server.message(calling_service = "/sota",
- service_name = rvi_sota_prefix + "/download_complete",
- transaction_id = "2",
- timeout = int(time.time())+60,
- parameters = [{
- u'status': 0,
- u'retry': g_retry
- }])
- g_retry = 0
-
- return {u'status': 0}
-
-#
-# Publish an updated HVAC value, entered at the command line of the
-# HVAC emulator, to all services who have set themselves up as
-# subscribers through the jlr.com/vin/1234/hvac/subscribe service.
-#
-
-#
-# A list of service names that should be notified when a value is
-# updated on the HVAC emulator's command line.
-#
-subscribers = []
-
-#
-# Setup a localhost URL, using a random port, that we will listen to
-# incoming JSON-RPC publish calls on, delivered by our RVI service
-# edge (specified by rvi_url).
-#
-emulator_service_host = 'localhost'
-emulator_service_port = random.randint(20001, 59999)
-emulator_service_url = 'http://'+emulator_service_host + ':' + str(emulator_service_port)
-
-#
-# Check that we have the correct arguments
-#
-if len(sys.argv) != 2:
- usage()
-
-# Grab the URL to use
-[ progname, rvi_url ] = sys.argv
-
-
-# setup the service names we will register with
-# The complete service name will be:
-# jlr.com/vin/1234/hvac/publish
-# - and -
-# jlr.com/vin/1234/hvac/subscribe
-#
-# Replace 1234 with the VIN number setup in the
-# node_service_prefix entry in vehicle.config
-
-# Setup an outbound JSON-RPC connection to the RVI Service Edeg.
-rvi_server = jsonrpclib.Server(rvi_url)
-
-emulator_service = RVIJSONRPCServer(addr=((emulator_service_host, emulator_service_port)),
- logRequests=False)
-
-
-#
-# Regsiter callbacks for incoming JSON-RPC calls delivered to
-# the HVAC emulator from the vehicle RVI node's Service Edge.
-#
-
-emulator_service.register_function(notify, "/sota/notify" )
-emulator_service.register_function(start, "/sota/start" )
-# emulator_service.register_function(chunk, "/sota/chunk" )
-emulator_service.register_function(finish, "/sota/finish" )
-
-# Create a thread to handle incoming stuff so that we can do input
-# in order to get new values
-thr = threading.Thread(target=emulator_service.serve_forever)
-thr.start()
-
-# Setup a websocket thread
-# ws_server = SocketServer.TCPServer(("127.0.0.1", 12999), WebSocketsHandler)
-ws_server = SocketServer.TCPServer(("", 9000), WebSocketsHandler)
-ws_server.allow_reuse_address = True
-ws_thread = threading.Thread(target=ws_server.serve_forever)
-ws_thread.start()
-
-# We may see traffic immediately from the RVI node when
-# we register. Let's sleep for a bit to allow the emulator service
-# thread to get up to speed.
-time.sleep(0.5)
-
-#
-# Register our HVAC emulator service with the vehicle RVI node's Service Edge.
-# We register both services using our own URL as a callback.
-#
-
-# Repeat registration until we succeeed
-rvi_dead = True
-while rvi_dead:
- try:
- res = rvi_server.register_service(service = "/sota/notify",
- network_address = emulator_service_url)
- rvi_dead = False
- except:
- print "No rvi. Wait and retry"
- time.sleep(2.0)
-
-
-full_notify_service_name = res['service']
-
-
-res = rvi_server.register_service(service = "/sota/start",
- network_address = emulator_service_url)
-
-full_start_service_name = res['service']
-
-
-#res = rvi_server.register_service(service = "/sota/chunk",
-# network_address = emulator_service_url)
-
-#full_chunk_service_name = res['service']
-
-res = rvi_server.register_service(service = "/sota/finish",
- network_address = emulator_service_url)
-
-full_finish_service_name = res['service']
-
-print "HVAC Emulator."
-print "Vehicle RVI node URL: ", rvi_url
-print "Emulator URL: ", emulator_service_url
-print "Full notify service name : ", full_notify_service_name
-print "Full start service name : ", full_start_service_name
-#print "Full chunk service name : ", full_chunk_service_name
-print "Full finish service name : ", full_finish_service_name
-
-while True:
- time.sleep(3600.0)
diff --git a/sota_demo/sota_server.py b/sota_demo/sota_server.py
deleted file mode 100644
index 67db373..0000000
--- a/sota_demo/sota_server.py
+++ /dev/null
@@ -1,239 +0,0 @@
-#!/usr/bin/python
-
-#
-# Copyright (C) 2014, Jaguar Land Rover
-#
-# This program is licensed under the terms and conditions of the
-# Mozilla Public License, version 2.0. The full text of the
-# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
-#
-
-#
-# Simple SOTA Client
-#
-import sys
-from rvi_json_rpc_server import RVIJSONRPCServer
-import jsonrpclib
-import random
-import time
-import threading
-import os
-import base64
-import struct
-import SocketServer
-from base64 import b64encode
-from hashlib import sha1
-from mimetools import Message
-from StringIO import StringIO
-import json
-import Queue
-
-transaction_id = 0
-package_queue = Queue.Queue()
-
-def package_pusher():
- global package_queue
- global transaction_id
-
- while True:
- [package, destination] = package_queue.get()
- print "Package pushed will push",package,"to",destination
- try:
- f = open(package)
-
- except Err:
- print "Could not open",file_name,":", Err
- return
-
-
- chunk_size = 128*1024
-
- f_stat = os.stat(package)
-
- transaction_id += 1
- rvi_server.message(calling_service = "/sota",
- service_name = destination + "/start",
- transaction_id = str(transaction_id),
- timeout = int(time.time())+60,
- parameters = [{ u'package': package,
- u'chunk_size': chunk_size,
- u'total_size': f_stat.st_size
- }])
-
- index = 0
-
- while True:
- offset = f.tell()
- msg = f.read(chunk_size)
- if msg == "":
- break
-
- print "Sending package:", package, " chunk:", index, " offset:", offset, " message size: ", len(msg)
-
- transaction_id+=1
- rvi_server.message(calling_service = "/sota",
- service_name = destination + "/chunk",
- transaction_id = str(transaction_id),
- timeout = int(time.time())+60,
- parameters = [
- { u'index': index },
- { u'msg': base64.b64encode(msg) }])
-
- index += 1
-
- f.close()
- print "Finishing package:", package
- time.sleep(1.0)
-
- transaction_id+=1
- rvi_server.message(calling_service = "/sota",
- service_name = destination + "/finish",
- transaction_id = str(transaction_id),
- timeout = int(time.time())+60,
- parameters = [ { u'dummy': 0}])
-
-def usage():
- print "Usage:", sys.argv[0], "<rvi_url>"
- print " <rvi_url> URL of Service Edge on a local RVI node"
- print
- print "The RVI Service Edge URL can be found in"
- print "[backend,vehicle].config as"
- print "env -> rvi -> components -> service_edge -> url"
- print
- print "The Service Edge URL is also logged as a notice when the"
- print "RVI node is started."
- sys.exit(255)
-
-
-def initiate_download(package, retry, destination):
- print "Will push packet", package, " transaction id", retry, " to",destination
- package_queue.put([package, destination])
- return {u'status': 0}
-
-def cancel_download(retry):
- print "transaction", retry, "was cancelled by device."
- return {u'status': 0}
-
-def download_complete(status, retry):
- print "Download transaction",retry," completed with:",status
- return {u'status': 0}
-
-
-#
-# Setup a localhost URL, using a random port, that we will listen to
-# incoming JSON-RPC publish calls on, delivered by our RVI service
-# edge (specified by rvi_url).
-#
-emulator_service_host = 'localhost'
-emulator_service_port = random.randint(20001, 59999)
-emulator_service_url = 'http://'+emulator_service_host + ':' + str(emulator_service_port)
-
-#
-# Check that we have the correct arguments
-#
-if len(sys.argv) != 2:
- usage()
-
-# Grab the URL to use
-[ progname, rvi_url ] = sys.argv
-
-
-
-# Setup an outbound JSON-RPC connection to the RVI Service Edge.
-rvi_server = jsonrpclib.Server(rvi_url)
-
-emulator_service = RVIJSONRPCServer(addr=((emulator_service_host, emulator_service_port)),
- logRequests=False)
-
-
-#
-# Regsiter callbacks for incoming JSON-RPC calls delivered to
-# the SOTA server from the vehicle RVI node's Service Edge.
-#
-initiate_download_service_name = "/sota/initiate_download"
-emulator_service.register_function(initiate_download, initiate_download_service_name )
-
-cancel_download_service_name = "/sota/cancel_download"
-emulator_service.register_function(cancel_download, cancel_download_service_name )
-
-download_complete_service_name = "/sota/download_complete"
-emulator_service.register_function(download_complete, download_complete_service_name )
-
-
-# Create a thread to handle incoming stuff so that we can do input
-# in order to get new values
-thr = threading.Thread(target=emulator_service.serve_forever)
-thr.start()
-
-# We may see traffic immediately from the RVI node when
-# we register. Let's sleep for a bit to allow the emulator service
-# thread to get up to speed.
-time.sleep(0.5)
-
-#
-# Register our HVAC emulator service with the vehicle RVI node's Service Edge.
-# We register both services using our own URL as a callback.
-#
-res = rvi_server.register_service(service = initiate_download_service_name,
- network_address = emulator_service_url)
-
-full_initiate_download_service_name = res['service']
-
-# Cancel download
-res = rvi_server.register_service(service = cancel_download_service_name,
- network_address = emulator_service_url)
-
-full_cancel_download_service_name = res['service']
-
-# Download complete
-res = rvi_server.register_service(service = download_complete_service_name,
- network_address = emulator_service_url)
-
-full_download_complete_service_name = res['service']
-
-print "HVAC Emulator."
-print "Vehicle RVI node URL: ", rvi_url
-print "Emulator URL: ", emulator_service_url
-print "Full initiate download service name : ", full_initiate_download_service_name
-print "Full download complete service name : ", full_download_complete_service_name
-print "Full cancel download service name : ", full_cancel_download_service_name
-
-chunk_size = 1024*64
-
-#
-# Start the queue dispatcher thread
-#
-package_pusher_thr = threading.Thread(target=package_pusher)
-package_pusher_thr.start()
-
-while True:
- transaction_id += 1
- line = raw_input('Enter <vin> <file_name> or "q" for quit: ')
- if line == 'q':
- emulator_service.shutdown()
- sys.exit(0)
-
-
-
- # Read a line and split it into a key val pair
- lst = line.split(' ')
- if len(lst) != 2:
- print "Nope", len(lst), lst
- continue
-
- [vin, file_name] = line.split(' ')
- dst = 'jlr.com/vin/'+vin+'/sota'
- try:
- f = open(file_name)
- except Err:
- print "Could not open",file_name,":", Err
- continue
-
- rvi_server.message(calling_service = "/sota",
- service_name = dst + "/notify",
- transaction_id = str(transaction_id),
- timeout = int(time.time())+60,
- parameters = [{ u'package': file_name,
- u'retry': transaction_id }])
-
- print('Package {} sent to {}'. format(file_name, dst))