branch : pmacs2
This commit is contained in:
moculus 2007-07-20 13:53:57 +00:00
parent 5feac52d26
commit f4abeb6433
2 changed files with 109 additions and 39 deletions

View File

@ -1,4 +1,4 @@
import datetime, md5, os, pwd, re, sets, shutil, stat import datetime, grp, md5, os, pwd, re, sets, shutil, stat
import aes, regex, highlight2 import aes, regex, highlight2
from point2 import Point from point2 import Point
@ -569,13 +569,13 @@ class DirBuffer(Buffer):
perms = ''.join(perm) perms = ''.join(perm)
try: try:
usr = pwd.getpwuid(info.st_uid)[0] user = pwd.getpwuid(info.st_uid)[0]
except: except:
usr = str(info.st_uid) user = str(info.st_uid)
try: try:
grp = pwd.getpwuid(info.st_gid)[0] group = grp.getgrgid(info.st_gid)[0]
except: except:
grp = str(info.st_gid) group = str(info.st_gid)
size = info.st_size size = info.st_size
unit = 0 unit = 0
@ -587,7 +587,7 @@ class DirBuffer(Buffer):
mtime = datetime.datetime.fromtimestamp(info.st_mtime).strftime('%b %d %H:%M') mtime = datetime.datetime.fromtimestamp(info.st_mtime).strftime('%b %d %H:%M')
fields = (perms, usr, grp, size, mtime, name) fields = (perms, user, group, size, mtime, name)
for i in range(0, 5): for i in range(0, 5):
try: try:
maxlens[i] = max(maxlens[i], len(fields[i])) maxlens[i] = max(maxlens[i], len(fields[i]))

View File

