diff options
author | Sascha Silbe <silbe@activitycentral.com> | 2011-03-03 12:45:43 (GMT) |
---|---|---|
committer | James Cameron <quozl@laptop.org> | 2011-03-03 22:35:57 (GMT) |
commit | 1aa9ba3abb5f30fcc223e0c46079e93a6ee78cf6 (patch) | |
tree | 762484659b0529e1dfbe333fcd80b13ea1597ad4 /library | |
parent | 1bf27049195dcf5a6816704d8c195f9a99e792fc (diff) |
Fix Pippy sound library on non-OLPC OS systems (SL#638)v40
Replace the hardcoded paths with corresponding lookups and raise an
exception if the TamTamEdit sound library cannot be found.
Inspired by patches from Julie Pichon <julie.pichon@gmail.com>.
Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
Acked-by: James Cameron <quozl@laptop.org>
Diffstat (limited to 'library')
-rwxr-xr-x | library/pippy/sound.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/library/pippy/sound.py b/library/pippy/sound.py index c5f864d..283b259 100755 --- a/library/pippy/sound.py +++ b/library/pippy/sound.py @@ -14,12 +14,20 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import errno import os import sys from gettext import gettext as _ -dirs = ['/usr/share/activities/TamTamEdit.activity/common/Resources/Sounds/', - '/home/olpc/Activities/TamTamEdit.activity/common/Resources/Sounds/'] +import sugar.env + + +tamtam_subdir = '/TamTamEdit.activity/common/Resources/Sounds/' +sound_candidate_dirs = [ + os.path.expandvars('$SUGAR_PATH/activities') + tamtam_subdir, + sugar.env.get_user_activities_path() + tamtam_subdir, +] + orchlines = [] scorelines = [] instrlist = [] @@ -34,10 +42,18 @@ def quit(self): """ +class SoundLibraryNotFoundError(Exception): + def __init__(self): + Exception.__init__(self, _('Cannot find TamTamEdit sound library.' + ' Did you install TamTamEdit?')) + + def finddir(): - for d in dirs: - if os.path.isdir(d): - return d + for directory in sound_candidate_dirs: + if os.path.isdir(directory): + return directory + + raise SoundLibraryNotFoundError() def defAdsr(attack=0.01, decay=0.1, sustain=0.8, release=0.1): @@ -290,11 +306,7 @@ def playWave(sound='horse', pitch=1, amplitude=1, loop=False, duration=1, def getSoundList(): - list = finddir() - if list == None: - print _("Please install TamTamEdit's sound library.") - sys.exit(0) - return sorted(os.listdir(list)) + return sorted(os.listdir(finddir())) temp_path = None |