[Sugar-devel] [PATCH] Prevent view source display of excluded file list (#2854)
Walter Bender
walter at sugarlabs.org
Sat Aug 13 11:14:15 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 two
globals, _EXCLUDE_SUFFIX and _EXCLUDE_FILE that include lists 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.
Note that this patch differs from an earlier one in that it separates the
check for excluded file types (by checking the suffix) from excluded files.
---
src/jarabe/view/viewsource.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py
index 1f89b75..4f4263e 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_SUFFIX = ('.pyc', '.pyo', '.so', '.o', '.a', '.la', '.mo', '~', '.xo',
+ '.tar', '.bz2', '.zip', '.gz')
+_EXCLUDE_FILE = ('.deps', '.libs')
+
_SOURCE_FONT = pango.FontDescription('Monospace %d' % style.FONT_SIZE)
_logger = logging.getLogger('ViewSource')
@@ -388,7 +393,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_SUFFIX) and not f in _EXCLUDE_FILE:
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