diff options
author | Walter Bender <walter@walter-laptop.(none)> | 2009-07-11 15:23:41 (GMT) |
---|---|---|
committer | Walter Bender <walter@walter-laptop.(none)> | 2009-07-11 15:23:41 (GMT) |
commit | e481cd08bc77641da8a1468749fe885fda62ad3b (patch) | |
tree | 84d0a8d866136929cf33e7c9a26b7e3f97b59a40 | |
parent | 6965c82745176ba3ffcaf2cc1aa29b92b176df8c (diff) |
-rw-r--r-- | implodeactivity.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/implodeactivity.py b/implodeactivity.py index 7dbd963..41e7aeb 100644 --- a/implodeactivity.py +++ b/implodeactivity.py @@ -28,7 +28,12 @@ from sugar.graphics.radiotoolbutton import RadioToolButton import implodegame import os -import json +try: + import json + json.dumps +except (ImportError, AttributeError): + import simplejson as json +from StringIO import StringIO import gtk import gobject @@ -80,8 +85,11 @@ class ImplodeActivity(Activity): def read_file(self, file_path): # Loads the game state from a file. f = file(file_path, 'rt') - file_data = json.read(f.read()) + content = f.read() + io = StringIO(content) + file_data = json.load(io) f.close() + print file_data _logger.debug(file_data) (file_type, version, game_data) = file_data @@ -92,10 +100,12 @@ class ImplodeActivity(Activity): # Writes the game state to a file. game_data = self._game.get_game_state() file_data = ['Implode save game', [1, 0], game_data] - content = json.write(file_data) last_game_path = self._get_last_game_path() for path in (file_path, last_game_path): f = file(path, 'wt') + io = StringIO() + json.dump(file_data,io) + content = io.getvalue() f.write(content) f.close() |