source: trunk/packages/python-afs/afs/_util.pyx @ 2693

Last change on this file since 2693 was 2599, checked in by broder, 15 years ago

Import python-afs.

Debathena should eventually be importing PyAFS for
<http://debathena.mit.edu/trac/ticket/395>, so hopefully this is only
temporary.

File size: 1.8 KB
Line 
1"""
2General PyAFS utilities, such as error handling
3"""
4
5import sys
6
7# otherwise certain headers are unhappy
8cdef extern from "netinet/in.h": pass
9cdef extern from "afs/vice.h": pass
10
11cdef int _init = 0
12
13# pioctl convenience wrappers
14
15cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, afs_int32 follow) except -1:
16    cdef ViceIoctl blob
17    cdef afs_int32 code
18    blob.in_size  = 0
19    blob.out_size = size
20    blob.out = buffer
21    code = pioctl(dir, op, &blob, follow)
22    # This might work with the rest of OpenAFS, but I'm not convinced
23    # the rest of it is consistent
24    if code == -1:
25        raise OSError(errno, strerror(errno))
26    pyafs_error(code)
27    return code
28
29cdef extern int pioctl_write(char *dir, afs_int32 op, char *buffer, afs_int32 follow) except -1:
30    cdef ViceIoctl blob
31    cdef afs_int32 code
32    blob.cin = buffer
33    blob.in_size = 1 + strlen(buffer)
34    blob.out_size = 0
35    code = pioctl(dir, op, &blob, follow)
36    # This might work with the rest of OpenAFS, but I'm not convinced
37    # the rest of it is consistent
38    if code == -1:
39        raise OSError(errno, strerror(errno))
40    pyafs_error(code)
41    return code
42
43# Error handling
44
45class AFSException(Exception):
46    def __init__(self, errno):
47        self.errno = errno
48        self.strerror = afs_error_message(errno)
49
50    def __repr__(self):
51        return "AFSException(%s)" % (self.errno)
52
53    def __str__(self):
54        return "[%s] %s" % (self.errno, self.strerror)
55
56def pyafs_error(code):
57    if not _init:
58        initialize_ACFG_error_table()
59        initialize_KTC_error_table()
60        initialize_PT_error_table()
61        initialize_RXK_error_table()
62        initialize_U_error_table()
63
64        _init = 1
65
66    if code != 0:
67        raise AFSException(code)
Note: See TracBrowser for help on using the repository browser.