[Sugar-devel] [PATCH] prevent view source display of .pyo, .pyc, .so files (#2854)

Walter Bender walter at sugarlabs.org
Mon Jul 4 06:37:00 EDT 2011


From: Walter Bender <walter.bender at gmail.com>

This patch addresses the issue raised in #2854: the exclusion of some file
types from being displayed by viewsource. This version of the patch uses a
global, _EXCLUDE, that includes a list of many more common file types to
exclude, as per some mining of .gitignore files by Sascha. In a future patch,
it may make sense to append the data from the .gitignore and git exclude files.

---
 src/jarabe/view/viewsource.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py
index a1c0be3..5f3abab 100644
--- a/src/jarabe/view/viewsource.py
+++ b/src/jarabe/view/viewsource.py
@@ -1,5 +1,6 @@
 # Copyright (C) 2008 One Laptop Per Child
 # Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
+# Copyright (C) 2011 Walter Bender
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -37,6 +38,9 @@ from sugar.datastore import datastore
 from sugar import mime
 
 
+_EXCLUDE = ('.pyc', '.pyo', '.so', '.o', '.a', '.la', '.mo', '~', '.xo',
+            '.tar', '.bz2', '.zip', '.gz', '.deps', '.libs')
+
 _SOURCE_FONT = pango.FontDescription('Monospace %d' % style.FONT_SIZE)
 
 _logger = logging.getLogger('ViewSource')
@@ -388,7 +392,7 @@ class FileViewer(gtk.ScrolledWindow):
     def _add_dir_to_model(self, dir_path, parent=None):
         model = self._tree_view.get_model()
         for f in os.listdir(dir_path):
-            if not f.endswith('.pyc'):
+            if not f.endswith(_EXCLUDE):
                 full_path = os.path.join(dir_path, f)
                 if os.path.isdir(full_path):
                     new_iter = model.append(parent, [f, full_path])
-- 
1.7.4.4



More information about the Sugar-devel mailing list