parent
1d2f8db085
commit
6a79d35968
33
dirutil.py
33
dirutil.py
|
@ -1,31 +1,35 @@
|
||||||
import datetime, grp, os, pwd, re, stat
|
import datetime, grp, os, pwd, re, stat
|
||||||
from point2 import Point
|
from point2 import Point
|
||||||
|
|
||||||
def resolve_token(w):
|
def resolve_token(w, y=None):
|
||||||
c = w.logical_cursor()
|
if y is None:
|
||||||
p = Point(0, c.y)
|
p = Point(0, w.logical_cursor().y)
|
||||||
|
else:
|
||||||
|
p = Point(0, y)
|
||||||
return w.get_next_token_by_type(p, 'name')
|
return w.get_next_token_by_type(p, 'name')
|
||||||
def resolve_name(w):
|
def resolve_name(w, y=None):
|
||||||
t = resolve_token(w)
|
t = resolve_token(w, y)
|
||||||
return t.string
|
return t.string
|
||||||
def resolve_path(w):
|
def resolve_path(w, y=None):
|
||||||
name = resolve_name(w)
|
name = resolve_name(w)
|
||||||
path = os.path.join(w.buffer.path, name)
|
path = os.path.join(w.buffer.path, name)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def find_name(w, s):
|
def find_name(w, s):
|
||||||
found = False
|
found = False
|
||||||
w.goto(Point(0, 0))
|
y = 0
|
||||||
c = w.logical_cursor()
|
c = w.logical_cursor()
|
||||||
while not found and c.y < len(w.buffer.lines):
|
while not found and y < len(w.buffer.lines):
|
||||||
t = resolve_token(w)
|
t = resolve_token(w, y)
|
||||||
if t.string == s:
|
if t.string == s:
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
w.goto(Point(c.x, c.y + 1))
|
y += 1
|
||||||
c = w.logical_cursor()
|
if found:
|
||||||
if not found:
|
w.application.methods['goto-line'].execute(w, lineno=y+1)
|
||||||
w.goto(Point(0, 0))
|
p = Point(c.x, y)
|
||||||
|
if not w.point_is_visible(p):
|
||||||
|
w.goto(p)
|
||||||
|
|
||||||
def valid_owner(owner):
|
def valid_owner(owner):
|
||||||
if not owner:
|
if not owner:
|
||||||
|
@ -60,7 +64,8 @@ def path_sort(a, b):
|
||||||
def path_fields(path, name):
|
def path_fields(path, name):
|
||||||
# let's escape some troublesome characters
|
# let's escape some troublesome characters
|
||||||
name = re.sub(r'([\a\b\n\r\t\v])', r'\\\1', name)
|
name = re.sub(r'([\a\b\n\r\t\v])', r'\\\1', name)
|
||||||
info = os.stat(path)
|
# don't follow links
|
||||||
|
info = os.lstat(path)
|
||||||
|
|
||||||
# - regular, b block, c character, d directory, l symlink, p fifo
|
# - regular, b block, c character, d directory, l symlink, p fifo
|
||||||
# s socket, ? unknown
|
# s socket, ? unknown
|
||||||
|
|
|
@ -112,7 +112,7 @@ class DirCmd(Method):
|
||||||
(status, output) = commands.getstatusoutput(cmd)
|
(status, output) = commands.getstatusoutput(cmd)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
w.set_error("%s failed (exit %d)" % (self.name, status))
|
w.set_error("%s failed (exit %d)" % (self.name, status))
|
||||||
w.application.methods['refresh-view'].execute(w, filename=path)
|
#w.application.methods['refresh-view'].execute(w, filename=path)
|
||||||
dirutil.find_name(w, basename)
|
dirutil.find_name(w, basename)
|
||||||
|
|
||||||
class Chmod(DirCmd):
|
class Chmod(DirCmd):
|
||||||
|
|
Loading…
Reference in New Issue