New comariface module by Gurer
This commit is contained in:
+92
-21
@@ -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:
|
||||||
try:
|
"""A class for communicating with comard."""
|
||||||
s = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
|
RESULT = 0
|
||||||
s.connect("/tmp/comar")
|
FAIL = 1
|
||||||
s.send(cmd)
|
RESULT_START = 2
|
||||||
s.close()
|
RESULT_END = 3
|
||||||
return True
|
NOTIFY = 4
|
||||||
except socket.error:
|
__LOCALIZE = 5
|
||||||
return False
|
__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):
|
comard = ComarIface()
|
||||||
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)
|
|
||||||
|
|||||||
+6
-6
@@ -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
|
||||||
self.metadata.package.name,
|
# with id?)
|
||||||
scriptPath)
|
comard.register(pcomar.om,
|
||||||
if not ret:
|
self.metadata.package.name,
|
||||||
ui.error("registerScript failed. Be sure that comard is running!\n")
|
scriptPath)
|
||||||
|
|
||||||
def check_requirements(self):
|
def check_requirements(self):
|
||||||
"""check system requirements"""
|
"""check system requirements"""
|
||||||
|
|||||||
+3
-2
@@ -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"""
|
||||||
|
|||||||
+3
-2
@@ -48,8 +48,9 @@ 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):
|
||||||
"""install a number of pisi package files"""
|
"""install a number of pisi package files"""
|
||||||
|
|||||||
Reference in New Issue
Block a user