Files
entropy/client/entropy-system-test-client
lxnay 4518ac8d4f Entropy:
- Socket Interface, client: correct EOT behavior


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1522 cd1c1023-2f26-0410-ae45-c471fc1f0318
2008-03-27 22:19:46 +00:00

111 lines
2.8 KiB
Python

#!/usr/bin/python
serverHost = "localhost"
serverPort = 999
import sys, os
import socket
socket.setdefaulttimeout(300)
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')
from entropyConstants import *
try:
import cPickle as pickle
except ImportError:
import pickle
try:
import cStringIO as stringio
except ImportError:
import StringIO as stringio
import dumpTools
s = None
def connect():
global s
# 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
def spawn(cmd, silent = False, getobj = False):
# send command
s.sendall(cmd)
data = ''
end_of_tmt = False
while 1:
try:
x = s.recv(8192)
except socket.timeout, e:
print 'interrupted, reason: %s' % (e,)
sys.exit(3)
if not x:
break
data += x
eot = etpConst['socket_service']['answers']['eot']
if data.endswith(eot*2): # if we have two eot it means it's
data = data[:-len(eot)] # been duplicated to avoid to be confused
elif data.endswith(eot):
end_of_tmt = True
data = data[:-len(eot)]
if not silent:
sys.stdout.write(x)
sys.stdout.flush()
if end_of_tmt:
break
if getobj and data:
f = stringio.StringIO(data)
data = dumpTools.unserialize(f)
f.close()
return data
connect()
# 1st step, get session
session = spawn("begin", silent = True)
if session == "0":
print "maximum number of sessions reached, server full"
sys.exit(4)
else:
print "session is:",session
# 2nd step, run the command
#spawn_result = spawn("%s match 'x11-libs/qt'" % (session,), silent = True)
spawn_result = spawn("%s reposync reponames=['sabayonlinux.org'] forceUpdate=True" % (session,))#, silent = True)
#print "spawn result is:",repr(result)
if spawn_result in [
etpConst['socket_service']['answers']['er'],
etpConst['socket_service']['answers']['no'],
etpConst['socket_service']['answers']['cl']
]:
rc = spawn("%s rc" % (session,), silent = True, getobj = True)
print "cannot continue, error code:",repr(spawn_result),"error message:",rc
s.close()
sys.exit(2)
# 3rd step, get rc
rc = spawn("%s rc" % (session,), silent = True, getobj = True)
print "REAL returned data:",repr(rc)
# 4th step, end session
rc = spawn("%s end" % (session,), silent = True)
print "END session result",repr(rc)
s.close()
sys.exit(0)