Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
class TgnTk(object):
    """ Native Python Tk interpreter. """
    def __init__(self):
        self.tcl = Tcl()

    def eval(self, command):
        return self.tcl.eval(command)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
import Tkinter
from Tkinter import Tcl
root = Tcl()
print "This is root",root


root.eval("puts Siva")
Ejemplo n.º 6
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
false = False
yes   = True
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
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
false = False
yes   = True
Ejemplo n.º 9
0
    |----------------------------|
    | 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):
    r = t.eval('stc::config {} {}'.format(handle_string, attributes))