コード例 #1
0
ファイル: baidufuse.py プロジェクト: amutu/baidufuse
class BaiduFS(Fuse):
    '''Baidu netdisk filesystem'''

    def __init__(self, *args, **kw):
        Fuse.__init__(self, *args, **kw)
        self.disk = BaiduPan(Baidufuseconf.baidu_token)

    def get_abs_path(self, path):
        return "%s%s" % (baidu_rootdir, path)

    def getattr(self, path):
        logger.error("getattr is: " + path)
        abs_path = self.get_abs_path(path)
        st = MyStat()
        jdata = json.loads(self.disk.meta(abs_path))
        if 'list' not in jdata:
            logger.error("getattr is None")
            return -errno.ENOENT
        st.st_ctime = jdata['list'][0]['ctime']
        st.st_mtime = jdata['list'][0]['mtime']
        st.st_mode = (stat.S_IFDIR | 0755) if jdata['list'][0]['isdir']\
            else (stat.S_IFREG | 0755)
        st.st_nlink = 2 if jdata['list'][0]['isdir'] else 1
        st.st_size = jdata['list'][0]['size']
        return st

    def readdir(self, path, offset):
        logger.error("readdir is: " + path)
        abs_path = self.get_abs_path(path)
        jdata = json.loads(self.disk.ls(abs_path))
        files = ['.', '..']
        for r in jdata['list']:
            files.append(r['path'].encode('ascii', 'ignore')[len(abs_path):])
        logger.error(files)
        for r in files:
            yield fuse.Direntry(r)

    def open(self, path, flags):
        logger.error("open is: " + path)
        pass
        accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
        if (flags & accmode) != os.O_RDONLY:
            return -errno.EACCES

    def mkdir(self, path, mode):
        logger.error("mkdir is:" + path)
        abs_path = self.get_abs_path(path)
        self.disk.mkdir(abs_path)

    def rmdir(self, path):
        logger.error("rmdir is:" + path)
        abs_path = self.get_abs_path(path)
        self.disk.rm(abs_path)

    def read(self, path, size, offset):
        logger.error("read is: " + path)
        abs_path = self.get_abs_path(path)
        paras = {'Range': 'bytes=%s-%s' % (offset, offset + size)}
        return self.disk.download(abs_path, paras)
コード例 #2
0
ファイル: baidufuse.py プロジェクト: bohai/baidufuse
class BaiduFS(Fuse):
    '''Baidu netdisk filesystem'''
    def __init__(self, *args, **kw):
        Fuse.__init__(self, *args, **kw)
        self.disk = BaiduPan(Baidufuseconf.baidu_token)

    def get_abs_path(self, path):
        return "%s%s" % (Baidufuseconf.baidu_rootdir, path)

    def getattr(self, path):
        logger.error("getattr is: " + path)
        abs_path = self.get_abs_path(path)
        st = MyStat()
        jdata = json.loads(self.disk.meta(abs_path))
        if 'list' not in jdata:
            logger.error("getattr is None")
            return -errno.ENOENT
        st.st_ctime = jdata['list'][0]['ctime']
        st.st_mtime = jdata['list'][0]['mtime']
        st.st_mode = (stat.S_IFDIR | 0755) if jdata['list'][0]['isdir']\
            else (stat.S_IFREG | 0755)
        st.st_nlink = 2 if jdata['list'][0]['isdir'] else 1
        st.st_size = jdata['list'][0]['size']
        return st

    def readdir(self, path, offset):
        logger.error("readdir is: " + path)
        abs_path = self.get_abs_path(path)
        jdata = json.loads(self.disk.ls(abs_path))
        files = ['.', '..']
        for r in jdata['list']:
            files.append(r['path'].encode('ascii', 'ignore')[len(abs_path):])
        logger.error(files)
        for r in files:
            yield fuse.Direntry(r)

    def open(self, path, flags):
        logger.error("open is: " + path)
        pass
        accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
        if (flags & accmode) != os.O_RDONLY:
            return -errno.EACCES

    def mkdir(self, path, mode):
        logger.error("mkdir is:" + path)
        abs_path = self.get_abs_path(path)
        self.disk.mkdir(abs_path)

    def rmdir(self, path):
        logger.error("rmdir is:" + path)
        abs_path = self.get_abs_path(path)
        self.disk.rm(abs_path)

    def read(self, path, size, offset):
        logger.error("read is: " + path)
        abs_path = self.get_abs_path(path)
        paras = {'Range': 'Range: bytes=%s-%s' % (offset, offset + size)}
        return self.disk.download(abs_path, headers=paras)
