Files
entropy/client/entropy-system-test-client
T
(no author) b55728f7be Entropy:
- Socket Interface: returned objects are now serialized


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1512 cd1c1023-2f26-0410-ae45-c471fc1f0318
2008-03-25 11:59:31 +00:00

72 lines
1.6 KiB
Python

#!/usr/bin/python
serverHost = "localhost"
serverPort = 999
import sys, os
import socket
sys.path.insert(0,'/usr/lib/entropy/libraries')
sys.path.insert(0,'/usr/lib/entropy/client')
sys.path.insert(0,'../libraries')
sys.path.insert(0,'../client')
try:
import cPickle as pickle
except ImportError:
import pickle
try:
import cStringIO as stringio
except ImportError:
import StringIO as stringio
import dumpTools
def spawn(cmd, silent = False, getobj = False):
# connect
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((serverHost, serverPort))
except socket.error, e:
if e[0] == 111:
print "no daemon running"
sys.exit(1)
else:
raise
# send command
s.sendall(cmd)
# get data
data = ''
x = s.recv(1024)
while x:
data += x
if not silent:
sys.stdout.write(x)
sys.stdout.flush()
x = s.recv(1024)
if getobj:
f = stringio.StringIO(data)
data = dumpTools.unserialize(f)
f.close()
s.close()
return data
# 1st step, get session
session = spawn("begin", silent = True)
print "session is:",session
# 2nd step, run the command
#s.send("reposync reponames=['sabayonlinux.org'] forceUpdate=True")
result = spawn("%s match 'x11-libs/qt'" % (session,), silent = True)
print "spawn result is:",result
# 3rd step, get rc
rc = spawn("%s rc" % (session,), silent = True, getobj = True)
print "REAL returned data:",rc,type(rc)
# 4th step, end session
rc = spawn("%s end" % (session,), silent = True)
print "END session result",rc