parent
c2b6775ed0
commit
ccc9bea508
40
buffer2.py
40
buffer2.py
|
@ -501,8 +501,8 @@ class DirBuffer(Buffer):
|
||||||
return self._name
|
return self._name
|
||||||
def path_exists(self):
|
def path_exists(self):
|
||||||
return os.path.exists(self.path)
|
return os.path.exists(self.path)
|
||||||
|
|
||||||
def open(self):
|
def _get_lines(self):
|
||||||
if not self.path_exists():
|
if not self.path_exists():
|
||||||
raise Exception, "directory %r does not exists" % self.path
|
raise Exception, "directory %r does not exists" % self.path
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ class DirBuffer(Buffer):
|
||||||
names.insert(0, '..')
|
names.insert(0, '..')
|
||||||
names.insert(0, '.')
|
names.insert(0, '.')
|
||||||
|
|
||||||
lines = []
|
fieldlines = []
|
||||||
maxlens = [0] * 5
|
maxlens = [0] * 5
|
||||||
for name in names:
|
for name in names:
|
||||||
# let's escape some troublesome characters
|
# let's escape some troublesome characters
|
||||||
|
@ -551,6 +551,23 @@ class DirBuffer(Buffer):
|
||||||
else:
|
else:
|
||||||
perm[i] = '-'
|
perm[i] = '-'
|
||||||
i += 1
|
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)
|
perms = ''.join(perm)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -578,18 +595,21 @@ class DirBuffer(Buffer):
|
||||||
maxlens[i] = max(maxlens[i], len(fields[i]))
|
maxlens[i] = max(maxlens[i], len(fields[i]))
|
||||||
except:
|
except:
|
||||||
raise Exception, '%d %r' % (i, fields[i])
|
raise Exception, '%d %r' % (i, fields[i])
|
||||||
lines.append(fields)
|
fieldlines.append(fields)
|
||||||
|
|
||||||
lines.sort(cmp=_path_sort)
|
fieldlines.sort(cmp=_path_sort)
|
||||||
|
|
||||||
fmt = '%%%ds %%-%ds %%-%ds %%%ds %%%ds %%s' % tuple(maxlens)
|
fmt = '%%%ds %%-%ds %%-%ds %%%ds %%%ds %%s' % tuple(maxlens)
|
||||||
|
|
||||||
self.lines = []
|
lines = []
|
||||||
for fields in lines:
|
for fields in fieldlines:
|
||||||
s = fmt % fields
|
s = fmt % fields
|
||||||
self.lines.append(s)
|
lines.append(s)
|
||||||
|
return lines
|
||||||
|
def open(self):
|
||||||
|
self.lines = self._get_lines()
|
||||||
def reload(self):
|
def reload(self):
|
||||||
self.open()
|
lines = self._get_lines()
|
||||||
|
self.set_lines(lines, force=True)
|
||||||
def save(self, force=False):
|
def save(self, force=False):
|
||||||
raise Exception, "can't save a directory buffer"
|
raise Exception, "can't save a directory buffer"
|
||||||
def save_as(self, path):
|
def save_as(self, path):
|
||||||
|
|
62
mode_dir.py
62
mode_dir.py
|
@ -4,7 +4,8 @@ from point2 import Point
|
||||||
|
|
||||||
class PermGrammar(Grammar):
|
class PermGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'set', r's'),
|
PatternRule(r'sticky', r'[tT]'),
|
||||||
|
PatternRule(r'setid', r'[sS]'),
|
||||||
PatternRule(r'read', r'r'),
|
PatternRule(r'read', r'r'),
|
||||||
PatternRule(r'write', r'w'),
|
PatternRule(r'write', r'w'),
|
||||||
PatternRule(r'exec', r'x'),
|
PatternRule(r'exec', r'x'),
|
||||||
|
@ -49,12 +50,16 @@ class Dir(mode2.Fundamental):
|
||||||
'unk.start': ('magenta', 'default'),
|
'unk.start': ('magenta', 'default'),
|
||||||
'unk.name': ('magenta', 'default'),
|
'unk.name': ('magenta', 'default'),
|
||||||
|
|
||||||
'perm.set': ('red', 'default'),
|
#'perm.setid': ('red', 'default'),
|
||||||
'perm.read': ('magenta', 'default'),
|
#'perm.sticky': ('red', 'default'),
|
||||||
'perm.write': ('magenta', 'default'),
|
'perm.setid': ('yellow', 'default'),
|
||||||
'perm.exec': ('magenta', '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'),
|
'group': ('cyan', 'default'),
|
||||||
'size': ('yellow', 'default'),
|
'size': ('yellow', 'default'),
|
||||||
'mtime': ('green', 'default'),
|
'mtime': ('green', 'default'),
|
||||||
|
@ -65,9 +70,19 @@ class Dir(mode2.Fundamental):
|
||||||
self.add_action(Chown())
|
self.add_action(Chown())
|
||||||
self.add_action(Chgrp())
|
self.add_action(Chgrp())
|
||||||
self.add_action_and_bindings(OpenPath(), ('RETURN',))
|
self.add_action_and_bindings(OpenPath(), ('RETURN',))
|
||||||
|
self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d'))
|
||||||
def name(self):
|
def name(self):
|
||||||
return "Dir"
|
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):
|
class Chmod(method.Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.set_error('chmod not implemented')
|
w.set_error('chmod not implemented')
|
||||||
|
@ -78,12 +93,37 @@ class Chgrp(method.Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.set_error('chgrp not implemented')
|
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):
|
class OpenPath(method.Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
assert w.buffer.btype == 'dir'
|
path = _resolve_path(w)
|
||||||
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)
|
|
||||||
w.set_error("opening %r" % path)
|
w.set_error("opening %r" % path)
|
||||||
w.application.methods['open-file'].execute(w, filename=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