third try is the charm. Sorry tomeu (and others).
On Thu, Apr 10, 2008 at 11:10 AM, Jameson Chema Quinn <[EMAIL PROTECTED]>
wrote:
> Resending patch in unified format
>
>
> On Thu, Apr 10, 2008 at 11:01 AM, Jameson Chema Quinn <
> [EMAIL PROTECTED]> wrote:
>
> > This patch also has one unrelated change, creating INSTANCE_DIR as a
> > global.
> >
>
>
diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py
index 2c1eaae..ceefc3c 100644
--- a/sugar/activity/activity.py
+++ b/sugar/activity/activity.py
@@ -84,6 +84,18 @@ J_DBUS_SERVICE = 'org.laptop.Journal'
J_DBUS_PATH = '/org/laptop/Journal'
J_DBUS_INTERFACE = 'org.laptop.Journal'
+INSTANCE_DIR = 'instance'
+
+class WarningDictionary(dict):
+ def __getitem__(self,key):
+ warnings.warn("Trying to get key %s in unallocated activity metadata dictionary %s"%(key,self),
+ RuntimeWarning, stacklevel=2)
+ return None
+ def __setetitem__(self,key,value):
+ warnings.warn("Trying to set key %s in unallocated activity metadata dictionary %s"%(key,self),
+ RuntimeWarning, stacklevel=2)
+ return dict.__setitem__(self,key,value)
+
class ActivityToolbar(gtk.Toolbar):
"""The Activity toolbar with the Journal entry title, sharing, Keep and Stop buttons
@@ -442,6 +454,10 @@ class Activity(Window, gtk.Container):
share_scope = SCOPE_PRIVATE
+ self.dirty = bool(handle or create_jobject) #do not save if not dirty.
+ #Individual activities responsible for setting and clearing
+ #this flag, but activity.py respects it.
+
if handle.object_id:
self._jobject = datastore.get(handle.object_id)
# TODO: Don't create so many objects until we have versioning
@@ -691,12 +707,16 @@ class Activity(Window, gtk.Container):
own implementation of write_file() to save your Activity specific data.
"""
- logging.debug('Activity.save: %r' % self._jobject.object_id)
+ logging.debug('Activity.save: %r' % self._jobject.object_id if self._jobject else 'NOTHING')
if self._updating_jobject:
logging.info('Activity.save: still processing a previous request.')
return
+ if not self.dirty:
+ logging.info('Activity.save: no need, nothing has happened since last save.')
+ return
+
buddies_dict = self._get_buddies()
if buddies_dict:
self.metadata['buddies_id'] = json.write(buddies_dict.keys())
@@ -707,11 +727,13 @@ class Activity(Window, gtk.Container):
self.metadata['preview'] = dbus.ByteArray(preview)
try:
- file_path = os.path.join(self.get_activity_root(), 'instance',
+ file_path = os.path.join(self.get_activity_root(), INSTANCE_DIR,
'%i' % time.time())
self.write_file(file_path)
- self._owns_file = True
- self._jobject.file_path = file_path
+ if os.path.isfile(file_path):
+ self._owns_file = True
+ if self._jobject:
+ self._jobject.file_path = file_path
except NotImplementedError:
pass
@@ -769,6 +791,8 @@ class Activity(Window, gtk.Container):
logging.debug('Share of activity %s successful, PS activity is %r.',
self._activity_id, activity)
+ logging.debug(u'DIRTY')
+ self.dirty = True #force a save of new data.
activity.props.name = self._jobject.metadata['title']
self._shared_activity = activity
@@ -905,7 +929,7 @@ class Activity(Window, gtk.Container):
if self._jobject:
return self._jobject.metadata
else:
- return None
+ return WarningDictionary()
metadata = property(get_metadata, None)
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar