forked from cmnolan/opencog-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyshell.py
32 lines (26 loc) · 1.06 KB
/
pyshell.py
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
import opencog.cogserver
from opencog.atomspace import types
# Have a module-global ipshell, which means that variables will remain. It doesn't work yet for some reason.
ipshell = None
# A nice IPython shell that runs within the CogServer.
# NOTE: it uses the CogServer input/output, not the telnet shell
class shell(opencog.cogserver.Request):
def run(self,args,atomspace):
self.run_shell(atomspace)
def run_shell(self, space):
global ipshell
from opencog.atomspace import AtomSpace, types, Atom, Handle, TruthValue
t = types
a = space
namespace = locals().copy()
doc = """OpenCog Python Shell. Access the main AtomSpace as 'space' or 'a'."""
try:
import sys; sys.argv = ['', '-noconfirm_exit', '-p', 'sh']
from IPython import embed
if ipshell == None:
ipshell = embed(user_ns = namespace)
ipshell()
except Exception, e:
print e
# import code
# code.interact(doc, None, namespace)