parent
c2b6775ed0
commit
ccc9bea508
38
buffer2.py
38
buffer2.py
|
@ -502,7 +502,7 @@ class DirBuffer(Buffer):
|
|||
def path_exists(self):
|
||||
return os.path.exists(self.path)
|
||||
|
||||
def open(self):
|
||||
def _get_lines(self):
|
||||
if not self.path_exists():
|
||||
raise Exception, "directory %r does not exists" % self.path
|
||||
|
||||
|
@ -511,7 +511,7 @@ class DirBuffer(Buffer):
|
|||
names.insert(0, '..')
|
||||
names.insert(0, '.')
|
||||
|
||||
lines = []
|
||||
fieldlines = []
|
||||
maxlens = [0] * 5
|
||||
for name in names:
|
||||
# let's escape some troublesome characters
|
||||
|
@ -551,6 +551,23 @@ class DirBuffer(Buffer):
|
|||
else:
|
||||
perm[i] = '-'
|
||||
i += 1
|
||||
|
||||
if info.st_mode & stat.S_ISUID:
|
||||
if perm[3] == 'x':
|
||||
perm[3] = 's'
|
||||
else:
|
||||
perm[3] = 'S'
|
||||
if info.st_mode & stat.S_ISGID:
|
||||
if perm[6] == 'x':
|
||||
perm[6] = 's'
|
||||
else:
|
||||
perm[6] = 'S'
|
||||
if info.st_mode & stat.S_ISVTX:
|
||||
if perm[9] == 'x':
|
||||
perm[9] = 't'
|
||||
else:
|
||||
perm[9] = 'T'
|
||||
|
||||
perms = ''.join(perm)
|
||||
|
||||
try:
|
||||
|
@ -578,18 +595,21 @@ class DirBuffer(Buffer):
|
|||
maxlens[i] = max(maxlens[i], len(fields[i]))
|
||||
except:
|
||||
raise Exception, '%d %r' % (i, fields[i])
|
||||
lines.append(fields)
|
||||
|
||||
lines.sort(cmp=_path_sort)
|
||||
fieldlines.append(fields)
|
||||
|
||||
fieldlines.sort(cmp=_path_sort)
|
||||
fmt = '%%%ds %%-%ds %%-%ds %%%ds %%%ds %%s' % tuple(maxlens)
|
||||
|
||||
self.lines = []
|
||||
for fields in lines:
|
||||
lines = []
|
||||
for fields in fieldlines:
|
||||
s = fmt % fields
|
||||
self.lines.append(s)
|
||||
lines.append(s)
|
||||
return lines
|
||||
def open(self):
|
||||
self.lines = self._get_lines()
|
||||
def reload(self):
|
||||
self.open()
|
||||
lines = self._get_lines()
|
||||
self.set_lines(lines, force=True)
|
||||
def save(self, force=False):
|
||||
raise Exception, "can't save a directory buffer"
|
||||
def save_as(self, path):
|
||||
|
|
56
mode_dir.py
56
mode_dir.py
|
@ -4,7 +4,8 @@ from point2 import Point
|
|||
|
||||
class PermGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'set', r's'),
|
||||
PatternRule(r'sticky', r'[tT]'),
|
||||
PatternRule(r'setid', r'[sS]'),
|
||||
PatternRule(r'read', r'r'),
|
||||
PatternRule(r'write', r'w'),
|
||||
PatternRule(r'exec', r'x'),
|
||||
|
@ -49,12 +50,16 @@ class Dir(mode2.Fundamental):
|
|||
'unk.start': ('magenta', 'default'),
|
||||
'unk.name': ('magenta', 'default'),
|
||||
|
||||
'perm.set': ('red', 'default'),
|
||||
#'perm.setid': ('red', 'default'),
|
||||
#'perm.sticky': ('red', 'default'),
|
||||
'perm.setid': ('yellow', 'default'),
|
||||
'perm.sticky': ('yellow', 'default'),
|
||||
'perm.read': ('magenta', 'default'),
|
||||
'perm.write': ('magenta', 'default'),
|
||||
'perm.exec': ('magenta', 'default'),
|
||||
|
||||
'owner': ('blue', 'default'),
|
||||
#'owner': ('blue', 'default'),
|
||||
'owner': ('cyan', 'default'),
|
||||
'group': ('cyan', 'default'),
|
||||
'size': ('yellow', 'default'),
|
||||
'mtime': ('green', 'default'),
|
||||
|
@ -65,9 +70,19 @@ class Dir(mode2.Fundamental):
|
|||
self.add_action(Chown())
|
||||
self.add_action(Chgrp())
|
||||
self.add_action_and_bindings(OpenPath(), ('RETURN',))
|
||||
self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d'))
|
||||
def name(self):
|
||||
return "Dir"
|
||||
|
||||
def _resolve_token(w):
|
||||
c = w.logical_cursor()
|
||||
p = Point(0, c.y)
|
||||
return w.get_next_token_by_type(p, 'name')
|
||||
def _resolve_path(w):
|
||||
t = _resolve_token(w)
|
||||
path = os.path.join(w.buffer.path, t.string)
|
||||
return path
|
||||
|
||||
class Chmod(method.Method):
|
||||
def _execute(self, w, **vargs):
|
||||
w.set_error('chmod not implemented')
|
||||
|
@ -78,12 +93,37 @@ class Chgrp(method.Method):
|
|||
def _execute(self, w, **vargs):
|
||||
w.set_error('chgrp not implemented')
|
||||
|
||||
class RemovePath(method.Method):
|
||||
def _execute(self, w, **vargs):
|
||||
path = _resolve_path(w)
|
||||
try:
|
||||
os.remove(path)
|
||||
w.set_error("deleted %r " % path)
|
||||
except:
|
||||
w.set_error("failed to delete %r" % path)
|
||||
c = w.logical_cursor()
|
||||
w.buffer.reload()
|
||||
#w.cursor = Point(c.x, min(c.y, len(w.buffer.lines) - 1))
|
||||
#w.cursor = Point(0, min(c.y, len(w.buffer.lines) - 1))
|
||||
w.cursor = Point(0, 0)
|
||||
class OpenPath(method.Method):
|
||||
def _execute(self, w, **vargs):
|
||||
assert w.buffer.btype == 'dir'
|
||||
c = w.logical_cursor()
|
||||
p = Point(0, c.y)
|
||||
t = w.get_next_token_by_type(p, 'name')
|
||||
path = os.path.join(w.buffer.path, t.string)
|
||||
path = _resolve_path(w)
|
||||
w.set_error("opening %r" % path)
|
||||
w.application.methods['open-file'].execute(w, filename=path)
|
||||
class RefreshView(method.Method):
|
||||
def _execute(self, w, **vargs):
|
||||
c = w.logical_cursor()
|
||||
t = _resolve_token(w)
|
||||
s = t.string
|
||||
w.buffer.reload()
|
||||
w.cursor = Point(c.x, 0)
|
||||
found = False
|
||||
while not found and w.cursor.y < len(w.buffer.lines):
|
||||
t = _resolve_token(w)
|
||||
if t.string == s:
|
||||
found = True
|
||||
else:
|
||||
w.cursor = Point(c.x, w.cursor.y + 1)
|
||||
if not found:
|
||||
w.cursor = Point(0, 0)
|
||||
|
|
Loading…
Reference in New Issue