Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraleherbau2011-03-31 10:43:18 -0400
committeraleherbau2011-03-31 10:43:18 -0400
commit60783280bd63e742b2b70cdbdff8d93758ffe820 (patch)
treef056f0359bb04fc28ab3590b3dd412d4278b31b3 /python/src/tcf/shell.py
parentab638aab968e71abfb8fde370b25c211434a2acd (diff)
downloadorg.eclipse.tcf-60783280bd63e742b2b70cdbdff8d93758ffe820.tar.gz
org.eclipse.tcf-60783280bd63e742b2b70cdbdff8d93758ffe820.tar.xz
org.eclipse.tcf-60783280bd63e742b2b70cdbdff8d93758ffe820.zip
Initial commit of TCF python scripting support.
Diffstat (limited to 'python/src/tcf/shell.py')
-rw-r--r--python/src/tcf/shell.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/python/src/tcf/shell.py b/python/src/tcf/shell.py
new file mode 100644
index 000000000..ac5e3e65f
--- /dev/null
+++ b/python/src/tcf/shell.py
@@ -0,0 +1,58 @@
+# *******************************************************************************
+# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *
+# * Contributors:
+# * Wind River Systems - initial API and implementation
+# *******************************************************************************
+
+import code, sys
+import tcf
+from tcf.util import sync, event
+from tcf import protocol, channel
+
+
+class Shell(code.InteractiveConsole, protocol.ChannelOpenListener, channel.ChannelListener):
+ def __init__(self):
+ locals = {
+ "tcf" : tcf,
+ "connect" : tcf.connect
+ }
+ sys.ps1 = "tcf> "
+ protocol.startEventQueue()
+ protocol.invokeAndWait(protocol.addChannelOpenListener, self)
+ code.InteractiveConsole.__init__(self, locals)
+ def interact(self, banner=None):
+ try:
+ super(Shell, self).interact(banner)
+ finally:
+ protocol.removeChannelOpenListener(self)
+ def onChannelOpen(self, channel):
+ wrapper = sync.DispatchWrapper(channel)
+ self.locals["channel"] = wrapper
+ self.locals["disconnect"] = wrapper.close
+ self.locals["cmd"] = sync.CommandControl(channel, interactive=True)
+ self.locals["events"] = event.EventRecorder(channel)
+ protocol.invokeAndWait(protocol.removeChannelOpenListener, self)
+ wrapper.addChannelListener(self)
+ def onChannelClosed(self, error):
+ del self.locals["channel"]
+ del self.locals["cmd"]
+ del self.locals["disconnect"]
+ del self.locals["events"]
+ protocol.addChannelOpenListener(self)
+
+def interact():
+ try:
+ # enable commandline editing if available
+ import readline
+ except ImportError:
+ pass
+ shell = Shell()
+ shell.interact("TCF Shell")
+
+if __name__ == "__main__":
+ interact()

Back to the top