import grp, os, pwd from point2 import Point def resolve_token(w): c = w.logical_cursor() p = Point(0, c.y) return w.get_next_token_by_type(p, 'name') def resolve_name(w): t = resolve_token(w) return t.string def resolve_path(w): name = resolve_name(w) path = os.path.join(w.buffer.path, name) 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)) def valid_owner(owner): if not owner: return False elif owner.isdigit(): return True try: pwd.getpwnam(owner) return True except: return False def valid_group(group): if not group: return False elif group.isdigit(): return True try: grp.getgrnam(group) return True except: return False