[Sugar-devel] [PATCH] Journal: Enable saving metadata in external device - OLPC#10717

godiard at sugarlabs.org godiard at sugarlabs.org
Fri Jun 17 10:20:47 EDT 2011


From: Gonzalo Odiard <godiard at gmail.com>

This patch enable saving metadata and renaming files in device
with write permission.
There are code to avoid break if the user change the title and other
properties, like description, tags or favorites, because changing
the title, the files used to save the meatata change the name too.

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/jarabe/journal/expandedentry.py |   20 ++++++++++++++++++--
 src/jarabe/journal/listview.py      |    3 ---
 src/jarabe/journal/model.py         |    6 ++++--
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index fe2f320..d293694 100644
--- a/src/jarabe/journal/expandedentry.py
+++ b/src/jarabe/journal/expandedentry.py
@@ -18,6 +18,7 @@ import logging
 from gettext import gettext as _
 import StringIO
 import time
+import os
 
 import hippo
 import cairo
@@ -406,7 +407,14 @@ class ExpandedEntry(hippo.CanvasBox):
             needs_update = True
 
         if needs_update:
-            model.write(self._metadata, update_mtime=False)
+            if self._metadata.get('mountpoint', '/') == '/':
+                model.write(self._metadata, update_mtime=False)
+            else:
+                old_file_path = os.path.join(self._metadata['mountpoint'],
+                        model.get_file_name(old_title,
+                        self._metadata['mime_type']))
+                model.write(self._metadata, file_path=old_file_path,
+                        update_mtime=False)
 
         self._update_title_sid = None
 
@@ -420,7 +428,15 @@ class ExpandedEntry(hippo.CanvasBox):
             self._metadata['keep'] = 0
         else:
             self._metadata['keep'] = 1
-        model.write(self._metadata, update_mtime=False)
+
+        if self._metadata.get('mountpoint', '/') == '/':
+            model.write(self._metadata, update_mtime=False)
+        else:
+            f_path = os.path.join(self._metadata['mountpoint'],
+                    model.get_file_name(self._metadata['title'],
+                    self._metadata['mime_type']))
+            model.write(self._metadata, file_path=f_path,
+                    update_mtime=False)
 
         keep_icon.props.keep = self.get_keep()
 
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 1bc8f8a..78e109a 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -328,9 +328,6 @@ class BaseListView(gtk.Bin):
         self._scroll_position = self.tree_view.props.vadjustment.props.value
         logging.debug('ListView.__map_cb %r', self._scroll_position)
 
-        is_editable = self._query.get('mountpoints', '') == '/'
-        self.cell_title.props.editable = is_editable
-
     def _is_query_empty(self):
         # FIXME: This is a hack, we shouldn't have to update this every time
         # a new search term is added.
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index fd25681..2be2bde 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -782,5 +782,7 @@ def get_unique_file_name(mount_point, file_name):
 
 
 def is_editable(metadata):
-    mountpoint = metadata.get('mountpoint', '/')
-    return mountpoint == '/'
+    if metadata.get('mountpoint', '/') == '/':
+        return True
+    else:
+        return os.access(metadata['mountpoint'], os.W_OK)
-- 
1.7.4.4



More information about the Sugar-devel mailing list