From 72f094f4177be526a641aa1a20806da5a857828b Mon Sep 17 00:00:00 2001 From: "g@localhost.localdomain" Date: Sun, 20 Aug 2006 19:18:09 +0200 Subject: [PATCH] Clean user given filenames, and set the same behaviour in curses as in gtk: the user can go to a directory upper than the one on the command line. --- pysize.py | 2 ++ ui/curses/ui_curses.py | 7 +++---- ui/utils.py | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pysize.py b/pysize.py index 12ae5d8..32416c8 100755 --- a/pysize.py +++ b/pysize.py @@ -5,6 +5,7 @@ import optparse from ui.ascii import ui_ascii from ui.curses import ui_curses from ui.gtk import ui_gtk +from ui.utils import clean_filename from core.sigquit_traceback import install_sigquit_traceback def _ui_auto(options, args): @@ -55,6 +56,7 @@ def _main(): if len(args) != 1: print parser.error('A single argument is expected') + args[0] = clean_filename(args[0]) continuation = lambda: UI[options.ui](options, args) if options.profile: diff --git a/ui/curses/ui_curses.py b/ui/curses/ui_curses.py index 0de6e3e..665b201 100644 --- a/ui/curses/ui_curses.py +++ b/ui/curses/ui_curses.py @@ -15,8 +15,7 @@ class _CursesApp: self.max_depth = options.max_depth if options.min_size != 'auto': raise Exception, 'curses UI supports only --min-size=auto' - self.root_path = args[0] - self._set_path(self.root_path) + self._set_path(args[0]) self._init_curses() def _init_curses(self): @@ -121,8 +120,8 @@ class _CursesApp: self.selected_node = selected if self.selected_node == self.tree.root: # Browsing to the left - if not os.path.samefile(self.path, self.root_path): - parent = os.path.dirname(self.selected_node.get_fullpath()) + if len(self.path) > 1: + parent = os.path.dirname(self.path) self._set_path(parent) else: self.selected_node = None diff --git a/ui/utils.py b/ui/utils.py index 443c020..6fb1c7a 100644 --- a/ui/utils.py +++ b/ui/utils.py @@ -33,3 +33,9 @@ def min_size_to_consider(min_size='auto', height=0): if not (letter in units_letters and suffix in ('iB', '')): raise Exception, 'Cannot parse unit in: ' + min_size return int(min_size) * 1024 ** units_letters.index(letter) + +def clean_filename(filename): + filename = filename.rstrip('/') + while '//' in filename: + filename = filename.replace('//', '/') + return filename -- 2.11.4.GIT