[Sugar-devel] [PATCH] Added ability to export Journal items.

Sebastian Silva sebastian at somosazucar.org
Thu Jun 2 00:25:46 EDT 2011


From: Sebastian Silva <icarito at sugarlabs.org>

We don't ship rainbow everywhere so it's worth a try.
---
 sugarcommander.py |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/sugarcommander.py b/sugarcommander.py
index 781bce9..f9cdc3f 100755
--- a/sugarcommander.py
+++ b/sugarcommander.py
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 import logging
-import os
+import os, shutil
 import time
 import gtk
 import pango
@@ -233,8 +233,16 @@ class SugarCommander(activity.Activity):
         self.resize_width_entry.hide()
 
         vbox = gtk.VBox(homogeneous=True,  spacing=5)
+        self.export_button = gtk.Button(_("Export Item To The Filesystem"))
+        self.export_button.connect('clicked',  self.export_journal_entry)
+        self.export_button.show()
         vbox.pack_start(column_table)
-        vbox.pack_end(self.list_scroller_journal)
+
+        vbox2 = gtk.VBox()
+        vbox2.pack_start(self.list_scroller_journal)
+        vbox2.pack_end(self.export_button, expand=False, fill=False)
+        vbox.pack_end(vbox2)
+        vbox2.show()
 
         canvas.append_page(vbox,  tab1_label)
  
@@ -568,6 +576,30 @@ class SugarCommander(activity.Activity):
 
         return os.stat(path).st_size
 
+    def export_journal_entry(self,  widget,  data=None):
+        jobject = datastore.get(self.selected_journal_entry.object_id)
+        file_path = jobject.get_file_path()
+        if not file_path:
+            return
+        logging.debug('file path %s' % file_path)
+        title = jobject.metadata.get('title', None)
+        target_dir = os.path.join(os.environ['HOME'],'Escritorio') # 'Desktop' in spanish
+        if not os.path.isdir(target_dir):
+            target_dir = os.path.join(os.environ['HOME'], 'Desktop')
+        if not os.path.isdir(target_dir):
+            target_dir = os.environ['HOME']
+        if file_path[-4]=='.': # not all data seems to have extension
+            file_extension = file_path[-4:]
+        target_file = title + file_extension
+        target_path = os.path.join (target_dir, target_file)
+        try:
+            shutil.copyfile(file_path, target_path)
+        except IOError:
+            self.alert(_('Failure'), _('could not write %s to %s') % (target_file,target_dir))
+        else:
+            self.alert(_('Success'),  _('%s was copied to %s.') 
+                    % (target_file, target_dir ))
+
     def create_journal_entry(self,  widget,  data=None):
         filename = self._filechooser.get_filename()
         journal_entry = datastore.create()
-- 
1.7.2.3



More information about the Sugar-devel mailing list