def pathtodir(self, f): '''Stat-to-dir conversion''' s = _os(os.lstat, f) u = uidname(s.st_uid) g = gidname(s.st_gid) res = s.st_mode & 0777 type = 0 ext = "" if stat.S_ISDIR(s.st_mode): type = type | py9p.QTDIR res = res | py9p.DMDIR qid = py9p.Qid(type, 0, py9p.hash8(f)) if self.dotu: if stat.S_ISLNK(s.st_mode): ext = os.readlink(f) ext = os.path.join(os.path.dirname(f), ext) elif stat.S_ISCHR(s.st_mode): ext = "c %d %d" % (os.major(s.st_rdev), os.minor(s.st_rdev)) elif stat.S_ISBLK(s.st_mode): ext = "b %d %d" % (os.major(s.st_rdev), os.minor(s.st_rdev)) else: ext = "" return py9p.Dir(1, 0, s.st_dev, qid, res, int(s.st_atime), int(s.st_mtime), s.st_size, os.path.basename(f), u, gidname(s.st_gid), u, ext, s.st_uid, s.st_gid, s.st_uid) else: return py9p.Dir(0, 0, s.st_dev, qid, res, int(s.st_atime), int(s.st_mtime), s.st_size, os.path.basename(f), u, g, u)
def __init__(self, name, parent, qtype=0, storage=None): py9p.Dir.__init__(self, True) self.parent = parent self.storage = storage or parent.storage self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(self.absolute_name())) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = {} self.static_children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE self.children["."] = self self.children[".."] = self.parent self.special_names = [".", ".."] else: self.mode = DEFAULT_FILE_MODE self.data = StringIO() self.special_names = [] self.storage.register(self) self.child_map = {} self.subst_map = {}
def __init__(self): self.dotu = 0 self.cancreate = 0 self.root = py9p.Dir(0) self.root.qid = py9p.Qid(py9p.QTDIR, 0, py9p.hash8('/')) self.root.localpath = '/' self.root.children = [] self.files[self.root.qid.path] = self.root for db in self.myexec("show databases"): self.root.children.append(db[0])
def pathtodir(self, f): '''Stat-to-dir conversion''' s = [] if f in self.myexec("show databases"): type = py9p.QTDIR res = py9p.DMDIR else: type = py9p.QTFILE res = 0770 qid = py9p.Qid(type, 0, py9p.hash8(f)) return py9p.Dir(1, 0, type, qid, res, 0, 0, 0, basename(f), 0, 0, 0)
def _wstat(self, tfid, path, uid=py9p.ERRUNDEF, gid=py9p.ERRUNDEF, mode=py9p.ERRUNDEF, newname=None): self.client._walk(self.client.ROOT, tfid, filter(None, path.split("/"))) if self.dotu: stats = [py9p.Dir( dotu=1, type=0, dev=0, qid=py9p.Qid(0, 0, py9p.hash8(path)), mode=mode, atime=int(time.time()), mtime=int(time.time()), length=py9p.ERRUNDEF, name=newname or path.split("/")[-1], uid="", gid="", muid="", extension="", uidnum=uid, gidnum=gid, muidnum=py9p.ERRUNDEF), ] else: stats = [py9p.Dir( dotu=0, type=0, dev=0, qid=py9p.Qid(0, 0, py9p.hash8(path)), mode=mode, atime=int(time.time()), mtime=int(time.time()), length=py9p.ERRUNDEF, name=newname or path.split("/")[-1], uid=pwd.getpwuid(uid).pw_name, gid=grp.getgrgid(gid).gr_name, muid=""), ] self.client._wstat(tfid, stats) self.client._clunk(tfid)
def __init__(self, name, qtype=0, parent=None): py9p.Dir.__init__(self, True) self.parent = parent self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(name)) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE else: self.mode = DEFAULT_FILE_MODE self.data = StringIO()
def decQ(self): return py9p.Qid(self.dec1(), self.dec4(), self.dec8())