New comariface module by Gurer

This commit is contained in:
Barış Metin
2005-08-04 22:57:57 +00:00
parent ff8eec8c19
commit 7bf6c95ec7
4 changed files with 104 additions and 31 deletions
+92 -21
View File
@@ -10,27 +10,98 @@
# Please read the COPYING file.
#
import socket
import struct
def sendCommand(cmd, blocking=False):
try:
s = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
s.connect("/tmp/comar")
s.send(cmd)
s.close()
return True
except socket.error:
return False
class ComarIface:
"""A class for communicating with comard."""
RESULT = 0
FAIL = 1
RESULT_START = 2
RESULT_END = 3
NOTIFY = 4
__LOCALIZE = 5
__REGISTER = 6
__REMOVE = 7
__CALL = 8
def __init__(self):
try:
self.sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
self.sock.connect("/tmp/comar")
except:
# should raise an exception here
print "Cannot connect to COMAR"
def __pack(self, cmd, id, args):
size = 0
args2 = []
# NOTE: COMAR RPC is using network byte order (big endian)
fmt = "!ii"
for a in args:
a = str(a) # damn unicode
fmt += "h%dsB" % (len(a))
size += 2 + len(a) + 1
args2.append(len(a))
args2.append(a.encode("utf-8"))
args2.append(0)
pak = struct.pack(fmt, (cmd << 24) | size, id, *args2)
return pak
def read_reply(self):
pass
def localize(self, localename):
"""Sets the language for translated replies.
Since comard has no way to detect caller's locale, this command
is used for sending user's language to the comard. Afterwards,
all the jobs started with API calls uses translated messages in
their replies.
You can get the localename parameter from setlocale(NULL) call.
"""
pass
def register(self, classname, packagename, cslfile, id = 0):
"""Registers a package script on the system model.
"""
pak = self.__pack(self.__REGISTER, id,
[ classname, packagename, cslfile ]
)
self.sock.send(pak)
def remove(self, packagename, id = 0):
"""Remove package's all scripts from system.
"""
pak = self.__pack(self.__REMOVE, id, [ packagename ])
self.sock.send(pak)
def call(self, methodname, args, id = 0):
"""Makes a configuration call on the system model.
"""
a = [ methodname ]
a.extend(args)
pak =self.__pack(self.__CALL, id, a)
self.sock.send(pak)
def call_package(self, methodname, packagename, args, id = 0):
"""Makes a configuration call directed to a package.
"""
pass
def call_instance(self, methodname, packagename, instancename, args, id = 0):
# not yet decided
pass
def get_packages(self, classname, id = 0):
"""Returns registered packages for a given system model class.
"""
pass
def ask_notify(self, notifyname, id = 0):
"""Asks for a notification event to be delivered.
"""
pass
def registerScript(om, appname, scriptPath):
cmd = '+' + om + ' ' + appname + ' ' +scriptPath + '\n'
return sendCommand(cmd)
def removeScripts(appname):
cmd = "-" + appname + '\n'
return sendCommand(cmd)
def call(om):
cmd = '$' + om + '\n'
return sendCommand(cmd)
comard = ComarIface()
+6 -6
View File
@@ -26,7 +26,7 @@ import packagedb
from packagedb import inst_packagedb
import dependency
from metadata import MetaData
import comariface
from comariface import comard
import operations
#import conflicts
@@ -83,11 +83,11 @@ class Installer:
for pcomar in self.metadata.package.providesComar:
scriptPath = os.path.join(self.package.comar_dir(),pcomar.script)
ui.info("Registering COMAR script %s\n" % pcomar.script)
ret = comariface.registerScript(pcomar.om,
self.metadata.package.name,
scriptPath)
if not ret:
ui.error("registerScript failed. Be sure that comard is running!\n")
# FIXME: We must check the result of the command (possibly
# with id?)
comard.register(pcomar.om,
self.metadata.package.name,
scriptPath)
def check_requirements(self):
"""check system requirements"""
+3 -2
View File
@@ -24,7 +24,7 @@ def remove_single(package_name):
"""Remove a single package"""
from installdb import installdb
from packagedb import inst_packagedb
from comariface import removeScripts
from comariface import comard
#TODO: check dependencies
@@ -44,7 +44,8 @@ def remove_single(package_name):
os.unlink(fpath)
installdb.remove(package_name)
inst_packagedb.remove_package(package_name)
removeScripts(package_name)
# FIXME: (return value)...
comard.remove(package_name)
def install_single(pkg):
"""install a single package from URI or ID"""
+3 -2
View File
@@ -48,8 +48,9 @@ def install(packages):
ui.error("Package is not installable. Its very likely a dependency problem.\n")
except Exception, e:
ui.error("Error: %e\n" % e)
print e
ui.error("Error: %s\n" % e)
def install_pkg_files(packages):
"""install a number of pisi package files"""