* pisi.PisiError -> pisi.Error , exception icin de

* boyle yapiliyormus
This commit is contained in:
Eray Özkural
2005-08-10 17:31:36 +00:00
parent a22d97e134
commit 978734100d
+73 -73
View File
@@ -16,105 +16,105 @@ import struct
import pisi import pisi
class ComarError(pisi.PisiError): class ComarError(pisi.PisiError):
pass pass
class ComarIface: class ComarIface:
"""A class for communicating with comard.""" """A class for communicating with comard."""
RESULT = 0 RESULT = 0
FAIL = 1 FAIL = 1
RESULT_START = 2 RESULT_START = 2
RESULT_END = 3 RESULT_END = 3
NOTIFY = 4 NOTIFY = 4
__LOCALIZE = 5 __LOCALIZE = 5
__REGISTER = 6 __REGISTER = 6
__REMOVE = 7 __REMOVE = 7
__CALL = 8 __CALL = 8
def __init__(self): def __init__(self):
try: try:
self.sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) self.sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
self.sock.connect("/tmp/comar") self.sock.connect("/tmp/comar")
except: except:
# should raise an exception here # should raise an exception here
raise ComarError, 'Cannot connect to COMAR daemon' raise ComarError, 'Cannot connect to COMAR daemon'
def __pack(self, cmd, id, args): def __pack(self, cmd, id, args):
size = 0 size = 0
args2 = [] args2 = []
# NOTE: COMAR RPC is using network byte order (big endian) # NOTE: COMAR RPC is using network byte order (big endian)
fmt = "!ii" fmt = "!ii"
for a in args: for a in args:
a = str(a) # damn unicode a = str(a) # damn unicode
fmt += "h%dsB" % (len(a)) fmt += "h%dsB" % (len(a))
size += 2 + len(a) + 1 size += 2 + len(a) + 1
args2.append(len(a)) args2.append(len(a))
args2.append(a.encode("utf-8")) args2.append(a.encode("utf-8"))
args2.append(0) args2.append(0)
pak = struct.pack(fmt, (cmd << 24) | size, id, *args2) pak = struct.pack(fmt, (cmd << 24) | size, id, *args2)
return pak return pak
def read_reply(self): def read_reply(self):
pass pass
def localize(self, localename): def localize(self, localename):
"""Sets the language for translated replies. """Sets the language for translated replies.
Since comard has no way to detect caller's locale, this command Since comard has no way to detect caller's locale, this command
is used for sending user's language to the comard. Afterwards, is used for sending user's language to the comard. Afterwards,
all the jobs started with API calls uses translated messages in all the jobs started with API calls uses translated messages in
their replies. their replies.
You can get the localename parameter from setlocale(NULL) call. You can get the localename parameter from setlocale(NULL) call.
""" """
pass pass
def register(self, classname, packagename, cslfile, id = 0): def register(self, classname, packagename, cslfile, id = 0):
"""Registers a package script on the system model. """Registers a package script on the system model.
""" """
pak = self.__pack(self.__REGISTER, id, pak = self.__pack(self.__REGISTER, id,
[ classname, packagename, cslfile ] [ classname, packagename, cslfile ]
) )
self.sock.send(pak) self.sock.send(pak)
def remove(self, packagename, id = 0): def remove(self, packagename, id = 0):
"""Remove package's all scripts from system. """Remove package's all scripts from system.
""" """
pak = self.__pack(self.__REMOVE, id, [ packagename ]) pak = self.__pack(self.__REMOVE, id, [ packagename ])
self.sock.send(pak) self.sock.send(pak)
def call(self, methodname, args, id = 0): def call(self, methodname, args, id = 0):
"""Makes a configuration call on the system model. """Makes a configuration call on the system model.
""" """
a = [ methodname ] a = [ methodname ]
a.extend(args) a.extend(args)
pak =self.__pack(self.__CALL, id, a) pak =self.__pack(self.__CALL, id, a)
self.sock.send(pak) self.sock.send(pak)
def call_package(self, methodname, packagename, args, id = 0): def call_package(self, methodname, packagename, args, id = 0):
"""Makes a configuration call directed to a package. """Makes a configuration call directed to a package.
""" """
pass pass
def call_instance(self, methodname, packagename, instancename, args, id = 0): def call_instance(self, methodname, packagename, instancename, args, id = 0):
# not yet decided # not yet decided
pass pass
def get_packages(self, classname, id = 0): def get_packages(self, classname, id = 0):
"""Returns registered packages for a given system model class. """Returns registered packages for a given system model class.
""" """
pass pass
def ask_notify(self, notifyname, id = 0): def ask_notify(self, notifyname, id = 0):
"""Asks for a notification event to be delivered. """Asks for a notification event to be delivered.
""" """
pass pass
comard = None comard = None
def init(): def init():
comard = ComarIface() comard = ComarIface()
def finalize(): def finalize():
if comard: if comard:
del comard del comard