Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-07-04 10:37:00 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-08-15 19:44:35 (GMT)
commitf04b5a628583c07c29abd5eb5b32d33c784f9c7e (patch)
treea7b16f734c8b1c82e96e3d6de8ee26f995ab678c /src
parent2148b47c2a5910eeb14fe827059585bef09fc111 (diff)
Prevent view source display of some binary and "junk" files (SL#2854)
This patch addresses the issue raised in SL#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. [added exclude list for (exact-match) file names, tweaked description] Signed-off-by: Sascha Silbe <silbe@activitycentral.com> Acked-by: Simon Schampijer <simon@laptop.org>
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/view/viewsource.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py
index 1f89b75..648e740 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,10 @@ from sugar.datastore import datastore
from sugar import mime
+_EXCLUDE_EXTENSIONS = ('.pyc', '.pyo', '.so', '.o', '.a', '.la', '.mo', '~',
+ '.xo', '.tar', '.bz2', '.zip', '.gz')
+_EXCLUDE_NAMES = ['.deps', '.libs']
+
_SOURCE_FONT = pango.FontDescription('Monospace %d' % style.FONT_SIZE)
_logger = logging.getLogger('ViewSource')
@@ -388,16 +393,18 @@ 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'):
- full_path = os.path.join(dir_path, f)
- if os.path.isdir(full_path):
- new_iter = model.append(parent, [f, full_path])
- self._add_dir_to_model(full_path, new_iter)
- else:
- current_iter = model.append(parent, [f, full_path])
- if f == self._initial_filename:
- selection = self._tree_view.get_selection()
- selection.select_iter(current_iter)
+ if f.endswith(_EXCLUDE_EXTENSIONS) or f in _EXCLUDE_NAMES:
+ continue
+
+ full_path = os.path.join(dir_path, f)
+ if os.path.isdir(full_path):
+ new_iter = model.append(parent, [f, full_path])
+ self._add_dir_to_model(full_path, new_iter)
+ else:
+ current_iter = model.append(parent, [f, full_path])
+ if f == self._initial_filename:
+ selection = self._tree_view.get_selection()
+ selection.select_iter(current_iter)
def __selection_changed_cb(self, selection):
model, tree_iter = selection.get_selected()