diff options
author | Akos PASZTORY <ext-akos.pasztory@nokia.com> | 2009-10-27 11:02:24 +0200 |
---|---|---|
committer | Akos PASZTORY <ext-akos.pasztory@nokia.com> | 2009-10-27 11:02:24 +0200 |
commit | 897c2d04e413466efb5b8a342a0f61bc207a679d (patch) | |
tree | 66d9b746c71a1e4be2109265e23a2887cd961d39 | |
parent | 455b85adf612f6c851c99265b32648b084fc4d9c (diff) | |
parent | a1dbbb617bb18e216b9f57a4c6e2e91cc1ea4593 (diff) |
Merge remote branch 'origin/master' into provider-commander-proxy
-rwxr-xr-x | libcontextsubscriber/customer-tests/commander/commander_disabled.py | 3 | ||||
-rwxr-xr-x | libcontextsubscriber/customer-tests/registry/registry.py | 2 | ||||
-rwxr-xr-x | sandbox/context-proxy | 112 |
3 files changed, 115 insertions, 2 deletions
diff --git a/libcontextsubscriber/customer-tests/commander/commander_disabled.py b/libcontextsubscriber/customer-tests/commander/commander_disabled.py index 5e3a6648..0fffd634 100755 --- a/libcontextsubscriber/customer-tests/commander/commander_disabled.py +++ b/libcontextsubscriber/customer-tests/commander/commander_disabled.py @@ -46,9 +46,10 @@ class CommanderDisabled(unittest.TestCase): commander.expect(CLTool.STDOUT, "Added", 10) # wait for it os.environ["CONTEXT_CLI_IGNORE_COMMANDER"] = "" listen = CLTool("context-listen", "test.int") + listen.expect(CLTool.STDERR, "Available commands", 10) # wait for it self.assert_(listen.expect(CLTool.STDOUT, CLTool.wanted("test.int", "int", "42"), - 1), + 3), "Provider provided value is wrong") def runTests(): diff --git a/libcontextsubscriber/customer-tests/registry/registry.py b/libcontextsubscriber/customer-tests/registry/registry.py index 629946f3..12dbfbe0 100755 --- a/libcontextsubscriber/customer-tests/registry/registry.py +++ b/libcontextsubscriber/customer-tests/registry/registry.py @@ -67,7 +67,7 @@ class PrintingProperties(unittest.TestCase): self.assert_(info_client.expectAll(CLTool.STDOUT, expected_results, - 1), + 10), "Bad introspection result from context-ls") def runTests(): diff --git a/sandbox/context-proxy b/sandbox/context-proxy new file mode 100755 index 00000000..2b6a366b --- /dev/null +++ b/sandbox/context-proxy @@ -0,0 +1,112 @@ +#!/usr/bin/python + +from sys import stderr, stdin +from subprocess import Popen, PIPE +from select import select +import re +import os + +class Program: + def __init__(self, cline): + d = dict(os.environ) + d.update({"CONTEXT_CLI_DISABLE_TYPE_CHECK": "1", + "CONTEXT_CLI_IGNORE_COMMANDER": "1"}) + + self.__process = Popen(cline, stdin=PIPE, stdout=PIPE, stderr=PIPE, + env = d) + + def send(self, string): + print >>self.__process.stdin, string + self.__process.stdin.flush() + + def outfd(self): + return self.__process.stdout.fileno() + + def readline(self): + return self.__process.stdout.readline() + + def ready(self): + raise NotImplementedError + +class Listen(Program): + def __init__(self, *properties): + Program.__init__(self, ["context-listen"] + list(properties)) + + def ready(self): + global provide + line = self.readline() + if line: + print >>stderr, "LISTEN:", line, + match = re.match("(.*?) = (.*?):(.*)\n", line) + if match: + property = match.group(1) + type = "" + if match.group(2) == "QString": + type = "string" + elif match.group(2) == "int": + type = "int" + elif match.group(2) == "bool": + type = "truth" + elif match.group(2) == "double": + type = "double" + else: + raise RuntimeError("unknown type from client: " + match.group(2)) + value = match.group(3) + provide.send("add " + type + " " + property + " " + value) + match = re.match("(.*?) is Unknown\n", line) + if match: + property = match.group(1) + provide.send("add " + type + " " + property) + provide.send("unset " + property) + + return True + else: + raise RuntimeError("context-listen terminated") + +class Provide(Program): + def __init__(self): + Program.__init__(self, ["context-provide-internal"]) + + def ready(self): + line = self.readline() + if line: + print "PROVIDE:", line, + return True + else: + raise RuntimeError("context-provide terminated") + +class UserInput(): + def outfd(self): + return stdin.fileno() + + def ready(self): + line = self.readline() + if line: + match = re.match("(.*?) (.*)\n", line) + command = match.group(1) + return True + else: + exit(0) + +class Select: + def __init__(self, *tools): + self.map = dict(map(lambda t: (t.outfd(), t), tools)) + self.rlist = map(lambda t: t.outfd(), tools) + + def select(self): + ret = select(self.rlist, [], [])[0] + for i in ret: + stderr.flush() + if not self.map[i].ready(): + self.rlist.remove(i) + del self.map[i] + +listen = Listen("test.a", "test.b") +provide = Provide() +provide.send("start") +s = Select(listen, provide) + +while True: + s.select() + if not s.rlist: + break |