def __init__(self): self.tclsh = Tcl() self.tclsh.eval( "source {C:\Program Files\Spirent Communications\Spirent TestCenter 3.60\Spirent TestCenter Application\SpirentTestCenter.tcl}" ) print "Initiallized"
def testLoadTk(self): import os if 'DISPLAY' not in os.environ: # skipping test of clean upgradeability return tcl = Tcl() self.assertRaises(TclError,tcl.winfo_geometry) tcl.loadtk() self.assertEqual('1x1+0+0', tcl.winfo_geometry())
def testLoadTk(self): import os if 'DISPLAY' not in os.environ: # skipping test of clean upgradeability return tcl = Tcl() self.assertRaises(TclError, tcl.winfo_geometry) tcl.loadtk() self.assertEqual('1x1+0+0', tcl.winfo_geometry())
def run(self): if not self.tcl: self.tcl = Tcl() while self._is_running: if not self.in_q.empty(): command = self.in_q.get() try: rc = self.tcl.eval(command) self.out_q.put(rc) except Exception as e: self.out_q.put(e) time.sleep(1)
def get_tk_patchlevel(): global _tk_patchlevel if _tk_patchlevel is None: tcl = Tcl() patchlevel = [] for x in tcl.call('info', 'patchlevel').split('.'): try: x = int(x, 10) except ValueError: x = -1 patchlevel.append(x) _tk_patchlevel = tuple(patchlevel) return _tk_patchlevel
def get_tk_patchlevel(): global _tk_patchlevel if _tk_patchlevel is None: tcl = Tcl() patchlevel = tcl.call('info', 'patchlevel') m = re.match(r'(\d+)\.(\d+)([ab.])(\d+)$', patchlevel) major, minor, releaselevel, serial = m.groups() major, minor, serial = int(major), int(minor), int(serial) releaselevel = {'a': 'alpha', 'b': 'beta', '.': 'final'}[releaselevel] if releaselevel == 'final': _tk_patchlevel = major, minor, serial, releaselevel, 0 else: _tk_patchlevel = major, minor, 0, releaselevel, serial return _tk_patchlevel
def OpenTcl(self): if self.tclInter is not None: self.tclInter.quit() self.tclInter = Tcl(None, None, 'Tk', 0) self.tclInter.eval(''' rename puts original_puts proc puts {args} { if {[llength $args] == 1} { return "=> [lindex $args 0]" } else { eval original_puts $args } } ''')
class TclInter(baseSession): tclInter = None def __init__(self, name, attrs, logger=None, logpath=None): baseSession.__init__(self, name, attrs, logger, logpath) def __del__(self): try: if self.tclInter is not None: self.tclInter.eval(''' rename original_puts puts ''') except: pass def OpenTcl(self): if self.tclInter is not None: self.tclInter.quit() self.tclInter = Tcl(None, None, 'Tk', 0) self.tclInter.eval(''' rename puts original_puts proc puts {args} { if {[llength $args] == 1} { return "=> [lindex $args 0]" } else { eval original_puts $args } } ''') def SendLine(self, command, Ctrl=False, Alt=False): if self.tclInter is None: self.OpenTcl() command = command.strip() self.output = self.tclInter.eval(command) output = "%s\n%s\n" % (command, self.output) self.seslog.write(output) print(output) return self.output def Expect(self, pattern, wait=None, noWait=False): import re p = re.compile(pattern, re.I | re.M) m = re.search(p, self.output) if m: pass else: msg = 'not found pattern: %s' % pattern raise Exception(msg)
class TgnTk(object): """ Native Python Tk interpreter. """ def __init__(self): self.tcl = Tcl() def eval(self, command): return self.tcl.eval(command)
class TgnTkMultithread(Thread): """ Native Python Tk interpreter with multithreading. """ _is_running = True def __init__(self): super(self.__class__, self).__init__() self.in_q = Queue() self.out_q = Queue() self.tcl = None def run(self): if not self.tcl: self.tcl = Tcl() while self._is_running: if not self.in_q.empty(): command = self.in_q.get() try: rc = self.tcl.eval(command) self.out_q.put(rc) except Exception as e: self.out_q.put(e) time.sleep(1) def stop(self): self._is_running = False def eval(self, command): self.in_q.put(command) while self.out_q.empty(): time.sleep(1) rc = self.out_q.get() if isinstance(rc, Exception): raise rc return rc
class TclInter(baseSession): tclInter=None def __init__(self, name,attrs,logger=None, logpath=None): baseSession.__init__(self, name, attrs, logger, logpath) def __del__(self): try: if self.tclInter is not None: self.tclInter.eval(''' rename original_puts puts ''') except: pass def OpenTcl(self): if self.tclInter is not None: self.tclInter.quit() self.tclInter = Tcl( None, None, 'Tk', 0) self.tclInter.eval(''' rename puts original_puts proc puts {args} { if {[llength $args] == 1} { return "=> [lindex $args 0]" } else { eval original_puts $args } } ''') def SendLine(self, command , Ctrl=False, Alt=False ): if self.tclInter is None: self.OpenTcl() command =command.strip() self.output =self.tclInter.eval(command) output ="%s\n%s\n"%(command, self.output) self.seslog.write(output) print(output) return self.output def Expect(self,pattern, wait =None, noWait=False): import re p =re.compile(pattern, re.I|re.M) m =re.search(p, self.output) if m: pass else: msg = 'not found pattern: %s'%pattern raise Exception(msg)
def OpenTcl(self): if self.tclInter is not None: self.tclInter.quit() self.tclInter = Tcl( None, None, 'Tk', 0) self.tclInter.eval(''' rename puts original_puts proc puts {args} { if {[llength $args] == 1} { return "=> [lindex $args 0]" } else { eval original_puts $args } } ''')
def testLoadTkFailure(self): old_display = None if sys.platform.startswith(('win', 'darwin', 'cygwin')): return else: with test_support.EnvironmentVarGuard() as env: if 'DISPLAY' in os.environ: del env['DISPLAY'] display = os.popen('echo $DISPLAY').read().strip() if display: return tcl = Tcl() self.assertRaises(TclError, tcl.winfo_geometry) self.assertRaises(TclError, tcl.loadtk) return
def testLoadTkFailure(self): old_display = None if sys.platform.startswith(('win', 'darwin', 'cygwin', 'msys')): # no failure possible on windows? # XXX Maybe on tk older than 8.4.13 it would be possible, # see tkinter.h. return with test_support.EnvironmentVarGuard() as env: if 'DISPLAY' in os.environ: del env['DISPLAY'] # on some platforms, deleting environment variables # doesn't actually carry through to the process level # because they don't support unsetenv # If that's the case, abort. display = os.popen('echo $DISPLAY').read().strip() if display: return tcl = Tcl() self.assertRaises(TclError, tcl.winfo_geometry) self.assertRaises(TclError, tcl.loadtk)
def testLoadTkFailure(self): import os old_display = None import sys if sys.platform.startswith(('win', 'darwin', 'cygwin')): return # no failure possible on windows? if 'DISPLAY' in os.environ: old_display = os.environ['DISPLAY'] del os.environ['DISPLAY'] # on some platforms, deleting environment variables # doesn't actually carry through to the process level # because they don't support unsetenv # If that's the case, abort. display = os.popen('echo $DISPLAY').read().strip() if display: return try: tcl = Tcl() self.assertRaises(TclError, tcl.winfo_geometry) self.assertRaises(TclError, tcl.loadtk) finally: if old_display is not None: os.environ['DISPLAY'] = old_display
def setUp(self): self.interp = Tcl() self.wantobjects = self.interp.tk.wantobjects()
def setUpModule(): if test_support.verbose: tcl = Tcl() print "patchlevel =", tcl.call("info", "patchlevel")
#!/usr/bin/python #encoding=utf-8 import os, sys, time, re import socket, struct from Tkinter import Tcl tcl = Tcl() class kmanager(): def __init__(self, rootdir="./"): self.script = os.path.join(rootdir, "Script", "Throughput.scr").replace("\\", "/") self.downscript = os.path.join(rootdir, "Script", "Throughputdown.scr").replace( "\\", "/") self.chariot_result = rootdir + "result" def save_chariot(allstr=None): fd = open(self.chariot_result, "a+") fd.write(allstr + "\n") fd.close() def run_Ixchariot(self, **kargs): self.start_ip = kargs['sip'].split(" ") self.sip_len = len(self.start_ip) self.dst_ip = kargs['dip'].split(" ") self.dip_len = len(self.dst_ip) self.sum_pair = kargs['sum_pair'] self.tx_pair = kargs['tx_pair'] self.proto = kargs['proto'].upper()
def __init__(self): self.tcl = Tcl()
# 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. ''' This file generates Ixia Library wrapper in Python, using TCL functions from IxTclHal. ''' from Tkinter import Tcl from collections import OrderedDict tcl = Tcl() tcl.eval('package req IxTclHal') tcl.eval('ixConnectToTclServer 10.144.31.91') tcl.eval('ixConnectToChassis 10.144.31.91') # # # # # # # # head = """ from Tkinter import Tcl t = Tcl() t.eval('package req IxTclHal') true = True
def setUpModule(): if test_support.verbose: tcl = Tcl() print 'patchlevel =', tcl.call('info', 'patchlevel')
# 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. ''' This file generates Ixia Library wrapper in Python, using TCL functions from IxTclHal. ''' from Tkinter import Tcl from collections import OrderedDict tcl = Tcl() tcl.eval('package req IxTclHal') tcl.eval('ixConnectToTclServer 10.144.31.91') tcl.eval('ixConnectToChassis 10.144.31.91') # # # # # # # # HEAD = """ from Tkinter import Tcl t = Tcl() t.eval('package req IxTclHal') true = True
class StcService(object): def __init__(self): self.tclsh = Tcl() self.tclsh.eval( "source {C:\Program Files\Spirent Communications\Spirent TestCenter 3.60\Spirent TestCenter Application\SpirentTestCenter.tcl}" ) print "Initiallized" # 对于服务端来说, 只有以" "打头的方法才能被客户端调用,所以要提供给客户端的方法都得加" " def test(self, num): return 1 + num def getVersion(self): return "STC 3.60" def init(self, *args): cmd = build_cmd('stc::init', *args) return self.tclsh.eval(cmd) def connect(self, *args): cmd = build_cmd('stc::connect', *args) return self.tclsh.eval(cmd) def disconnect(self, *args): cmd = build_cmd('stc::disconnect', *args) return self.tclsh.eval(cmd) def create(self, *args): cmd = build_cmd('stc::create', *args) return self.tclsh.eval(cmd) def delete(self, *args): cmd = build_cmd('stc::delete', *args) return self.tclsh.eval(cmd) def config(self, *args): cmd = build_cmd('stc::config', *args) return self.tclsh.eval(cmd) def get(self, *args): cmd = build_cmd('stc::get', *args) return self.tclsh.eval(cmd) def perform(self, *args): cmd = build_cmd('stc::perform', *args) return self.tclsh.eval(cmd) def apply(self, *args): cmd = build_cmd('stc::apply', *args) return self.tclsh.eval(cmd) def reserve(self, *args): cmd = build_cmd('stc::reserve', *args) return self.tclsh.eval(cmd) def release(self, *args): cmd = build_cmd('stc::release', *args) return self.tclsh.eval(cmd) def subscribe(self, *args): cmd = build_cmd('stc::subscribe', *args) return self.tclsh.eval(cmd) def unsubscribe(self, *args): cmd = build_cmd('stc::unsubscribe', *args) return self.tclsh.eval(cmd) def sleep(self, *args): cmd = build_cmd('stc::sleep', *args) return self.tclsh.eval(cmd) def help(self, *args): cmd = build_cmd('stc::help', *args) return self.tclsh.eval(cmd)
def testLoadTk(self): tcl = Tcl() self.assertRaises(TclError, tcl.winfo_geometry) tcl.loadtk() self.assertEqual('1x1+0+0', tcl.winfo_geometry()) tcl.destroy()
def setUp(self): self.root = Tcl()
def setUp(self): self.interp = Tcl()
import Tkinter from Tkinter import Tcl root = Tcl() print "This is root",root root.eval("puts Siva")
def setUpModule(): if test_support.verbose: tcl = Tcl() shout 'patchlevel =', tcl.call('info', 'patchlevel')
''' |----------------------------| | Spirent STC wrapper module | |----------------------------| This is a python wrapper other STC TCL library The TCLLIBPATH environment variable must be set to include the path to Spirent Test Center Application directory. Example: export TCLLIBPATH=/home/user/Spirent_TestCenter_4.44/Spirent_TestCenter_Application_Linux ''' from Tkinter import Tcl t = Tcl() t.eval('package req SpirentTestCenter') true = True false = False yes = True no = False none = None def stc_apply(): r = t.eval('stc::apply') return r def stc_config(handle_string, attributes):