[Sugar-devel] [PATCH] Handle missing gst-plugins-espeak gracefully - SL#3345

Anish Mangal anish at activitycentral.com
Tue Apr 24 09:39:39 EDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue 24 Apr 2012 06:55:19 PM IST, godiard at sugarlabs.org wrote:
> From: Gonzalo Odiard <godiard at gmail.com>
>
> The text-to-speech support in Sugar (jarabe.model.speech) depends on
> gst-plugins-espeak [1]. While Sugar continues to work properly in the
> absence of gst-plugins-espeak, loading the corresponding components
> (keyboard shortcut handler and Frame device icon) currently fails hard
> and produces a traceback in the log. However TTS support is entirely
> optional and the traceback suggests an unhandled system failure rather
> than optional support not being available. Fix this by catching the
> exception when accessing the SpeechManager and logging a warning
> instead.
>
> [1] https://wiki.sugarlabs.org/go/Activity_Team/gst-plugins-espeak
>
> Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
> ---
>  extensions/deviceicon/speech.py |    7 +++++--
>  extensions/globalkey/speech.py  |    3 +--
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/extensions/deviceicon/speech.py b/extensions/deviceicon/speech.py
> index 6b8f915..889d509 100644
> --- a/extensions/deviceicon/speech.py
> +++ b/extensions/deviceicon/speech.py
> @@ -14,6 +14,7 @@
>  # along with this program; if not, write to the Free Software
>  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>
> +import logging
>  from gettext import gettext as _
>
>  import glib
> @@ -31,7 +32,6 @@ from sugar.graphics import style
>  from jarabe.frame.frameinvoker import FrameWidgetInvoker
>  from jarabe.model import speech
>
> -
>  _ICON_NAME = 'microphone'
>
>
> @@ -145,4 +145,7 @@ class SpeechPalette(Palette):
>
>
>  def setup(tray):
> -    tray.add_device(SpeechDeviceView())
> +    try:
> +        tray.add_device(SpeechDeviceView())
> +    except:
> +        logging.warning('Text to speech no available. Missing dependencies')

Ideally we shouldn't be just catching generic exceptions like above but
rather specific...

except <SomeException>:

Also, instead of logging.warning, maybe a logging.exception would be
better?

> diff --git a/extensions/globalkey/speech.py b/extensions/globalkey/speech.py
> index 2879b69..e47c778 100644
> --- a/extensions/globalkey/speech.py
> +++ b/extensions/globalkey/speech.py
> @@ -14,10 +14,9 @@
>  # along with this program; if not, write to the Free Software
>  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
>
> -from jarabe.model import speech
> -
>  BOUND_KEYS = ['<alt><shift>s']
>
> +from jarabe.model import speech
>

Why the need to move this import below the const declaration? Its not
that way in other extension modules.

>  def handle_key_press(key):
>      manager = speech.get_speech_manager()

Reviewed-by: Anish Mangal <anish at activitycentral.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPlq0bAAoJEBoxUdDHDZVp65IH/RP2I7PyKFW2+Qbk5Q7veBZf
tdDskQOM8P9cbDJ3jr3pVagsxHb3b8Bnh9mDNhAahSqe7uHbD2uL5D9gJKPu6yez
2JihP99qKmp8+iAKyR3HQpNZ4EY9dKfDQS5qRgVi2OFiPiUnZf6QTKML/rNygqDF
kjLDgBH3M5u3TuUgSGZnvITdkovRaOIAw/qqbWRYOXQyo8UcHZGQP2+9wm/zGpZM
plxYHHq8fvxUMY/eDHiVi/OlilxWx4LcnmJVnMZUB9w4WjvgCVEo548s9tlDiG5x
0Ag/jghHeWYYW3MtLPS2+EQTmd5LsMgxzBgaXJN/U1Z4MIxmJOQ/vvTtZDWXNa8=
=E6aG
-----END PGP SIGNATURE-----



More information about the Sugar-devel mailing list