Example #1
0
def telnet(*k, **kw):
    """
    sends text via telnet
    example: telnet(port=2000, host="someotherhost.com")
    """
    if (len(k) == 3 and len(kw) == 0):
        port = 8999
        host = "127.0.0.1"
        if (not telnetOutput.has_key((port, host))):
            telnetOutput[(port, host)] = Telnet(host, port)
        _within = k[0]
        _text = k[1]
        _text = _text % _getNamespace(back=2)
        print "sending %s " % _text
        telnetOutput[(port, host)].write(_text)
        return
    port = kw.get("port", 8999)
    host = kw.get("host", "127.0.0.1")

    if (not telnetOutput.has_key((port, host))):
        telnetOutput[(port, host)] = Telnet(host, port)

    def telnettransform(within, _text, g):
        _text = _text % _getNamespace(back=2)
        print "sending %s " % _text
        telnetOutput[(port, host)].write(_text)

    return telnettransform
Example #2
0
def telnet(*k, **kw):
    """
    sends text via telnet
    example: telnet(port=2000, host="someotherhost.com")
    """
    if (len(k)==3 and len(kw)==0):
        port=8999
        host="127.0.0.1"
        if (not telnetOutput.has_key((port, host))):
            telnetOutput[(port, host)] = Telnet(host, port)
        _within = k[0]
        _text = k[1]
        _text = _text % _getNamespace(back=2)
        print "sending %s " % _text
        telnetOutput[(port, host)].write(_text)
        return
    port = kw.get("port", 8999)
    host = kw.get("host", "127.0.0.1")

    if (not telnetOutput.has_key((port, host))):
        telnetOutput[(port, host)] = Telnet(host, port)
    def telnettransform(within, _text, g):
        _text = _text % _getNamespace(back=2)
        print "sending %s " % _text
        telnetOutput[(port, host)].write(_text)

    return telnettransform
Example #3
0
def bash(*args):
    """Execute in a bash shell.
	There are two ways to call this, first as just 'bash' this executes the text and prints the output. Secondly, bash("varname"), executes the text and sets varname equal to this output.
	"""
    if (len(args) == 3):
        a, b, c = args
        ss = b % _getNamespace(2)
        print ss
        pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
        f = file(pp, "w")
        print >> f, ss
        f.close()
        ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
        ex.waitFor(1)
        print ex.getOutput()
        return ex.getOutput()
    else:

        def doBash(a, b, c):
            ss = b % _getNamespace(2)
            pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
            f = file(pp, "w")
            print >> f, ss
            f.close()
            ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
            ex.waitFor(1)
            c[args[0]] = ex.getOutput()
            return ex.getOutput()

        return doBash
Example #4
0
def bash(*args):
	"""Execute in a bash shell.
	There are two ways to call this, first as just 'bash' this executes the text and prints the output. Secondly, bash("varname"), executes the text and sets varname equal to this output.
	"""
	if (len(args)==3):
		a,b,c = args
		ss = b % _getNamespace(2)
		print ss
		pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
		f = file(pp, "w")
		print >> f, ss
		f.close()
		ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
		ex.waitFor(1)
		print ex.getOutput()
		return ex.getOutput()
	else:
		def doBash(a,b,c):
			ss = b % _getNamespace(2)
			pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
			f = file(pp, "w")
			print >> f, ss
			f.close()
			ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
			ex.waitFor(1)
			c[args[0]]=ex.getOutput()
			return ex.getOutput()
		return doBash
Example #5
0
 def telnettransform(within, _text, g):
     _text = IndentationUtils.indentTo(0, _text)
     _text = _text.replace("\n","\\n")
     _text = _text.replace("\t","\\t")
     _text = _text.replace("\"","\\\"")
     if (injectGlobals):
         _text = _text % _getNamespace(2)
     _text = "python\"%s\"" % _text
     telnetOutput[(port, host)].write(_text)
Example #6
0
 def telnettransform(within, _text, g):
     _text = IndentationUtils.indentTo(0, _text)
     _text = _text.replace("\n", "\\n")
     _text = _text.replace("\t", "\\t")
     _text = _text.replace("\"", "\\\"")
     if (injectGlobals):
         _text = _text % _getNamespace(2)
     _text = "python\"%s\"" % _text
     telnetOutput[(port, host)].write(_text)
Example #7
0
 def doBash(a, b, c):
     ss = b % _getNamespace(2)
     pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
     f = file(pp, "w")
     print >> f, ss
     f.close()
     ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
     ex.waitFor(1)
     c[args[0]] = ex.getOutput()
     return ex.getOutput()
Example #8
0
		def doBash(a,b,c):
			ss = b % _getNamespace(2)
			pp = File.createTempFile("field_tmpBash", "").getAbsolutePath()
			f = file(pp, "w")
			print >> f, ss
			f.close()
			ex = ExecuteCommand(".", ["/bin/bash", pp], 1)
			ex.waitFor(1)
			c[args[0]]=ex.getOutput()
			return ex.getOutput()
