diff options
-rw-r--r-- | code/directory.py | 15 | ||||
-rw-r--r-- | code/fm.py | 4 | ||||
-rw-r--r-- | code/fsobject.py | 9 | ||||
-rw-r--r-- | code/ui.py | 6 | ||||
-rw-r--r-- | ranger | 2 | ||||
-rw-r--r-- | test/tc_directory.py | 3 |
6 files changed, 30 insertions, 9 deletions
diff --git a/code/directory.py b/code/directory.py index ef68d35f..da7c0948 100644 --- a/code/directory.py +++ b/code/directory.py @@ -1,5 +1,5 @@ import fsobject -import file +import file, debug class Directory(fsobject.FSObject): def __init__(self, path): @@ -19,10 +19,17 @@ class Directory(fsobject.FSObject): self.content_loaded = True import os if self.exists: - self.filenames = os.listdir(self.path) + basenames = os.listdir(self.path) + mapped = map(lambda name: os.path.join(self.path, name), basenames) + self.filenames = list(mapped) + self.infostring = ' %d' % len(self.filenames) + debug.log('infostring set!') self.files = [] for name in self.filenames: - f = file.File(name) + if os.path.isdir(name): + f = Directory(name) + else: + f = file.File(name) f.load() self.files.append(f) @@ -36,7 +43,7 @@ class Directory(fsobject.FSObject): def __getitem__(self, key): if not self.accessible: raise fsobject.NotLoadedYet() - return self.filenames[key] + return self.files[key] if __name__ == '__main__': d = Directory('.') diff --git a/code/fm.py b/code/fm.py index c2fe30a4..6631aee4 100644 --- a/code/fm.py +++ b/code/fm.py @@ -1,5 +1,5 @@ import sys -import ui, debug, directory +import ui, debug, directory, fstype class FM(): def __init__(self, options, environment): @@ -25,6 +25,8 @@ class FM(): try: while 1: try: +# if type(self.env.cf) is directory.Directory: +# self.env.cf.load_content_once() self.ui.feed(self.env.directories, self.env.pwd, self.env.cf, self.env.termsize) self.ui.draw() except KeyboardInterrupt: diff --git a/code/fsobject.py b/code/fsobject.py index 1e194ac9..148976d2 100644 --- a/code/fsobject.py +++ b/code/fsobject.py @@ -17,6 +17,8 @@ class FSObject(object): self.islink = False self.brokenlink = False self.stat = None + self.infostring = None + self.permissions = None self.type = fstype.Unknown # load() reads useful information about the file from the file system @@ -34,10 +36,17 @@ class FSObject(object): if os.path.isdir(self.path): self.type = fstype.Directory + self.infostring = '--' elif os.path.isfile(self.path): self.type = fstype.File + self.infostring = ' %d' % self.stat.st_size + else: + self.type = fstype.Unknown + self.infostring = None + except OSError: self.islink = False + self.infostring = None self.type = fstype.Nonexistent self.exists = False self.accessible = False diff --git a/code/ui.py b/code/ui.py index 7d8fd828..3994d7ce 100644 --- a/code/ui.py +++ b/code/ui.py @@ -1,4 +1,4 @@ -import curses +import curses, debug class UI(): def __init__(self, options): self.scr = curses.initscr() @@ -31,7 +31,9 @@ class UI(): import time self.scr.erase() for i in range(1, len(self.pwd)): - self.scr.addstr(i, 0, self.pwd[i]) + f = self.pwd.files[i] + self.scr.addstr(i, 0, f.path) + if f.infostring: self.scr.addstr(i, 50, f.infostring) self.scr.refresh() def get_next_key(self): diff --git a/ranger b/ranger index 8e63ec86..4973e42f 100644 --- a/ranger +++ b/ranger @@ -15,7 +15,7 @@ def main(): import locale locale.setlocale(locale.LC_ALL, 'en_US.utf8') - path = '.' + path = '..' opt = options.get() env = environment.Environment() diff --git a/test/tc_directory.py b/test/tc_directory.py index 69717ba2..f97f9913 100644 --- a/test/tc_directory.py +++ b/test/tc_directory.py @@ -1,7 +1,7 @@ import unittest import sys, os sys.path.append('../code') -import directory, fsobject, file +import directory, fsobject, file, debug TESTDIR = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), 'testdir')) TESTFILE = os.path.join(TESTDIR, 'testfile5234148') @@ -30,6 +30,7 @@ class Test1(unittest.TestCase): # Get the filenames you expect it to have and sort both before # comparing. I don't expect any order after only loading the filenames. assumed_filenames = os.listdir(TESTDIR) + assumed_filenames = list(map(lambda str: os.path.join(TESTDIR, str), assumed_filenames)) assumed_filenames.sort() dir.filenames.sort() |