Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcgames/util.py
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2012-10-20 09:22:01 (GMT)
committer Gary Martin <gary@garycmartin.com>2012-10-23 23:44:17 (GMT)
commite6cff9307917aa97019785c32fbf0e412ba0e7ea (patch)
treed1d8dc602db9dab662bcfa0376ac97d81f80abe7 /olpcgames/util.py
parentec034421db0933df5065dd681320ea39e96fc616 (diff)
some changes to back to life
Diffstat (limited to 'olpcgames/util.py')
-rwxr-xr-xolpcgames/util.py85
1 files changed, 0 insertions, 85 deletions
diff --git a/olpcgames/util.py b/olpcgames/util.py
deleted file mode 100755
index a0c26b0..0000000
--- a/olpcgames/util.py
+++ /dev/null
@@ -1,85 +0,0 @@
-"""Abstraction layer for working outside the Sugar environment"""
-import traceback, cStringIO
-import logging
-log = logging.getLogger( 'olpcgames.util' )
-import os
-import os.path
-
-NON_SUGAR_ROOT = '~/.sugar/default/olpcgames'
-
-try:
- from sugar.activity.activity import get_bundle_path as _get_bundle_path
- def get_bundle_path( ):
- """Retrieve bundle path from activity with fix for silly registration bug"""
- path = _get_bundle_path()
- if path.endswith( '.activity.activity' ):
- log.warn( '''Found double .activity suffix in bundle path, truncating: %s''', path )
- path = path[:-9]
- return path
-except ImportError:
- log.warn( '''Do not appear to be running under Sugar, stubbing-in get_bundle_path''' )
- def get_bundle_path():
- """Retrieve a substitute data-path for non OLPC systems"""
- return os.getcwd()
-
-
-def get_activity_root( ):
- """Return the activity root for data storage operations
-
- If the activity is present, returns the activity's root,
- otherwise returns NON_SUGAR_ROOT as the directory.
- """
- root = os.environ.get( 'SUGAR_ACTIVITY_ROOT' )
- if not root:
- root = NON_SUGAR_ROOT
- log.debug( 'Activity Root: %s', root )
- return os.path.expanduser( root )
-
-def data_path(file_name):
- """Return the full path to a file in the data sub-directory of the bundle"""
- dirname = os.path.join(get_bundle_path(), 'data' )
- if not os.path.isdir( dirname ):
- os.makedirs( dirname )
- return os.path.join( dirname, file_name )
-def tmp_path(file_name):
- """Return the full path to a file in the temporary directory"""
- dirname = os.path.join(get_bundle_path(), 'tmp' )
- if not os.path.isdir( dirname ):
- os.makedirs( dirname )
- return os.path.join(dirname, file_name)
-
-def get_traceback(error):
- """Get formatted traceback from current exception
-
- error -- Exception instance raised
-
- Attempts to produce a 10-level traceback as a string
- that you can log off. Use like so:
-
- try:
- doSomething()
- except Exception, err:
- log.error(
- '''Failure during doSomething with X,Y,Z parameters: %s''',
- util.get_traceback( err ),
- )
- """
- if error is None:
- error = []
- for (f,l,func,statement) in traceback.extract_stack()[:-2]:
- if statement:
- statement = ': %s'%( statement, )
- if func:
- error.append( '%s.%s (%s)%s'%( f,func,l, statement))
- else:
- error.append( '%s (%s)%s'%( f,l, statement))
- return "\n".join( error )
- else:
- exception = str(error)
- file = cStringIO.StringIO()
- try:
- traceback.print_exc( limit=10, file = file )
- exception = file.getvalue()
- finally:
- file.close()
- return exception