Ticket #1241: sugar-1241-toolkit.patch

File sugar-1241-toolkit.patch, 2.5 KB (added by alsroot, 12 years ago)
  • src/sugar/datastore/datastore.py

    From 74f702fbf07930d02df199013bc6bd9d030db1f8 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Wed, 2 Sep 2009 14:49:09 +0000
    Subject: ObjectChooser displays USB media files, but fails to access file #1241
    
    ---
     src/sugar/datastore/datastore.py |   47 +++++++++++++++++++++++++++++++++++++-
     1 files changed, 46 insertions(+), 1 deletions(-)
    
    diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py
    index f001d76..cc93e3d 100644
    a b import logging 
    2323import time
    2424from datetime import datetime
    2525import os
    26 
     26import tempfile
    2727import gobject
    2828
     29from sugar import env
    2930from sugar.datastore import dbus_helpers
    3031from sugar import mime
    3132
    class DSObject(object): 
    138139    def copy(self):
    139140        return DSObject(None, self._metadata.copy(), self._file_path)
    140141
     142class NonDSObject(object):
     143
     144    def __init__(self, file_path):
     145        self.object_id = file_path
     146        self._metadata = DSMetadata()
     147        self._file_path = None
     148        self._destroyed = False
     149
     150    def get_metadata(self):
     151        return self._metadata
     152
     153    metadata = property(get_metadata)
     154
     155    def get_file_path(self, fetch=True):
     156        # we have to create symlink since its a common practice
     157        # to create hardlinks to jobject files
     158        if self._file_path is None:
     159            self._file_path = tempfile.mktemp(
     160                    prefix='nondsobject',
     161                    dir=os.path.join(env.get_profile_path(), 'data'))
     162            os.symlink(self.object_id, self._file_path)
     163        return self._file_path
     164
     165    file_path = property(get_file_path)
     166
     167    def destroy(self):
     168        if self._destroyed:
     169            logging.warning('This NonDSObject has already been destroyed!.')
     170            return
     171        self._destroyed = True
     172        if self._file_path is not None:
     173            os.remove(self._file_path)
     174            self._file_path = None
     175
     176    def __del__(self):
     177        if not self._destroyed:
     178            logging.warning('NonDSObject was deleted without cleaning up. '
     179                            'Call NonDSObject.destroy() before disposing it.')
     180            self.destroy()
     181
    141182
    142183def get(object_id):
    143184    logging.debug('datastore.get')
     185
     186    if object_id.startswith('/'):
     187        return NonDSObject(object_id)
     188
    144189    metadata = dbus_helpers.get_properties(object_id)
    145190
    146191    ds_object = DSObject(object_id, DSMetadata(metadata), None)