Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-01-03 15:47:50 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-03 15:47:50 (GMT)
commit4c090f79a50897f7c150f94c84054cfd4a1991ac (patch)
tree106b758152388cc5cb1aa3d9a975b16a09a3ddac
parent550c2f00834cf047b62f4fe541c308cea29b04a3 (diff)
Use util.TempFilePath and stop leaking temp files
-rw-r--r--src/jarabe/journal/journaltoolbox.py10
-rw-r--r--src/jarabe/journal/listview.py8
-rw-r--r--src/jarabe/journal/misc.py29
-rw-r--r--src/jarabe/journal/model.py10
-rw-r--r--src/jarabe/journal/palettes.py9
5 files changed, 38 insertions, 28 deletions
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index bcd59b7..ce20d6b 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -311,6 +311,7 @@ class EntryToolbar(gtk.Toolbar):
gtk.Toolbar.__init__(self)
self._metadata = None
+ self._temp_file_path = None
self._resume = ToolButton('activity-start')
self._resume.connect('clicked', self._resume_clicked_cb)
@@ -355,12 +356,13 @@ class EntryToolbar(gtk.Toolbar):
self.__clipboard_clear_func_cb)
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data):
- file_path = model.get_file(self._metadata['uid'])
- selection_data.set_uris(['file://' + file_path])
+ # Get hold of a reference so the temp file doesn't get deleted
+ self._temp_file_path = model.get_file(self._metadata['uid'])
+ selection_data.set_uris(['file://' + self._temp_file_path])
def __clipboard_clear_func_cb(self, clipboard, data):
- #TODO: should we remove here the temp file created before?
- pass
+ # Release and delete the temp file
+ self._temp_file_path = None
def _erase_button_clicked_cb(self, button):
registry = bundleregistry.get_registry()
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 1f3281f..01ec8b1 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -79,6 +79,7 @@ class BaseListView(gtk.HBox):
self.connect('destroy', self.__destroy_cb)
# DND stuff
+ self._temp_file_path = None
self._pressed_button = None
self._press_start_x = None
self._press_start_y = None
@@ -345,14 +346,17 @@ class BaseListView(gtk.HBox):
self._press_start_y = None
self._last_clicked_entry = None
+ # Release and delete the temp file
+ self._temp_file_path = None
+
def _drag_data_get_cb(self, widget, context, selection, target_type,
event_time):
logging.debug("drag_data_get_cb: requested target " + selection.target)
metadata = self._last_clicked_entry.metadata
if selection.target == 'text/uri-list':
- #TODO: figure out the best place to get rid of that temp file
- file_path = model.get_file(metadata)
+ # Get hold of a reference so the temp file doesn't get deleted
+ self._temp_file_path = model.get_file(metadata)
selection.set(selection.target, 8, file_path)
elif selection.target == 'journal-object-id':
selection.set(selection.target, 8, metadata['uid'])
diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
index 16047e6..3c6ef8e 100644
--- a/src/jarabe/journal/misc.py
+++ b/src/jarabe/journal/misc.py
@@ -55,23 +55,23 @@ def get_icon_name(metadata):
file_name = None
- #TODO: figure out the best place to get rid of that temp file
- file_path = model.get_file(metadata['uid'])
- if is_activity_bundle(metadata) and os.path.exists(file_path):
- try:
- bundle = ActivityBundle(file_path)
- file_name = bundle.get_icon()
- except Exception:
- logging.warning('Could not read bundle:\n' + \
- ''.join(traceback.format_exception(*sys.exc_info())))
- file_name = _get_icon_file_name('application-octet-stream')
-
if not file_name and metadata.get('activity', ''):
service_name = metadata['activity']
activity_info = bundleregistry.get_registry().get_bundle(service_name)
if activity_info:
file_name = activity_info.get_icon()
+ if is_activity_bundle(metadata):
+ file_path = model.get_file(metadata['uid'])
+ if os.path.exists(file_path):
+ try:
+ bundle = ActivityBundle(file_path)
+ file_name = bundle.get_icon()
+ except Exception:
+ logging.warning('Could not read bundle:\n' + \
+ ''.join(traceback.format_exception(*sys.exc_info())))
+ file_name = _get_icon_file_name('application-octet-stream')
+
mime_type = metadata['mime_type']
if not file_name and mime_type:
icon_name = mime.get_mime_icon(mime_type)
@@ -98,8 +98,7 @@ def get_date(metadata):
def get_bundle(metadata):
try:
- #TODO: figure out the best place to get rid of that temp file
- file_path = model.get_file(metadata['uid'])
+ file_path = util.TempFilePath(model.get_file(metadata['uid']))
if is_activity_bundle(metadata) and os.path.exists(file_path):
return ActivityBundle(file_path)
elif is_content_bundle(metadata) and os.path.exists(file_path):
@@ -144,7 +143,7 @@ def resume(metadata, bundle_id=None):
if is_activity_bundle(metadata) and bundle_id is None:
logging.debug('Creating activity bundle')
- #TODO: figure out the best place to get rid of that temp file
+
file_path = model.get_file(metadata['uid'])
bundle = ActivityBundle(file_path)
if not registry.is_installed(bundle):
@@ -166,7 +165,7 @@ def resume(metadata, bundle_id=None):
elif is_content_bundle(metadata) and bundle_id is None:
logging.debug('Creating content bundle')
- #TODO: figure out the best place to get rid of that temp file
+
file_path = model.get_file(metadata['uid'])
bundle = ContentBundle(file_path)
if not bundle.is_installed():
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index cf66b43..56dad20 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -25,6 +25,7 @@ import gconf
from sugar import dispatch
from sugar import mime
+from sugar import util
DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore'
DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore'
@@ -291,7 +292,11 @@ def get_file(object_id):
return object_id
else:
logging.debug('get_file asked for entry with id %r' % object_id)
- return _get_datastore().get_filename(object_id)
+ file_path = _get_datastore().get_filename(object_id)
+ if file_path:
+ return util.TempFilePath(file_path)
+ else:
+ return None
def get_unique_values(key):
"""Returns a list with the different values a property has taken
@@ -312,13 +317,12 @@ def copy(metadata, mount_point):
"""
metadata = get(metadata['uid'])
- #TODO: figure out the best place to get rid of that temp file
file_path = get_file(metadata['uid'])
+ file_path.delete = False
metadata['mountpoint'] = mount_point
del metadata['uid']
- #TODO: should we transfer ownership?
return write(metadata, file_path)
def write(metadata, file_path='', update_mtime=True):
diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
index 6832750..1345f43 100644
--- a/src/jarabe/journal/palettes.py
+++ b/src/jarabe/journal/palettes.py
@@ -38,6 +38,7 @@ class ObjectPalette(Palette):
def __init__(self, metadata):
self._metadata = metadata
+ self._temp_file_path = None
activity_icon = Icon(icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
activity_icon.props.file = misc.get_icon_name(metadata)
@@ -102,13 +103,14 @@ class ObjectPalette(Palette):
self.__clipboard_clear_func_cb)
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data):
- file_path = model.get_file(self._metadata['uid'])
+ # Get hold of a reference so the temp file doesn't get deleted
+ self._temp_file_path = model.get_file(self._metadata['uid'])
logging.debug('__clipboard_get_func_cb %r' % file_path)
selection_data.set_uris(['file://' + file_path])
def __clipboard_clear_func_cb(self, clipboard, data):
- #TODO: should we remove here the temp file created before?
- pass
+ # Release and delete the temp file
+ self._temp_file_path = None
def __erase_activate_cb(self, menu_item):
registry = bundleregistry.get_registry()
@@ -120,7 +122,6 @@ class ObjectPalette(Palette):
def __friend_selected_cb(self, menu_item, buddy):
logging.debug('__friend_selected_cb')
- #TODO: figure out the best place to get rid of that temp file
file_name = model.get_file(self._metadata['uid'])
title = str(self._metadata['title'])