[Sugar-devel] [sugar-toolkit-gtk3 PATCH] sl#4276: Writing the icon-files for ".xo" files on a permanent mount-point, and not /tmp. mount-point.

Ajay Garg ajay at activitycentral.com
Mon Dec 10 14:09:12 EST 2012


This issue happens, when ".xo" files need to be rendered in the listview in non-journal locations.
In such cases, these files have no "activity" or "bundle_id" fields in their metadata.

Thus, the current way to know the icon-file-name for such ".xo" files was to expand the zipped files, and write out the icon-files at pseudo-permanent storage,  at /tmp.

However, before the icon-file could be used by the listview to "pick up" the icon bytes, it was  being  garbage-collected.

Thus, now as the solution, we write the icon-files (maximum of one file per activity) at "~/.sugar/default/icon_files". Now, the  icons are rendered correctly then.


 src/sugar3/bundle/activitybundle.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/sugar3/bundle/activitybundle.py b/src/sugar3/bundle/activitybundle.py
index 3895673..2c0894d 100644
--- a/src/sugar3/bundle/activitybundle.py
+++ b/src/sugar3/bundle/activitybundle.py
@@ -209,11 +209,22 @@ class ActivityBundle(Bundle):
             return os.path.join(self._path, icon_path)
         else:
             icon_data = self.get_file(icon_path).read()
-            temp_file, temp_file_path = tempfile.mkstemp(prefix=self._icon,
-                                                         suffix='.svg')
-            os.write(temp_file, icon_data)
-            os.close(temp_file)
-            return util.TempFilePath(temp_file_path)
+
+            # First  check to see if the directory exists.
+            icon_files_dir_path = env.get_profile_path('icon_files')
+            if not os.path.isdir(icon_files_dir_path):
+                os.makedirs(icon_files_dir_path, 0770)
+
+            icon_file_path = os.path.join(icon_files_dir_path,
+                                          self._icon + '.svg')
+
+            # Write the icon-data file, if not already existing.
+            if not os.path.exists(icon_file_path):
+                icon_file_pointer = open(icon_file_path, 'w')
+                icon_file_pointer.write(icon_data)
+                icon_file_pointer.close()
+
+            return icon_file_path
 
     def get_activity_version(self):
         """Get the activity version"""
-- 
1.7.11.7



More information about the Sugar-devel mailing list