Example #9
0
def telnetMaya(*k, **kw):
    """Sends code (python) to Maya.
    example: telnetMaya(port=8000,host="someotherhost.com",injectGlobals=1)
    """
    if (len(k) == 3 and len(kw) == 0):
        port = 8999
        host = "127.0.0.1"
        injectGlobals = 1
        if (not telnetOutput.has_key((port, host))):
            telnetOutput[(port, host)] = Telnet(host, port)
        within = k[0]
        _text = k[1]
        g = k[2]
        _text = IndentationUtils.indentTo(0, _text)
        _text = _text.replace("\n", "\\n")
        _text = _text.replace("\t", "\\t")
        _text = _text.replace("\"", "\\\"")
        if (injectGlobals):
            _text = _text % _getNamespace(2)
        _text = "python\"%s\"" % _text
        telnetOutput[(port, host)].write(_text)
        return
    port = kw.get("port", 8999)
    host = kw.get("host", "127.0.0.1")
    injectGlobals = kw.get("injectGlobals", 1)
    if (not telnetOutput.has_key((port, host))):
        telnetOutput[(port, host)] = Telnet(host, port)

    def telnettransform(within, _text, g):
        _text = IndentationUtils.indentTo(0, _text)
        _text = _text.replace("\n", "\\n")
        _text = _text.replace("\t", "\\t")
        _text = _text.replace("\"", "\\\"")
        if (injectGlobals):
            _text = _text % _getNamespace(2)
        _text = "python\"%s\"" % _text
        telnetOutput[(port, host)].write(_text)

    return telnettransform
Example #10
0
def telnetMaya(*k, **kw):
    """Sends code (python) to Maya.
    example: telnetMaya(port=8000,host="someotherhost.com",injectGlobals=1)
    """
    if (len(k)==3 and len(kw)==0):
        port=8999
        host="127.0.0.1"
        injectGlobals=1
        if (not telnetOutput.has_key((port, host))):
            telnetOutput[(port, host)] = Telnet(host, port)
        within = k[0]
        _text = k[1]
        g = k[2]
        _text = IndentationUtils.indentTo(0, _text)
        _text = _text.replace("\n","\\n")
        _text = _text.replace("\t","\\t")
        _text = _text.replace("\"","\\\"")
        if (injectGlobals):
            _text = _text % _getNamespace(2)
        _text = "python\"%s\"" % _text
        telnetOutput[(port, host)].write(_text)
        return 
    port = kw.get("port", 8999)
    host = kw.get("host", "127.0.0.1")
    injectGlobals = kw.get("injectGlobals", 1)
    if (not telnetOutput.has_key((port, host))):
        telnetOutput[(port, host)] = Telnet(host, port)
    def telnettransform(within, _text, g):
        _text = IndentationUtils.indentTo(0, _text)
        _text = _text.replace("\n","\\n")
        _text = _text.replace("\t","\\t")
        _text = _text.replace("\"","\\\"")
        if (injectGlobals):
            _text = _text % _getNamespace(2)
        _text = "python\"%s\"" % _text
        telnetOutput[(port, host)].write(_text)
    return telnettransform
Example #11
0
def insideGenerator(within, _text, g):
    """ wrap inside generator, and perform """
    genPreamble = """
#from __future__ import generators
def __exit0():
	_environment.exit()
def __enter0():
	_environment.enter()
def __tmp0():
	yield 0
"""
    genPostamble = """
#	globals().update(locals())
u.stackPrePost(__enter0, __tmp0(), _progress, __exit0)
"""
    _text = IndentationUtils.indentTo(1, _text)
    _text = genPreamble+_text+genPostamble
    localLocal = {"_progress":None}
    if (within):
	if (within.get()):
	    if (within.get().reference):
		localLocal["_progress"]=within.get().reference

    exec _text in _getNamespace(back=2), localLocal
Example #12
0
def insideGenerator(within, _text, g):
    """ wrap inside generator, and perform """
    genPreamble = """
#from __future__ import generators
def __exit0():
	_environment.exit()
def __enter0():
	_environment.enter()
def __tmp0():
	yield 0
"""
    genPostamble = """
#	globals().update(locals())
u.stackPrePost(__enter0, __tmp0(), _progress, __exit0)
"""
    _text = IndentationUtils.indentTo(1, _text)
    _text = genPreamble + _text + genPostamble
    localLocal = {"_progress": None}
    if (within):
        if (within.get()):
            if (within.get().reference):
                localLocal["_progress"] = within.get().reference

    exec _text in _getNamespace(back=2), localLocal
Example #13
0
def defaultTransform(within, _text, g):
    """ do nothing, just execute the text itself """
    exec _text in _getNamespace(back=2)
Example #14
0
 def telnettransform(within, _text, g):
     _text = _text % _getNamespace(back=2)
     print "sending %s " % _text
     telnetOutput[(port, host)].write(_text)
Example #15
0
def defaultTransform(within, _text, g):
    """ do nothing, just execute the text itself """
    exec _text in _getNamespace(back=2)
Example #16
0
 def telnettransform(within, _text, g):
     _text = _text % _getNamespace(back=2)
     print "sending %s " % _text
     telnetOutput[(port, host)].write(_text)
Example #17
0
def applescript(inside, text, l, back=2):
    """Execute as AppleScript"""
    script = AppleScript(text % _getNamespace(back), 1)
    print "script:%s"%script.getOutput()
Example #18
0
def applescript(inside, text, l, back=2):
    """Execute as AppleScript"""
    script = AppleScript(text % _getNamespace(back), 1)
    print "script:%s" % script.getOutput()