diff --git a/0001-Do-not-use-the-exceptions-module.patch b/0001-Do-not-use-the-exceptions-module.patch new file mode 100644 index 0000000..e999c59 --- /dev/null +++ b/0001-Do-not-use-the-exceptions-module.patch @@ -0,0 +1,54 @@ +From 2023730c6ece6edf6ddb8f73d80409230fc06089 Mon Sep 17 00:00:00 2001 +From: Mathieu Bridon +Date: Wed, 28 Nov 2012 23:44:39 +0800 +Subject: [PATCH 1/2] Do not use the exceptions module + +On Python 2, it is imported automatically, so there really isn't any +need to import it, it's classes can be used directly: + $ python2 + >>> e = Exception() + >>> import exceptions + >>> isinstance(e, exceptions.Exception) + True + +Also, it doesn't exist on Python 3, so removing it will make the port +easier. +--- + pycanberra.py | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/pycanberra.py b/pycanberra.py +index 6b1a064..a1bae5d 100644 +--- a/pycanberra.py ++++ b/pycanberra.py +@@ -4,7 +4,6 @@ + # License: LGPL 2.1 + ########################################################################## + from ctypes import * +-import exceptions + import time + + # /** +@@ -519,16 +518,16 @@ def GetApi(): + # int ca_proplist_set(ca_proplist *p, const char *key, const void *data, size_t nbytes); + + +-class CanberraException(exceptions.Exception): ++class CanberraException(Exception): + def __init__(self, err, *args, **kwargs): + self._err = err +- super(exceptions.Exception, self).__init__(*args, **kwargs) ++ super(Exception, self).__init__(*args, **kwargs) + + def get_error(self): + return self._err + + def __str__(self): +- return super(exceptions.Exception, self).__str__() + " (error %d)" % self._err ++ return super(Exception, self).__str__() + " (error %d)" % self._err + + + class Canberra(object): +-- +1.8.1 + diff --git a/0002-Ensure-all-strings-passed-to-libcanberra-are-byte-st.patch b/0002-Ensure-all-strings-passed-to-libcanberra-are-byte-st.patch new file mode 100644 index 0000000..74348da --- /dev/null +++ b/0002-Ensure-all-strings-passed-to-libcanberra-are-byte-st.patch @@ -0,0 +1,78 @@ +From e1104818d795bde79e203ba750ce37fbba9a8e90 Mon Sep 17 00:00:00 2001 +From: Mathieu Bridon +Date: Wed, 2 Jan 2013 19:26:23 +0800 +Subject: [PATCH 2/2] Ensure all strings passed to libcanberra are byte strings + +We need to pass byte strings to libcanberra, which is default with +Python 2 when defining a string as "foo". + +However, on Python 3, the same definition gives a unicode string, which +libcanberra can't handle. + +To avoid forcing applications to change the way they called pycanberra +on Python 2, pycanberra now quickly ensures that all strings it handles +are encoded to bytes, if they weren't already. +--- + pycanberra.py | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/pycanberra.py b/pycanberra.py +index a1bae5d..0d219ba 100644 +--- a/pycanberra.py ++++ b/pycanberra.py +@@ -6,6 +6,18 @@ + from ctypes import * + import time + ++# This is inspired by the six module: http://pypi.python.org/pypi/six ++import sys ++if sys.version_info.major == 3: ++ string_types = str, ++ def b(s): ++ return s.encode("latin-1") ++else: ++ string_types = basestring, ++ def b(s): ++ return s ++ ++ + # /** + # * CA_PROP_MEDIA_NAME: + # * +@@ -556,6 +568,8 @@ class Canberra(object): + raise CanberraException(res, "Failed to destroy context") + + def change_props(self, *args): ++ args = tuple(b(arg) if isinstance(arg, string_types) else arg ++ for arg in args) + res = GetApi().ca_context_change_props(self._handle, *args) + if res != CA_SUCCESS: + raise CanberraException(res, "Failed to change props") +@@ -573,11 +587,15 @@ class Canberra(object): + pass + + def play(self, playId, *args): ++ args = tuple(b(arg) if isinstance(arg, string_types) else arg ++ for arg in args) + res = GetApi().ca_context_play(self._handle, playId, *args) + if res != CA_SUCCESS: + raise CanberraException(res, "Failed to play!") + + def cache(self, *args): ++ args = tuple(b(arg) if isinstance(arg, string_types) else arg ++ for arg in args) + res = GetApi().ca_context_cache(self._handle, *args) + if res != CA_SUCCESS: + raise CanberraException(res, "Failed to cache") +@@ -596,6 +614,8 @@ class Canberra(object): + + def easy_play_sync(self, eventName): + """ play an event sound synchronously """ ++ if isinstance(eventName, string_types): ++ eventName = b(eventName) + self.play(1, + CA_PROP_EVENT_ID, eventName, + None) +-- +1.8.1 + diff --git a/pycanberra.spec b/pycanberra.spec index c4604f0..58a46ec 100644 --- a/pycanberra.spec +++ b/pycanberra.spec @@ -6,7 +6,7 @@ License: LGPLv2 # There's no versioning upstream, it's all about the Git hash Version: 0 -Release: 0.2.git%{git_hash}%{?dist} +Release: 0.3.git%{git_hash}%{?dist} URL: https://github.com/psykoyiko/pycanberra/ @@ -17,22 +17,38 @@ URL: https://github.com/psykoyiko/pycanberra/ # $ git archive --prefix=pycanberra-$GIT_HASH/ --format=tar HEAD | xz > pycanberra-git.$GIT_HASH.tar.xz Source0: %{name}-git.%{git_hash}.tar.xz +# I submitted these patches upstream, but they haven't been accepted yet +# https://github.com/psykoyiko/pycanberra/pull/2 +# I'm pulling them in the package because other packages need pycanberra with +# Python 3 (e.g gnome-clocks) +Patch0: 0001-Do-not-use-the-exceptions-module.patch +Patch1: 0002-Ensure-all-strings-passed-to-libcanberra-are-byte-st.patch + BuildArch: noarch BuildRequires: python2-devel +BuildRequires: python3-devel # This will break at run time when libcanberra bumps its soname :( Requires: libcanberra %description -A very basic (and incomplete) wrapper for libcanberra. +A very basic (and incomplete) wrapper of libcanberra for Python 2. + -This is necessary until libcanberra gets proper GObject Introspection support. +%package -n python3-canberra +Summary: A very basic (and incomplete) wrapper for libcanberra + +%description -n python3-canberra +A very basic (and incomplete) wrapper of libcanberra for Python 3. %prep %setup -q -n pycanberra-%{git_hash} +%patch0 -p1 +%patch1 -p1 + %build # Nothing to build @@ -42,13 +58,25 @@ This is necessary until libcanberra gets proper GObject Introspection support. install -d %{buildroot}%{python_sitelib} install -p -m 0644 pycanberra.py %{buildroot}%{python_sitelib} +install -d %{buildroot}%{python3_sitelib} +install -p -m 0644 pycanberra.py %{buildroot}%{python3_sitelib} + %files %doc COPYING README %{python_sitelib}/pycanberra.py* +%files -n python3-canberra +%doc COPYING README +%{python3_sitelib}/pycanberra.py +%{python3_sitelib}/__pycache__/pycanberra.cpython-33.py? + + %changelog +* Wed Feb 06 2013 Mathieu Bridon - 0-0.3.git65c3b3f +- Add a python3 subpackage. + * Tue Oct 02 2012 Mathieu Bridon - 0-0.2.git65c3b3f - Fix requirement on libcanberra.