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
+89 -18
View File
@@ -10,27 +10,98 @@
# Please read the COPYING file. # Please read the COPYING file.
# #
import socket import socket
import struct
def sendCommand(cmd, blocking=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: try:
s = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) self.sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
s.connect("/tmp/comar") self.sock.connect("/tmp/comar")
s.send(cmd) except:
s.close() # should raise an exception here
return True print "Cannot connect to COMAR"
except socket.error:
return False
def registerScript(om, appname, scriptPath): def __pack(self, cmd, id, args):
cmd = '+' + om + ' ' + appname + ' ' +scriptPath + '\n' size = 0
return sendCommand(cmd) 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 removeScripts(appname): def read_reply(self):
cmd = "-" + appname + '\n' pass
return sendCommand(cmd)
def call(om): def localize(self, localename):
cmd = '$' + om + '\n' """Sets the language for translated replies.
return sendCommand(cmd)
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
comard = ComarIface()
+4 -4
View File
@@ -26,7 +26,7 @@ import packagedb
from packagedb import inst_packagedb from packagedb import inst_packagedb
import dependency import dependency
from metadata import MetaData from metadata import MetaData
import comariface from comariface import comard
import operations import operations
#import conflicts #import conflicts
@@ -83,11 +83,11 @@ class Installer:
for pcomar in self.metadata.package.providesComar: for pcomar in self.metadata.package.providesComar:
scriptPath = os.path.join(self.package.comar_dir(),pcomar.script) scriptPath = os.path.join(self.package.comar_dir(),pcomar.script)
ui.info("Registering COMAR script %s\n" % pcomar.script) ui.info("Registering COMAR script %s\n" % pcomar.script)
ret = comariface.registerScript(pcomar.om, # FIXME: We must check the result of the command (possibly
# with id?)
comard.register(pcomar.om,
self.metadata.package.name, self.metadata.package.name,
scriptPath) scriptPath)
if not ret:
ui.error("registerScript failed. Be sure that comard is running!\n")
def check_requirements(self): def check_requirements(self):
"""check system requirements""" """check system requirements"""
+3 -2
View File
@@ -24,7 +24,7 @@ def remove_single(package_name):
"""Remove a single package""" """Remove a single package"""
from installdb import installdb from installdb import installdb
from packagedb import inst_packagedb from packagedb import inst_packagedb
from comariface import removeScripts from comariface import comard
#TODO: check dependencies #TODO: check dependencies
@@ -44,7 +44,8 @@ def remove_single(package_name):
os.unlink(fpath) os.unlink(fpath)
installdb.remove(package_name) installdb.remove(package_name)
inst_packagedb.remove_package(package_name) inst_packagedb.remove_package(package_name)
removeScripts(package_name) # FIXME: (return value)...
comard.remove(package_name)
def install_single(pkg): def install_single(pkg):
"""install a single package from URI or ID""" """install a single package from URI or ID"""
+2 -1
View File
@@ -48,7 +48,8 @@ def install(packages):
ui.error("Package is not installable. Its very likely a dependency problem.\n") ui.error("Package is not installable. Its very likely a dependency problem.\n")
except Exception, e: except Exception, e:
ui.error("Error: %e\n" % e) print e
ui.error("Error: %s\n" % e)
def install_pkg_files(packages): def install_pkg_files(packages):