X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/python-afs.git/blobdiff_plain/2592f714b7bf436892c330063f8ae197b4662d0b..dee660f2c4164dbe8862e0158494dbfe966b8c43:/afs/afs.pyx diff --git a/afs/afs.pyx b/afs/afs.pyx index a54a1c9..77456b4 100644 --- a/afs/afs.pyx +++ b/afs/afs.pyx @@ -4,21 +4,38 @@ General PyAFS utilities, such as error handling import sys +# otherwise certain headers are unhappy +cdef import from "netinet/in.h": pass +cdef import from "afs/vice.h": pass + cdef int _init = 0 +# pioctl convenience wrappers + +cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, afs_int32 follow) except -1: + cdef ViceIoctl blob + cdef afs_int32 code + blob.in_size = 0 + blob.out_size = size + blob.out = buffer + code = pioctl(dir, op, &blob, follow) + pyafs_error(code) + return code + +# Error handling + class AFSException(Exception): - def __init__(self, errno, message): + def __init__(self, errno): self.errno = errno self.strerror = afs_error_message(errno) - self.message = message def __repr__(self): - return "AFSException(%s, %s)" % (self.errno, self.message) + return "AFSException(%s)" % (self.errno) def __str__(self): - return "[%s] (%s) while %s" % (self.errno, self.strerror, self.message) + return "[%s] %s" % (self.errno, self.strerror) -def pyafs_error(code, msg): +def pyafs_error(code): if not _init: initialize_ACFG_error_table() initialize_KTC_error_table() @@ -29,4 +46,4 @@ def pyafs_error(code, msg): _init = 1 if code != 0: - raise AFSException(code, msg) + raise AFSException(code)