Пример #1
0
def getFsFromKey(key, username):
    if key in sources.keys():
        source = sources[key]
        root_path = source['params']['root_path'] + username
        cur_fs = source['cls'](root_path)
        return cur_fs
    else:
        return None
Пример #2
0
def getFsFromKey(key, username):
    if key in sources.keys():
        source = sources[key]
        root_path = source['params']['root_path'] + username
        cur_fs = source['cls'](root_path)
        return cur_fs
    else:
        return None
Пример #3
0
def api( request ):
    cmd = request.POST.get('cmd', request.GET.get('cmd'))
    if not cmd:
        raise Http404
    
    # todo: remove these special cases
    if cmd == 'delete':
        root, path = splitPath( request.POST['file'] )
    elif cmd in ['view', 'download']:
        root, path = splitPath( request.GET['file'] )
    elif cmd == 'rename':
        root, path = splitPath( request.POST['oldname'] )
    else:
        root, path = splitPath( request.POST['path'] )
        
    if root:
        cur_fs = getFsFromKey( root )
    
    if cmd == 'get':
        if not root:
            items = []
            for item in sources.keys():
                row = {
                    'text':item
                    ,'size':0
                    ,'iconCls':'test'
                    ,'modified_time':''
                    ,'created_time':''
                    ,'leaf':False
                }
                items.append( row )
            return items
        return dirToJson( cur_fs, path, recursive = False )
    elif cmd == 'newdir':
        cur_fs.makedir( path )
        return {'success':True}
    elif cmd == 'rename':
        # todo : handle FS level moves
        root2, path2 = splitPath( request.POST['newname'] )
        if root == root2:
            # same FS
            cur_fs.rename( path, path2 )
        else:
            # different FS
            cur_fs2 = getFsFromKey( root2 )
            inFile = cur_fs.open( path, 'rb' )
            outFile = cur_fs2.open( path2, 'wb' ) 
            outFile.write( inFile.read() )
            outFile.close()
            
        return {'success':True}
    elif cmd == 'delete':
        if cur_fs.isdir( path ):
            cur_fs.removedir( path )
        else:
            cur_fs.remove( path )
        return {'success':True}
    elif cmd == 'view':
        # todo redir to APACHE or OTHER
        file = cur_fs.open( path, 'rb' )
        return download( path, file)
    elif cmd == 'download':
        # todo redir to APACHE or OTHER
        file = cur_fs.open( path, 'rb' )
        return download( path, file, attachment = True)
        
    return {'success':False, 'msg':'Erreur'}
Пример #4
0
def api(request):
    cmd = request.POST.get('cmd', request.GET.get('cmd'))
    if not cmd:
        raise Http404

    # todo: remove these special cases
    if cmd == 'delete':
        root, path = splitPath(request.POST['file'])
    elif cmd in ['view', 'download']:
        root, path = splitPath(request.GET['file'])
    elif cmd == 'rename':
        root, path = splitPath(request.POST['oldname'])
    else:
        root, path = splitPath(request.POST['path'])

    if root:
        cur_fs = getFsFromKey(root)

    if cmd == 'get':
        if not root:
            items = []
            for item in sources.keys():
                row = {
                    'text': item,
                    'size': 0,
                    'iconCls': 'test',
                    'modified_time': '',
                    'created_time': '',
                    'leaf': False
                }
                items.append(row)
            return items
        return dirToJson(cur_fs, path, recursive=False)
    elif cmd == 'newdir':
        cur_fs.makedir(path)
        return {'success': True}
    elif cmd == 'rename':
        # todo : handle FS level moves
        root2, path2 = splitPath(request.POST['newname'])
        if root == root2:
            # same FS
            cur_fs.rename(path, path2)
        else:
            # different FS
            cur_fs2 = getFsFromKey(root2)
            inFile = cur_fs.open(path, 'rb')
            outFile = cur_fs2.open(path2, 'wb')
            outFile.write(inFile.read())
            outFile.close()

        return {'success': True}
    elif cmd == 'delete':
        if cur_fs.isdir(path):
            cur_fs.removedir(path)
        else:
            cur_fs.remove(path)
        return {'success': True}
    elif cmd == 'view':
        # todo redir to APACHE or OTHER
        file = cur_fs.open(path, 'rb')
        return download(path, file)
    elif cmd == 'download':
        # todo redir to APACHE or OTHER
        file = cur_fs.open(path, 'rb')
        return download(path, file, attachment=True)

    return {'success': False, 'msg': 'Erreur'}