0efbc8ea27
- fixed sqlite IntegrityError trapping in etpDatabase.addPackage() - third big commit for the Socket Interface, adding sessions management, changed protocol git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@1509 cd1c1023-2f26-0410-ae45-c471fc1f0318
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
#!/usr/bin/python
|
|
import sys
|
|
import socket
|
|
serverHost = "localhost"
|
|
serverPort = 999
|
|
def spawn(cmd, silent = 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.send(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)
|
|
s.close()
|
|
return data
|
|
|
|
try:
|
|
|
|
# 1st step, get session
|
|
session = spawn("begin", silent = True)
|
|
print "session is:",session # XXX VALIDATE
|
|
|
|
# 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)
|
|
print "REAL returned data:",rc
|
|
|
|
# 4th step, end session
|
|
rc = spawn("%s end" % (session,), silent = True)
|
|
print "END session result",rc
|
|
|
|
except KeyboardInterrupt:
|
|
sys.exit(0)
|