summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2010-04-14 22:28:19 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2010-04-14 22:28:19 +0200
commit67d927540ee10dbf70b9b71eda152605a63bbc90 (patch)
tree7247e43b1b159439743e6c77edfd4124b9fe63e2 /portato
parent06f03d7aa376c8164eff5068a412e76cf2c0b0a9 (diff)
parente5b5b6793999a5094832b1819cc6b5e5e5f0ca39 (diff)
downloadportato-67d927540ee10dbf70b9b71eda152605a63bbc90.tar.gz
portato-67d927540ee10dbf70b9b71eda152605a63bbc90.tar.bz2
portato-67d927540ee10dbf70b9b71eda152605a63bbc90.zip
Merge branch '0.14'
* 0.14: Make some useless info messages being debug statements Improve the C modules Small modifications made to the French translation (typos, grammar). Fixed the unicode support and stuff ... and also made eix faster :) Disable debug messages by default Better eix error inheritance and handling
Diffstat (limited to 'portato')
-rw-r--r--portato/eix/exceptions.py11
-rw-r--r--portato/eix/parser.pyx78
-rw-r--r--portato/ipc.pxd3
-rw-r--r--portato/ipc.pyx36
-rw-r--r--portato/plugin.py6
5 files changed, 79 insertions, 55 deletions
diff --git a/portato/eix/exceptions.py b/portato/eix/exceptions.py
index 95283ac..955da42 100644
--- a/portato/eix/exceptions.py
+++ b/portato/eix/exceptions.py
@@ -23,7 +23,14 @@ class EixError (Exception):
:ivar message: The error message
"""
+
message = _("Unknown error.")
+
+ def __init__ (self, msg = None):
+ Exception.__init__(self)
+
+ if msg:
+ self.message = msg
def __str__ (self):
return self.message
@@ -34,7 +41,7 @@ class EndOfFileException (EixError):
"""
def __init__ (self, filename):
- self.message = _("End of file reached though it was not expected: '%s'") % filename
+ EixError.__init__(self, _("End of file reached though it was not expected: '%s'") % filename)
class UnsupportedVersionError (EixError):
"""
@@ -42,4 +49,4 @@ class UnsupportedVersionError (EixError):
"""
def __init__ (self, version):
- self.message = _("Version '%s' is not supported.") % version
+ EixError.__init__(self, _("Version '%s' is not supported.") % version)
diff --git a/portato/eix/parser.pyx b/portato/eix/parser.pyx
index 6363b37..a6bcc96 100644
--- a/portato/eix/parser.pyx
+++ b/portato/eix/parser.pyx
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# File: portato/eix/_parser.pyx
+# File: portato/eix/parser.pyx
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2006-2010 René 'Necoro' Neumann
@@ -20,12 +20,12 @@ For the exact way all the functions work, have a look at the eix format descript
__docformat__ = "restructuredtext"
cdef extern from "stdio.h":
- ctypedef struct FILE:
- pass
+ ctypedef struct FILE
int fgetc(FILE* stream)
long ftell(FILE* stream)
int fseek(FILE* stream, long offset, int whence)
+ int fread(void* ptr, int size, int n, FILE* stream)
int EOF
int SEEK_CUR
@@ -36,6 +36,11 @@ cdef extern from "Python.h":
ctypedef unsigned char UChar
ctypedef long long LLong
+from python_unicode cimport PyUnicode_DecodeUTF8
+from python_mem cimport PyMem_Malloc, PyMem_Free
+from python_exc cimport PyErr_NoMemory
+from python_string cimport PyString_FromStringAndSize
+
from portato.eix.exceptions import EndOfFileException
#
@@ -54,7 +59,15 @@ cdef int _get_byte (FILE* file) except -1:
# Base Types
#
-cdef LLong _number (object pfile):
+cpdef LLong number (object pfile):
+ """
+ Returns a number.
+
+ :param file: The file to read from
+ :type file: file
+ :rtype: int
+ """
+
cdef UChar n
cdef LLong value
cdef int i
@@ -84,18 +97,7 @@ cdef LLong _number (object pfile):
return value
-def number (file):
- """
- Returns a number.
-
- :param file: The file to read from
- :type file: file
- :rtype: int
- """
-
- return _number(file)
-
-def vector (file, get_type, nelems = None):
+cpdef object vector (object file, object get_type, object nelems = None):
"""
Returns a vector of elements.
@@ -118,28 +120,44 @@ def vector (file, get_type, nelems = None):
cdef LLong i
if nelems is None:
- n = _number(file)
+ n = number(file)
else:
n = nelems
return [get_type(file) for i in range(n)]
-def string (file):
+cpdef object string (object pfile, bint unicode = False):
"""
Returns a string.
- :param file: The file to read from
- :type file: file
- :rtype: str
+ :param pfile: The file to read from
+ :type pfile: file
+ :param unicode: Return unicode
+ :type unicode: bool
+ :rtype: str or unicode
"""
- nelems = _number(file)
+ cdef LLong nelems = number(pfile)
+ cdef FILE* file = PyFile_AsFile(pfile)
+ cdef char* s
+
+ s = <char*>PyMem_Malloc((nelems + 1) * sizeof(char))
+
+ if s is NULL:
+ PyErr_NoMemory()
+
+ try:
+ if fread(s, sizeof(char), nelems, file) < nelems:
+ raise EndOfFileException, pfile.name
- s = file.read(nelems)
+ s[nelems] = '\0'
- if len(s) != nelems:
- raise EndOfFileException, file.name
+ if unicode:
+ return PyUnicode_DecodeUTF8(s, nelems, 'replace')
+ else: # simple string, implicitly copied
+ return PyString_FromStringAndSize(s, nelems)
- return s
+ finally:
+ PyMem_Free(s)
#
# Complex Types
@@ -220,8 +238,8 @@ cdef class header:
:param file: The file to read from
:type file: file
"""
- self.version = _number(file)
- self.ncats = _number(file)
+ self.version = number(file)
+ self.ncats = number(file)
self.overlays = vector(file, overlay)
self.provide = vector(file, string)
self.licenses = vector(file, string)
@@ -274,12 +292,12 @@ cdef class package:
cdef FILE* cfile = PyFile_AsFile(file)
cdef long after_offset
- self._offset = _number(file)
+ self._offset = number(file)
after_offset = ftell(cfile)
self.name = string(file)
- self.description = unicode(string(file))
+ self.description = string(file, True)
# skip the rest, as it is currently unneeded
#self.provide = vector(file, number)
diff --git a/portato/ipc.pxd b/portato/ipc.pxd
index 38e6d30..5bcddd1 100644
--- a/portato/ipc.pxd
+++ b/portato/ipc.pxd
@@ -11,7 +11,8 @@
# Written by René 'Necoro' Neumann <necoro@necoro.net>
from python_string cimport *
-from python_mem cimport *
+from python_mem cimport PyMem_Malloc, PyMem_Free
+from python_exc cimport PyErr_NoMemory
cdef extern from "errno.h":
int errno
diff --git a/portato/ipc.pyx b/portato/ipc.pyx
index abb26fe..7dcf949 100644
--- a/portato/ipc.pyx
+++ b/portato/ipc.pyx
@@ -70,7 +70,7 @@ cdef class MessageQueue (object):
elif errno == ENOENT:
raise MessageQueueError("Queue does not exist and 'create' is not set.")
elif errno == ENOMEM or errno == ENOSPC:
- raise MemoryError("Insufficient ressources.")
+ PyErr_NoMemory()
else:
raise OSError(errno, strerror(errno))
@@ -111,7 +111,7 @@ cdef class MessageQueue (object):
msg = <msg_data*>PyMem_Malloc(sizeof(msg_data) + size)
if msg is NULL:
- raise MemoryError("Out of memory")
+ PyErr_NoMemory()
memcpy(msg.mtext, <char*>message, size)
msg.mtype = type
@@ -119,18 +119,17 @@ cdef class MessageQueue (object):
with nogil:
ret = msgsnd(self.msgid, msg, size, 0)
- try:
- if ret == -1:
- if errno == EIDRM or errno == EINVAL:
- raise MessageQueueRemovedError("Queue was removed.")
- elif errno == EINTR:
- raise MessageQueueError("Signaled while waiting.")
- elif errno == EACCES:
- raise MessageQueueError("Permission denied.")
- else:
- raise OSError(errno, strerror(errno))
- finally:
- PyMem_Free(msg)
+ PyMem_Free(msg)
+
+ if ret == -1:
+ if errno == EIDRM or errno == EINVAL:
+ raise MessageQueueRemovedError("Queue was removed.")
+ elif errno == EINTR:
+ raise MessageQueueError("Signaled while waiting.")
+ elif errno == EACCES:
+ raise MessageQueueError("Permission denied.")
+ else:
+ raise OSError(errno, strerror(errno))
def receive (self):
"""
@@ -145,7 +144,7 @@ cdef class MessageQueue (object):
msg = <msg_data*>PyMem_Malloc(sizeof(msg_data) + MAX_MESSAGE_SIZE)
if msg is NULL:
- raise MemoryError("Out of memory")
+ PyErr_NoMemory()
msg.mtype = 0
@@ -162,12 +161,11 @@ cdef class MessageQueue (object):
raise MessageQueueError("Permission denied.")
else:
raise OSError(errno, strerror(errno))
-
- retTuple = (PyString_FromStringAndSize(msg.mtext, ret), msg.mtype)
+ else:
+ return (PyString_FromStringAndSize(msg.mtext, ret), msg.mtype)
+
finally:
PyMem_Free(msg)
- return retTuple
-
cdef inline key_t random_key (self):
return <int>(<double>rand() / (<double>RAND_MAX + 1) * INT_MAX)
diff --git a/portato/plugin.py b/portato/plugin.py
index cfe3d93..f510540 100644
--- a/portato/plugin.py
+++ b/portato/plugin.py
@@ -461,7 +461,7 @@ class PluginQueue (object):
else:
for w in p.widgets:
WidgetSlot.slots[w.slot].add_widget(w)
- info(_("Widgets of plugin '%s' loaded."), p.name)
+ debug("Widgets of plugin '%s' loaded.", p.name)
def add (self, plugin, disable = False):
"""
@@ -538,7 +538,7 @@ class PluginQueue (object):
call.call(*hargs, **hkwargs)
if active.override: # override
- info(_("Overriding hook '%(hook)s' with plugin '%(plugin)s'."), {"hook": hook, "plugin": active.override.plugin.name})
+ debug("Overriding hook '%(hook)s' with plugin '%(plugin)s'.", {"hook": hook, "plugin": active.override.plugin.name})
ret = active.override.call(*hargs, **hkwargs)
else: # normal
ret = func(*args, **kwargs)
@@ -630,7 +630,7 @@ class PluginQueue (object):
for l in list:
callList.append(l)
- info(_("Dependant '%(dep)s' for '%(hook)s' in plugin '%(plugin)s' not found! Adding nevertheless."), {"hook": hook, "plugin": l.plugin.name, "dep": l.dep})
+ debug("Dependant '%(dep)s' for '%(hook)s' in plugin '%(plugin)s' not found! Adding nevertheless.", {"hook": hook, "plugin": l.plugin.name, "dep": l.dep})
for hook in before:
resolve(hook, before[hook], "before", 0)