コード例 #3
0
 #quota
 print disk.quota()
 #upload
 print disk.upload('hello', path='/apps/appname/hello.txt')
 #merge
 '''
 def merge(self, path, param, **kw):
     self.urlpath = 'file'
     self.method = 'createsuperfile'
     self._method = 'POST'
     return self._request(path=path, param=param, **kw)
 '''
 param = ''
 print disk.merge('/apps/appname/hello.txt', param=param)
 #download
 print disk.download(path='/apps/appname/hello.txt')
 print disk.download(path='/apps/appname/hello.txt',
                     headers={"Range": "Range: bytes:1-100"})
 #mkdir
 print disk.mkdir('/apps/appname/dirname')
 #meta
 print disk.meta('/apps/appname/filename')
 #mmeta
 print disk.mmeta(json.dumps({"list": [{"path": "/apps/appname/"}]}))
 #ls
 print disk.ls("/apps/appname/")
 #mv
 print disk.mv("/apps/appname/hello.txt", "/apps/appname/hello.txt.bak")
 #mmv
 par = {
     "list": [{
コード例 #4
0
ファイル: baifuse.py プロジェクト: tbronchain/baifuse
class BaiFuse(LoggingMixIn, Operations):
    def __init__(self, root, token):
        self.root = root
        self.token = token
        self.api = BaiduPan(self.token)

    def get_path(self, path):
        return os.path.join(BAIDUPATH,path)

#    def chmod(self, path, mode):
#        return True

#    def chown(self, path, uid, gid):
#        return True

#    def create(self, path, mode):
#        f = self.sftp.open(path, 'w')
#        f.chmod(mode)
#        f.close()
#        return 0

#    def destroy(self, path):
#        self.sftp.close()
#        self.client.close()

    def getattr(self, path, fh=None):
        resp = json.loads(self.api.meta(self.get_path(path)))
        if 'list' not in resp:
            return {}
        return {
            'st_ino': 0,
            'st_dev': 0,
            'st_atime': 0,
            'st_mtime': resp['list'][0]['mtime'],
            'st_ctime': resp['list'][0]['ctime'],
            'st_gid': os.getgid(),
            'st_uid': os.getuid(),
            'st_mode': ((stat.S_IFDIR | 0755) if resp['list'][0]['isdir'] else (stat.S_IFREG | 0755)),
            'st_size': resp['list'][0]['size'],
            'st_nlink': (2 if resp['list'][0]['isdir'] else 1),
            }

    def mkdir(self, path, mode):
        self.api.mkdir(self.get_path(path))
        #return?

    def read(self, path, size, offset, fh):
        return self.api.download(self.get_path(path),
                                 headers={'Range':"Range: bytes=%s-%s"%(offset,offset+size)})

    def readdir(self, path, fh):
        resp = json.loads(self.api.ls(self.get_path(path)))
        return ['.', '..'] + [name['path'].encode('utf-8') for name in resp['list']]

#    def readlink(self, path):
#        return self.sftp.readlink(path)

#    def rename(self, old, new):
#        return self.sftp.rename(old, self.root + new)

    def rmdir(self, path):
        self.api.rm(self.get_path(path))
        # return ?

#    def symlink(self, target, source):
#        return self.sftp.symlink(source, target)

#    def truncate(self, path, length, fh=None):
#        return self.sftp.truncate(path, length)

#    def unlink(self, path):
#        return self.sftp.unlink(path)

#    def utimens(self, path, times=None):
#        return self.sftp.utime(path, times)

    def write(self, path, data, offset, fh):
        # can't use the api -> need file dissociation + merge (super file)
        return self.api.upload(path)
コード例 #5
0
ファイル: example.py プロジェクト: cha0s-repo/baidupan
 #quota
 print disk.quota()
 #upload
 print disk.upload('hello', path='/apps/appname/hello.txt')
 #merge
 '''
 def merge(self, path, param, **kw):
     self.urlpath = 'file'
     self.method = 'createsuperfile'
     self._method = 'POST'
     return self._request(path=path, param=param, **kw)
 '''
 param = ''
 print disk.merge('/apps/appname/hello.txt', param=param)
 #download
 print disk.download(path='/apps/appname/hello.txt')
 #mkdir
 print disk.mkdir('/apps/appname/dirname')
 #meta
 print disk.meta('/apps/appname/filename')
 #mmeta
 print disk.mmeta(json.dumps({"list": [{"path": "/apps/appname/"}]}))
 #ls
 print disk.ls("/apps/appname/")
 #mv
 print disk.mv("/apps/appname/hello.txt", "/apps/appname/hello.txt.bak")
 #mmv
 par = {"list": [{"from": "/apps/appname/hello.txt.bak",
                  "to": "/apps/appname/hello.txt.bak.bak"},
                 {"from": "/apps/appname/dirs",
                  "to": "/apps/appname/dirsbak"}]}
コード例 #6
0
ファイル: example.py プロジェクト: JackonYang/baidupan
 #quota
 print disk.quota()
 #upload
 print disk.upload('hello', path='/apps/appname/hello.txt')
 #merge
 '''
 def merge(self, path, param, **kw):
     self.urlpath = 'file'
     self.method = 'createsuperfile'
     self._method = 'POST'
     return self._request(path=path, param=param, **kw)
 '''
 param = ''
 print disk.merge('/apps/appname/hello.txt', param=param)
 #download
 print disk.download(path='/apps/appname/hello.txt')
 print disk.download(path='/apps/appname/hello.txt',
                     headers={"Range": "Range: bytes:1-100"})
 #mkdir
 print disk.mkdir('/apps/appname/dirname')
 #meta
 print disk.meta('/apps/appname/filename')
 #mmeta
 print disk.mmeta(json.dumps({"list": [{"path": "/apps/appname/"}]}))
 #ls
 print disk.ls("/apps/appname/")
 #mv
 print disk.mv("/apps/appname/hello.txt", "/apps/appname/hello.txt.bak")
 #mmv
 par = {"list": [{"from": "/apps/appname/hello.txt.bak",
                  "to": "/apps/appname/hello.txt.bak.bak"},