From f67a1150e9f23c8b23e83b10cc97b2a43d59215f Mon Sep 17 00:00:00 2001 From: Antoine van Gelder Date: Tue, 30 Oct 2007 20:45:00 +0000 Subject: * Feature: If no sound set, play default sound: laugh_attack.au * Fixed: Activity icon now adopts users color scheme * Fixed: Temp directory now rooted off activity.get_activity_root() * Fixed: Moved locale/ dir back to po/ * Fixed: Temp filenames now created using more secure tempfile.mkstemp() * i18n: Changed pot files to utf-8 --- (limited to 'globals.py') diff --git a/globals.py b/globals.py index 5cadaeb..0a6d2e6 100644 --- a/globals.py +++ b/globals.py @@ -16,6 +16,7 @@ import os import logging +import tempfile from sugar.activity import activity try: from hashlib import sha1 @@ -32,7 +33,9 @@ class __globals(object): def __init__(self): self.__pwd = activity.get_bundle_path() + self.__root = None self.__logo = 'resources/GameLogoCharacter.png' + self.__laugh = 'resources/laugh_attack.au' self.__activity_state = None self.__activity = None @@ -46,6 +49,7 @@ class __globals(object): # convert all of these to @Property def set_activity_instance(self, activity_instance): logging.debug('setting actifity %r' % activity_instance) + self.__root = activity_instance.get_activity_root() self.__activity = activity_instance # TODO -> Should we refresh the GUI for this one ? @@ -62,19 +66,28 @@ class __globals(object): return self.__pwd @property + def root(self): + return self.__root + + @property def tmpdir(self): '''Temporary directory - currently this exists for the sole purpose of having a place to dump sounds and images into so we don't have to keep them in memory - don't know if this will still be valid under bitfrost, don't know if sounds and images can be pulled directly out of the journal when needing to be (dis)played''' - return '/tmp' #os.path.join(self.__pwd, 'tmp') + logging.debug('Temp dir is %s' % os.path.join(self.__root, 'tmp')) + return os.path.join(self.__root, 'tmp') @property def logo(self): return os.path.join(self.pwd, self.__logo) @property + def laugh_uri(self): + return os.path.join(self.pwd, self.__laugh) + + @property def JokeMachineState(self): if not self.__activity_state: # Okay - When app is not run from Journal activity.read_file() is never @@ -100,10 +113,9 @@ class __globals(object): # utility functions with global state def temporary_filename(self): - # TODO - remember these and delete them all on app exit - file_name = os.tempnam(self.tmpdir) - self.__temporary_filenames.append(file_name) - return file_name + (fd, name) = tempfile.mkstemp(prefix='jokemachine_') + self.__temporary_filenames.append(name) + return name def shutdown(self): -- cgit v0.9.1