@ -1,4 +1,4 @@
import method, mode2, os.path import grp, method, mode2, os.path, pwd, re
from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule
from point2 import Point from point2 import Point
from method import Method, Argument from method import Method, Argument
@ -51,15 +51,12 @@ class Dir(mode2.Fundamental):
'unk.start': ('magenta', 'default'), 'unk.start': ('magenta', 'default'),
'unk.name': ('magenta', 'default'), 'unk.name': ('magenta', 'default'),
#'perm.setid': ('red', 'default'),
#'perm.sticky': ('red', 'default'),
'perm.setid': ('yellow', 'default'), 'perm.setid': ('yellow', 'default'),
'perm.sticky': ('yellow', 'default'), 'perm.sticky': ('yellow', 'default'),
'perm.read': ('magenta', 'default'), 'perm.read': ('magenta', 'default'),
'perm.write': ('magenta', 'default'), 'perm.write': ('magenta', 'default'),
'perm.exec': ('magenta', 'default'), 'perm.exec': ('magenta', 'default'),
#'owner': ('blue', 'default'),
'owner': ('cyan', 'default'), 'owner': ('cyan', 'default'),
'group': ('cyan', 'default'), 'group': ('cyan', 'default'),
'size': ('yellow', 'default'), 'size': ('yellow', 'default'),
@ -82,57 +79,130 @@ def _resolve_token(w):
c = w.logical_cursor() c = w.logical_cursor()
p = Point(0, c.y) p = Point(0, c.y)
return w.get_next_token_by_type(p, 'name') return w.get_next_token_by_type(p, 'name')
def _resolve_path(w): def _resolve_name(w):
t = _resolve_token(w) t = _resolve_token(w)
path = os.path.join(w.buffer.path, t.string) return t.string
def _resolve_path(w):
name = _resolve_name(w)
path = os.path.join(w.buffer.path, name)
return path return path
def _find_name(w, s):
found = False
w.goto(Point(0, 0))
c = w.logical_cursor()
while not found and c.y < len(w.buffer.lines):
t = _resolve_token(w)
if t.string == s:
found = True
break
w.goto(Point(c.x, c.y + 1))
c = w.logical_cursor()
if not found:
w.goto(Point(0, 0))
class RefreshView(Method):
def _execute(self, w, **vargs):
t = _resolve_token(w)
s = t.string
w.buffer.reload()
_find_name(w, s)
class OpenPath(Method):
def _execute(self, w, **vargs):
path = _resolve_path(w)
w.set_error("opening %r" % path)
w.application.methods['open-file'].execute(w, filename=path)
class Chmod(Method): class Chmod(Method):
args = [Argument('mode', type=type(''), prompt="New Mode: ")]
octal_re = re.compile('^[0-7]{1,4}$')
symbolic_re = re.compile('(?:[ugoa]*(?:[-+=](?:[rwxXst]*|[ugo]))+ *,?)+')
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chmod not implemented') if self.octal_re.match(vargs['mode']):
pass
elif self.symbolic_re.match(vargs['mode']):
pass
else:
w.set_error("Not a valid mode: %r" % vargs['mode'])
basename = _resolve_name(w)
path = os.path.join(w.buffer.path, basename)
retval = os.system('chmod %r %r' % (vargs['mode'], path))
w.application.methods['refresh-view'].execute(w, filename=path)
_find_name(w, basename)
if retval != 0:
w.set_error("chmod %r failed (exit %d)" % (vargs['mode'], retval))
class Chown(Method): class Chown(Method):
args = [Argument('owner', type=type(''), prompt="New Owner: ")]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chown not implemented') fields = vargs['owner'].split(':')
if len(fields) == 1:
(owner, group) = (fields[0], None)
elif len(fields) == 2:
(owner, group) = fields
else:
w.set_error("Malformed 'owner' argument: %r" % vargs['owner'])
return
if not owner.isdigit():
try:
pwd.getpwnam(owner)
except:
w.set_error("User %r does not exist" % owner)
return
if group is not None and not group.isdigit():
try:
grp.getgrnam(group)
except:
w.set_error("Group %r does not exist" % group)
return
basename = _resolve_name(w)
path = os.path.join(w.buffer.path, basename)
retval = os.system('chown %r %r' % (vargs['owner'], path))
w.application.methods['refresh-view'].execute(w, filename=path)
_find_name(w, basename)
if retval != 0:
w.set_error("chown %r failed (exit %d)" % (vargs['mode'], retval))
class Chgrp(Method): class Chgrp(Method):
args = [Argument('group', type=type(''), prompt="New Group: ")]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chgrp not implemented') w.set_error('chgrp not implemented')
class TouchPath(Method): class TouchPath(Method):
args = [Argument('filename', datatype="path", prompt="Touch File: ")] args = [Argument('filename', datatype="path", prompt="Touch File: ")]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
path = vargs['filename'] basename = vargs['filename']
path = os.path.join(w.buffer.path, basename)
retval = os.system('touch %r' % path) retval = os.system('touch %r' % path)
w.application.methods['refresh-view'].execute(w, filename=path) w.application.methods['refresh-view'].execute(w, filename=path)
_find_name(w, basename)
if retval != 0: if retval != 0:
w.set_error("touch failed with exit status %d" % retval) w.set_error("touch %r failed (exit %d)" % (path, retval))
class RemovePath(Method): class RemovePath(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
path = _resolve_path(w) self._old_window = w
w.application.methods['previous-line'].execute(w) self._old_path = _resolve_path(w)
basename = os.path.basename(self._old_path)
self._prompt = "Do you want to delete %r? " % basename
w.application.open_mini_buffer(self._prompt, self._callback)
def _callback(self, v):
a = self._old_window.application
if v == 'yes':
self._doit()
a.close_mini_buffer()
return
if v == 'no':
a.close_mini_buffer()
return
a.open_mini_buffer(self._prompt, self._callback)
a.set_error('Please type "yes" or "no"')
def _doit(self):
w = self._old_window
path = self._old_path
try: try:
w.application.methods['previous-line'].execute(w)
os.remove(path) os.remove(path)
w.set_error("deleted %r " % path) w.set_error("deleted %r " % path)
w.application.methods['refresh-view'].execute(w, filename=path) w.application.methods['refresh-view'].execute(w, filename=path)
except: except:
w.set_error("failed to delete %r" % path) w.set_error("failed to delete %r" % path)
class OpenPath(Method):
def _execute(self, w, **vargs):
path = _resolve_path(w)
w.set_error("opening %r" % path)
w.application.methods['open-file'].execute(w, filename=path)
class RefreshView(Method):
def _execute(self, w, **vargs):
c = w.logical_cursor()
t = _resolve_token(w)
s = t.string
w.buffer.reload()
w.goto(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.goto(Point(c.x, w.cursor.y + 1))
if not found:
w.goto(Point(0, 0))