From e10334539d6b6c8c01d5936aa68e1b4b42f85963 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sun, 26 Jul 2009 03:23:31 +0200 Subject: Add libeix to setup.py --- setup.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index f5f77fb..7276b92 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,10 @@ import os from distutils.core import setup + +from Cython.Distutils.extension import Extension +from Cython.Distutils import build_ext + from portato.constants import VERSION, ICON_DIR, PLUGIN_DIR, TEMPLATE_DIR, APP from build_manpage import build_manpage @@ -21,12 +25,14 @@ def plugin_list (*args): """Creates a list of correct plugin pathes out of the arguments.""" return [("plugins/%s.py" % x) for x in args] -packages = ["portato", "portato.db", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage"] +packages = ["portato", "portato.db", "portato.eix", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage"] data_files = [ (TEMPLATE_DIR, [os.path.join("portato/gui/templates",x) for x in os.listdir("portato/gui/templates") if x.endswith(".ui")]), (ICON_DIR, ["icons/portato-icon.png"]), (PLUGIN_DIR, plugin_list("gpytage", "notify", "etc_proposals", "reload_portage", "package_details"))] +libeix = Extension("portato.eix.libeix", ["portato/eix/libeix.pyx"]) + # do the distutils setup setup(name=APP, version = VERSION, @@ -38,6 +44,7 @@ setup(name=APP, author = "René 'Necoro' Neumann", author_email = "necoro@necoro.net", packages = packages, + ext_modules = [libeix], data_files = data_files, - cmdclass={'build_manpage': build_manpage} + cmdclass={'build_manpage': build_manpage, 'build_ext' : build_ext} ) -- cgit v1.2.3-54-g00ecf From 40344af86dbe9c7ad2f38b18f31f0f8a4917bda9 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Mon, 27 Jul 2009 00:38:41 +0200 Subject: Moved from Cython to normal Python --- portato/eix.py | 113 ++++++++++++++++++++++++++++++++++++++++++++++ portato/eix/__init__.py | 0 portato/eix/eix_utils.pxd | 17 ------- portato/eix/eix_utils.pyx | 15 ------ portato/eix/libeix.pyx | 102 ----------------------------------------- setup.py | 10 +--- 6 files changed, 115 insertions(+), 142 deletions(-) create mode 100644 portato/eix.py delete mode 100644 portato/eix/__init__.py delete mode 100644 portato/eix/eix_utils.pxd delete mode 100644 portato/eix/eix_utils.pyx delete mode 100644 portato/eix/libeix.pyx (limited to 'setup.py') diff --git a/portato/eix.py b/portato/eix.py new file mode 100644 index 0000000..927870e --- /dev/null +++ b/portato/eix.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# +# File: portato/eix.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2006-2009 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by René 'Necoro' Neumann + +from __future__ import absolute_import, with_statement + +import struct +from functools import wraps + +from .helper import debug + +class EixError (Exception): + message = "Unknown error." + + def __str__ (self): + return self.message + +class EndOfFileException (EixError): + + def __init__ (self, filename): + self.message = "End of file reached though it was not expected: '%s'" % filename + +class EixReaderClosed (EixError): + message = "EixReader is already closed." + +class UnsupportedVersionError (EixError): + + def __init__ (self, version): + self.message = "Version '%s' is not supported." % version + +class EixReader (object): + supported_versions = (28, ) + + def __init__ (self, filename): + self.filename = filename + self.file = open(filename, "r") + self.closed = 0 + + try: + self.version = self.get_number() + + if self.version not in self.supported_versions: + raise UnsupportedVersionError(self.version) + + debug("Started EixReader for version %s.", self.version) + except: + self.close() + raise + + def check_closed (f): + @wraps(f) + def wrapper (self, *args, **kwargs): + if self.closed: + raise EixReaderClosed + + return f(self, *args, **kwargs) + return wrapper + + @check_closed + def get_number (self): + n = self._get_bytes(1) + + if n < 0xFF: + value = n + else: + count = 0 + + while (n == 0xFF): + count += 1 + n = self._get_bytes(1) + + if n == 0: + n = 0xFF # 0xFF is encoded as 0xFF 0x00 + count -= 1 + + value = n << (count*8) + + if count > 0: + rest = self._get_bytes(count, expect_list = True) + + for i, r in enumerate(rest): + value += r << ((count - i - 1)*8) + + return value + + def _get_bytes (self, length, expect_list = False): + s = self.file.read(length) + + if len(s) != length: + raise EndOfFileException, self.filename + + if length == 1 and not expect_list: + return ord(s) # is faster than unpack and we have a scalar + else: + return struct.unpack("%sB" % length, s) + + @check_closed + def close (self): + if self.closed: + raise EixReaderClosed + + self.file.close() + self.closed = 1 + + debug("EixReader closed.") diff --git a/portato/eix/__init__.py b/portato/eix/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/portato/eix/eix_utils.pxd b/portato/eix/eix_utils.pxd deleted file mode 100644 index 39f60a9..0000000 --- a/portato/eix/eix_utils.pxd +++ /dev/null @@ -1,17 +0,0 @@ -cdef extern from *: - ctypedef int size_t - -cdef extern from "errno.h": - int errno - -cdef extern from "string.h": - char* strerror (int errno) - size_t strlen (char* s) - char* strcpy (char* dest, char* src) - -cdef extern from "Python.h": - void* PyMem_Malloc (size_t n) - void PyMem_Free (void* p) - -cdef: - char* strdup (char* other) except NULL diff --git a/portato/eix/eix_utils.pyx b/portato/eix/eix_utils.pyx deleted file mode 100644 index 0ea9603..0000000 --- a/portato/eix/eix_utils.pyx +++ /dev/null @@ -1,15 +0,0 @@ -cdef char* strdup (char * other) except NULL: - cdef size_t len - cdef char* new - - if other is NULL: - return NULL - - len = strlen(other) - new = PyMem_Malloc(len+1) - - if new is NULL: - raise MemoryError, "Malloc of new string copy" - return NULL - - return strcpy(new, other) diff --git a/portato/eix/libeix.pyx b/portato/eix/libeix.pyx deleted file mode 100644 index 2a1c7df..0000000 --- a/portato/eix/libeix.pyx +++ /dev/null @@ -1,102 +0,0 @@ -class EixError (Exception): - message = "Unknown error." - - def __str__ (self): - return self.message - -class EndOfFileException (EixError): - - def __init__ (self, filename): - self.message = "End of file reached though it was not expected: '%s'" % filename - -class EixReaderClosed (EixError): - message = "EixReader is already closed." - -class UnsupportedVersionError (EixError): - - def __init__ (self, version): - self.message = "Version '%s' is not supported." % version - -cdef class EixReader (object): - cdef object file - cdef char closed - - cdef readonly object filename - cdef readonly object version - - supported_versions = (28, ) - - def __init__ (self, filename): - self.filename = filename - self.file = open(filename, "r") - self.closed = 0 - - self.version = self._get_number() - - if self.version not in self.supported_versions: - raise UnsupportedVersionError(self.version) - - cdef unsigned long _get_number (self) except *: - cdef unsigned char n - cdef short count, i - cdef unsigned long value - cdef char* rest - cdef object orest - - n = self._get_one_byte() - - if n < 0xFF: - value = n - else: - count = 0 - - while (n == 0xFF): - count += 1 - n = self._get_one_byte() - - if n == 0: - n = 0xFF # 0xFF is encoded as 0xFF 0x00 - count -= 1 - - value = n << (count*8) - - if count > 0: - orest = self.get_string(count) - rest = orest # cast to char* - - for 0 <= i < count: - value += (rest[i]) << ((count - i - 1)*8) - - return value - - cdef unsigned char _get_one_byte (self) except? 0: - s = self.file.read(1) - - if len(s) != 1: - raise EndOfFileException, self.filename - - return ord(s) - - cdef object _get_string (self, length): - if self.closed: - raise EixReaderClosed - - s = self.file.read(length) - - if len(s) != length: - raise EndOfFileException, self.filename - - return s - - def get_number (self): - if self.closed: - raise EixReaderClosed - - return self._get_number() - - def close (self): - if self.closed: - raise EixReaderClosed - - self.file.close() - self.closed = 1 diff --git a/setup.py b/setup.py index 7276b92..f69d373 100644 --- a/setup.py +++ b/setup.py @@ -14,9 +14,6 @@ import os from distutils.core import setup -from Cython.Distutils.extension import Extension -from Cython.Distutils import build_ext - from portato.constants import VERSION, ICON_DIR, PLUGIN_DIR, TEMPLATE_DIR, APP from build_manpage import build_manpage @@ -25,14 +22,12 @@ def plugin_list (*args): """Creates a list of correct plugin pathes out of the arguments.""" return [("plugins/%s.py" % x) for x in args] -packages = ["portato", "portato.db", "portato.eix", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage"] +packages = ["portato", "portato.db", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage"] data_files = [ (TEMPLATE_DIR, [os.path.join("portato/gui/templates",x) for x in os.listdir("portato/gui/templates") if x.endswith(".ui")]), (ICON_DIR, ["icons/portato-icon.png"]), (PLUGIN_DIR, plugin_list("gpytage", "notify", "etc_proposals", "reload_portage", "package_details"))] -libeix = Extension("portato.eix.libeix", ["portato/eix/libeix.pyx"]) - # do the distutils setup setup(name=APP, version = VERSION, @@ -44,7 +39,6 @@ setup(name=APP, author = "René 'Necoro' Neumann", author_email = "necoro@necoro.net", packages = packages, - ext_modules = [libeix], data_files = data_files, - cmdclass={'build_manpage': build_manpage, 'build_ext' : build_ext} + cmdclass={'build_manpage': build_manpage} ) -- cgit v1.2.3-54-g00ecf From 18edc07bf7735c0d72d1b9e69c1e566ebfa1c0c3 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 14 Aug 2009 23:09:00 +0200 Subject: Correct setup.py --- setup.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index f69d373..792e8e6 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,8 @@ import os from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext from portato.constants import VERSION, ICON_DIR, PLUGIN_DIR, TEMPLATE_DIR, APP @@ -22,12 +24,24 @@ def plugin_list (*args): """Creates a list of correct plugin pathes out of the arguments.""" return [("plugins/%s.py" % x) for x in args] -packages = ["portato", "portato.db", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage"] +packages = [ + "portato", + "portato.db", + "portato.eix", + "portato.gui", "portato.gui.windows", + "portato.plugins", + "portato.backend", "portato.backend.portage" + ] + data_files = [ (TEMPLATE_DIR, [os.path.join("portato/gui/templates",x) for x in os.listdir("portato/gui/templates") if x.endswith(".ui")]), (ICON_DIR, ["icons/portato-icon.png"]), (PLUGIN_DIR, plugin_list("gpytage", "notify", "etc_proposals", "reload_portage", "package_details"))] +ext_modules = [ + Extension("portato.eix.parser", ["portato/eix/parser.pyx"]) + ] + # do the distutils setup setup(name=APP, version = VERSION, @@ -40,5 +54,6 @@ setup(name=APP, author_email = "necoro@necoro.net", packages = packages, data_files = data_files, - cmdclass={'build_manpage': build_manpage} + cmdclass={'build_manpage': build_manpage, 'build_ext' : build_ext}, + ext_modules = ext_modules ) -- cgit v1.2.3-54-g00ecf From cf0bb490641f5cc082a83ecd43854c6905fdb02e Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 14 Aug 2009 23:55:52 +0200 Subject: Allow to disable eix in setup.py --- setup.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 792e8e6..e255fd9 100644 --- a/setup.py +++ b/setup.py @@ -12,9 +12,9 @@ # Written by René 'Necoro' Neumann import os +import sys + from distutils.core import setup -from distutils.extension import Extension -from Cython.Distutils import build_ext from portato.constants import VERSION, ICON_DIR, PLUGIN_DIR, TEMPLATE_DIR, APP @@ -27,7 +27,6 @@ def plugin_list (*args): packages = [ "portato", "portato.db", - "portato.eix", "portato.gui", "portato.gui.windows", "portato.plugins", "portato.backend", "portato.backend.portage" @@ -38,9 +37,19 @@ data_files = [ (ICON_DIR, ["icons/portato-icon.png"]), (PLUGIN_DIR, plugin_list("gpytage", "notify", "etc_proposals", "reload_portage", "package_details"))] -ext_modules = [ - Extension("portato.eix.parser", ["portato/eix/parser.pyx"]) - ] +# extension stuff +ext_modules = [] +cmdclass={'build_manpage': build_manpage} + +if "--disable-eix" in sys.argv: + sys.argv.remove("--disable-eix") +else: + from Cython.Distutils import build_ext + from distutils.extension import Extension + + ext_modules.append(Extension("portato.eix.parser", ["portato/eix/parser.pyx"])) + cmdclass['build_ext'] = build_ext + packages.append("portato.eix") # do the distutils setup setup(name=APP, @@ -54,6 +63,6 @@ setup(name=APP, author_email = "necoro@necoro.net", packages = packages, data_files = data_files, - cmdclass={'build_manpage': build_manpage, 'build_ext' : build_ext}, - ext_modules = ext_modules + ext_modules = ext_modules, + cmdclass = cmdclass ) -- cgit v1.2.3-54-g00ecf