Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[a92026]: contrib / manhole.py Maximize Restore History

Download this file

manhole.py    34 lines (28 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This is a script that allows you to talk to the embedded python interpreter
# using ssh. To use it, put it in the GUIScript directory and then add the
# following to include.py, or issue using the python console
#
# import manhole
# manhole.createManhole(port = 2222, users = { 'gemrb': 'password' })
#
# Then you can connect using ssh to the given port and issue python commands.
import GemRB
from twisted.internet import reactor
reactor.startRunning()
GemRB.SetTickHook(lambda: reactor.iterate())
from twisted.conch import manhole, manhole_ssh
from twisted.conch.insults import insults
from twisted.cred import checkers, portal
def createManhole(port = 2222, users = { 'gemrb': 'password' }):
"""Create a twisted manhole for accessing the embedded python interpreter"""
namespace = { 'GemRB' : GemRB }
def makeProtocol():
return insults.ServerProtocol(manhole.ColoredManhole, namespace)
r = manhole_ssh.TerminalRealm()
r.chainedProtocolFactory = makeProtocol
c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
for (username, password) in users.iteritems():
c.addUser(username, password)
p = portal.Portal(r, [c])
f = manhole_ssh.ConchFactory(p)
return reactor.listenTCP(port, f)