Beispiel #1
0
    def __init__(self, conn=None, namespace=None, root=None):
        if not conn and namespace:
            conn = 'unix!%s/%s' % (NAMESPACE, namespace)
        try:
            self.lastfid = ROOT_FID
            self.fids = set()
            self.lock = RLock()

            def process(data):
                return fcall.Fcall.unmarshall(data)[1]

            self.mux = Mux(conn, process, maxtag=256)

            resp = self._dorpc(
                fcall.Tversion(version=pyxp.VERSION, msize=65535))
            if resp.version != pyxp.VERSION:
                raise ProtocolException, "Can't speak 9P version '%s'" % resp.version
            self.msize = resp.msize

            self._dorpc(
                fcall.Tattach(fid=ROOT_FID,
                              afid=fcall.NO_FID,
                              uname=os.environ['USER'],
                              aname=''))

            if root:
                path = self._splitpath(root)
                resp = self._dorpc(
                    fcall.Twalk(fid=ROOT_FID, newfid=ROOT_FID, wname=path))
        except Exception:
            traceback.print_exc(sys.stdout)
            if getattr(self, 'mux', None):
                self.mux.fd.close()
            raise
Beispiel #2
0
 def next(resp=None, exc=None, tb=None):
     if exc and ctxt['ofid'] != ROOT_FID:
         self._aclunk(ctxt['fid'])
     if not ctxt['path'] and resp or exc:
         if exc and fail:
             return self.respond(fail, None, exc, tb)
         return self.respond(callback, ctxt['fid'], exc, tb)
     wname = ctxt['path'][:fcall.MAX_WELEM]
     ofid = ctxt['ofid']
     ctxt['path'] = ctxt['path'][fcall.MAX_WELEM:]
     if resp:
         ctxt['ofid'] = ctxt['fid']
     self._dorpc(fcall.Twalk(fid=ofid, newfid=ctxt['fid'], wname=wname),
                 next)
Beispiel #3
0
    def _walk(self, path):
        fid = self._getfid()
        ofid = ROOT_FID
        while True:
            self._dorpc(
                fcall.Twalk(fid=ofid,
                            newfid=fid,
                            wname=path[0:fcall.MAX_WELEM]))
            path = path[fcall.MAX_WELEM:]
            ofid = fid
            if len(path) == 0:
                break

        @apply
        class Res:
            def __enter__(res):
                return fid

            def __exit__(res, exc_type, exc_value, traceback):
                if exc_type:
                    self._clunk(fid)

        return Res