Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArtActivity.py
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2009-03-18 15:38:15 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-03-18 15:38:15 (GMT)
commit534dc5bc710e797f94423452e119e8ed406f880c (patch)
treec8cd593e0fa33d96b4fe8003bfd483cee3aa6995 /TurtleArtActivity.py
parent44d3d6379485193181f22a83ec1e192b15016e03 (diff)
fixed premature read_file bug
Diffstat (limited to 'TurtleArtActivity.py')
-rw-r--r--TurtleArtActivity.py44
1 files changed, 23 insertions, 21 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 977369c..a28333b 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -136,7 +136,7 @@ class TurtleArtActivity(activity.Activity):
'data')
if self._jobject and self._jobject.file_path:
- self.read_ta_file(self._jobject.file_path)
+ self.read_file(self._jobject.file_path)
## sharing code
# Get the Presence Service
@@ -315,28 +315,30 @@ class TurtleArtActivity(activity.Activity):
os.remove(pngfile)
os.remove(tafile)
- def read_ta_file(self, file_path):
+ def read_file(self, file_path):
import tarfile,os,tempfile,shutil
- _logger.debug("Reading file %s" % file_path)
- # should be a tar file
- if file_path[-5:] == ".gtar":
- tar_fd = tarfile.open(file_path, 'r')
- tmpdir = tempfile.mkdtemp()
- try:
- # We'll get 'ta_code.ta' and possibly a 'ta_image.png'
- tar_fd.extractall(tmpdir)
- tawindow.load_files(self.tw, os.path.join(tmpdir, \
- 'ta_code.ta'), os.path.join(tmpdir, 'ta_image.png'))
- finally:
- shutil.rmtree(tmpdir)
- tar_fd.close()
- # try to open a .ta file
- elif file_path[-3:] == ".ta":
- tawindow.load_files(self.tw, file_path, "")
-
- # run the activity
- tawindow.runbutton(self.tw, 0)
+ if hasattr(self, 'tw'):
+ _logger.debug("Reading file %s" % file_path)
+ # should be a tar file
+ if file_path[-5:] == ".gtar":
+ tar_fd = tarfile.open(file_path, 'r')
+ tmpdir = tempfile.mkdtemp()
+ try:
+ # We'll get 'ta_code.ta' and possibly a 'ta_image.png'
+ tar_fd.extractall(tmpdir)
+ tawindow.load_files(self.tw, os.path.join(tmpdir, \
+ 'ta_code.ta'), os.path.join(tmpdir, 'ta_image.png'))
+ finally:
+ shutil.rmtree(tmpdir)
+ tar_fd.close()
+ # try to open a .ta file
+ elif file_path[-3:] == ".ta":
+ tawindow.load_files(self.tw, file_path, "")
+ # run the activity
+ tawindow.runbutton(self.tw, 0)
+ else:
+ _logger.debug("Deferring reading file %s" % file_path)
def jobject_new_patch(self):
oldj = self._jobject