From cc87d98d21c6b06e8797522e28a1df2a11c5d923 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 12 Aug 2009 02:00:08 +0000 Subject: fixed save/load problem with old builds --- diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 2684a33..7c0838d 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -390,8 +390,8 @@ class TurtleArtActivity(activity.Activity): if hasattr(self, 'tw'): _logger.debug("Reading file %s" % file_path) - # should be a tar file - if file_path[-5:] == ".gtar": + # should be a gtar (newer builds) or tar (767) file + if file_path[-5:] == ".gtar" or file_path[-4:] == ".tar": tar_fd = tarfile.open(file_path, 'r') tmpdir = tempfile.mkdtemp() try: diff --git a/taproject.py b/taproject.py index 2fc676a..c0c5c69 100644 --- a/taproject.py +++ b/taproject.py @@ -24,10 +24,20 @@ pygtk.require('2.0') import gtk import pickle try: + _in_a_pickle = False import json json.dumps + from json import load as jload + from json import dump as jdump except (ImportError, AttributeError): - import simplejson as json + try: + import simplejson as json + from json import load as jload + from json import dump as jdump + except: + # use pickle on old systems + _in_a_pickle = True + from StringIO import StringIO import os.path @@ -64,9 +74,9 @@ def load_files(tw,ta_file, png_file=''): f.seek(0) # rewind necessary because of pickle.load text = f.read() io = StringIO(text) - listdata = json.load(io) + listdata = jload(io) print listdata - # listdata = json.decode(text) + # listdata = jdecode(text) data = tuplify(listdata) # json converts tuples to lists f.close() new_project(tw) @@ -81,20 +91,22 @@ def get_load_name(tw): # unpack serialized data sent across a share def load_string(tw,text): - io = StringIO(text) - listdata = json.load(io) - # listdata = json.decode(text) - data = tuplify(listdata) # json converts tuples to lists - new_project(tw) - read_data(tw,data) + if _in_a_pickle is False: + io = StringIO(text) + listdata = jload(io) + # listdata = jdecode(text) + data = tuplify(listdata) # json converts tuples to lists + new_project(tw) + read_data(tw,data) # unpack sserialized data from the clipboard def clone_stack(tw,text): - io = StringIO(text) - listdata = json.load(io) - # listdata = json.decode(text) - data = tuplify(listdata) # json converts tuples to lists - read_stack(tw,data) + if _in_a_pickle is False: + io = StringIO(text) + listdata = jload(io) + # listdata = jdecode(text) + data = tuplify(listdata) # json converts tuples to lists + read_stack(tw,data) # paste stack from the clipboard def read_stack(tw,data): @@ -196,21 +208,28 @@ def get_save_name(tw): def save_data(tw,fname): f = file(fname, "w") data = assemble_data_to_save(tw) - io = StringIO() - json.dump(data,io) - text = io.getvalue() - # text = json.encode(data) - f.write(text) + if _in_a_pickle is True: + pickle.dump(data,f) + else: + io = StringIO() + jdump(data,io) + text = io.getvalue() + print text + # text = jencode(data) + f.write(text) f.close() # Used to send data across a shared session def save_string(tw): - data = assemble_data_to_save(tw) - io = StringIO() - json.dump(data,io) - text = io.getvalue() - # text = json.encode(data) - return text + if _in_a_pickle is False: + data = assemble_data_to_save(tw) + io = StringIO() + jdump(data,io) + text = io.getvalue() + # text = jencode(data) + return text + else: + return "" def assemble_data_to_save(tw): bs = blocks(tw) @@ -236,12 +255,15 @@ def assemble_data_to_save(tw): # serialize a stack to save to the clipboard def serialize_stack(tw): - data = assemble_stack_to_clone(tw) - io = StringIO() - json.dump(data,io) - text = io.getvalue() - # text = json.encode(data) - return text + if _in_a_pickle is False: + data = assemble_stack_to_clone(tw) + io = StringIO() + jdump(data,io) + text = io.getvalue() + # text = jencode(data) + return text + else: + return "" # find the stack under the cursor and serialize it def assemble_stack_to_clone(tw): -- cgit v0.9.1