示例#1
0
def tarload(request, *args, **kwargs):
    """
    Download group of files in TAR format
    @param path    : Relative path of target files  
    @param files[] : List of files
    """        
    path        = request.POST.get('path')
    files       = request.POST.getlist('files[]')
    
    # 권한 확인
    fileManager = CELLAR_FileManager(request)
    if path is None or not fileManager.isReadable(path) :
        raise PermissionDenied
     
    dirs = path.split("/");
    while "" in dirs :
        dirs.remove("")
    dirs.reverse()
 
    tarStream = TarStream.open(fileManager.getFullPath(path), 128)
    for file in files :
        tarStream.add(file)
     
    response = StreamingHttpResponse(tarStream, content_type='application/x-tar')
    response['Content-Length'] = tarStream.getTarSize() 
    response['Content-Disposition'] = 'attachment'
        
    return response
示例#2
0
def deleteFiles(request, *args, **kwargs): 
    """
    return {
        ...
        exts : [(ext, errno), ...]
    }
     
    0 : 성공
    1 : 대상이 경로입니다
    2 : -
    3 : 허용되지 않은 요청입니다
    4 : 오류가 발생하였습니다
    5 : 권한 없음
    """     
    groupPath   = request.POST.get("groupPath")
    exts        = request.POST.getlist("exts[]")
     
      
    targetPath  = os.path.normpath(os.path.dirname(groupPath)) + "/"
    filegroup   = os.path.basename(groupPath)
    filenames   = []
    for ext in exts :
        filenames.append(filegroup + ext)
     
    fileManager = CELLAR_FileManager(request)
    resultSet   = fileManager.rmfiles(targetPath, filenames)
    result      = []
    code        = 0
    
    info("file.delete : {0}".format(fileManager.getFullPath(groupPath))) 
    for row in resultSet :
        ext = os.path.splitext(row[0])[1]
        result.append((ext, row[1]))
        if row[1] == 0 :
            ok("file.delete : {0}".format(ext))
        else :
            error("dir.delete : E{0} {1}".format(code, ext))
        
        if row[1] is not 0 :
            code = row[1]
     
    message = {
        0 : "성공",
        1 : "대상이 경로입니다",
        2 : "",
        3 : "허용되지 않은 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한 없음"
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "groupPath" : groupPath,
        "result"    : result  
    }
    return HttpResponse(json.dumps(response))
示例#3
0
def getUserAuthority(request, *args, **kwargs):
    path = request.POST.get("path")
    fileManager = CELLAR_FileManager(request)
    response = {
        "code"      : 0,
        "message"   : "",
        "path"      : path,
        "register"  : False,
        "readable"  : fileManager.isReadable(path),
        "writeable" : fileManager.isWriteable(path),
        "deletable" : fileManager.isDeletable(path)
    }
     
    return HttpResponse(json.dumps(response))
示例#4
0
def renameGroup(request, *args, **kwargs):
    """
    * Common 
    0 : "SUCCESS",
    1 : "파일을 찾을 수 없습니다",
    2 : "변경하려는 대상이 존재합니다",
    3 : "허용되지 않는 요청입니다",
    4 : "오류가 발생하였습니다",
    5 : "권한이 없습니다",
     
    * Additional 
    dstGroup    : New group path. Not valid in error. 
    result      : [ (ext, errno, dstPath), (ext, errno dstPath), ... ] 
    """
       
    srcGroup = request.POST.get('srcGroup');
    srcExts = request.POST.getlist('srcExts[]');
    dst = request.POST.get('dst');
    dstGroup = os.path.normpath(srcGroup + os.path.sep + os.pardir + os.path.sep + dst) 
     
    fileManager = CELLAR_FileManager(request) 
    result = []
    code = 0
     
    for ext in srcExts :
        newPath = ""
        srcPath = srcGroup + ext
        dstPath = dstGroup + ext
        errno = fileManager.rename(srcPath, dstPath)
        if errno :  code = errno
        else : newPath = dstPath
         
        result.append([ext, errno, newPath])
         
    message = {
        0 : "SUCCESS",
        1 : "파일/경로를 찾을 수 없습니다",
        2 : "변경하려는 대상이 존재합니다",
        3 : "허용되지 않는 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한이 없습니다",
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "dstGroup"  : dstGroup,
        "result"    : result  
    }
    return HttpResponse(json.dumps(response))
示例#5
0
def move(request, *args, **kwargs):
    """
    * Common 
    0 : "SUCCESS",
    1 : "파일/경로를 찾을 수 없습니다",
    2 : "이동하려는 위치가 파일입니다",
    3 : "허용되지 않는 요청입니다",
    4 : "오류가 발생하였습니다",
    5 : "권한이 없습니다",
     
    * Additional 
    dstPath : Destination path
    result  : [ (target, errno, newPath), (target, errnom newPath), ... ] 
    """
    
    targets = request.POST.getlist("targets[]")
    dstPath = request.POST.get("dstPath")
    fileManager = CELLAR_FileManager(request)
     
    result = []
    code = 0
    for target in targets :
        newPath = ""
        errno = fileManager.move(target, dstPath)
        if errno :  code = errno
        else : newPath = dstPath + os.path.basename(os.path.normpath(target))
         
        result.append([target, errno, newPath + "/"])
     
    message = {
        0 : "SUCCESS",
        1 : "파일/경로를 찾을 수 없습니다",
        2 : "변경하려는 위치가 파일입니다",
        3 : "허용되지 않는 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한이 없습니다",
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "dstPath"   : dstPath,
        "result"    : result  
    }
    return HttpResponse(json.dumps(response)) 
示例#6
0
def download(request, *args, **kwargs):
    """
    Download a file
    @param kwargs:    
        filepath    : Relative file path of target file. Root is user home.
    """
    
    target = kwargs['filepath']
    
    # Authority Check
    fileManager = CELLAR_FileManager(request)
    if target is None or not fileManager.isReadable(os.path.dirname(target)) :
        raise PermissionDenied
    
    fullPath = UserInfo.getUserInfo(request).getHomePath() + "/" + target
    response = StreamingHttpResponse(FileWrapper(open(fullPath, mode='rb')), content_type='application/octet-stream')
    response['Content-Length'] = os.path.getsize(fullPath)    
    response['Content-Disposition'] = 'attachment'
     
    return response
示例#7
0
def createDir(request, *args, **kwargs):
    """
    * Common 
    0 : "SUCCESS",
    1 : "생성 위치가 존재하지 않습니다",
    2 : "생성 위치가 파일입니다",
    3 : "허용되지 않는 요청입니다",
    4 : "오류가 발생하였습니다",
    5 : "권한이 없습니다",
     
    * Additional 
    newPath : 생성된 새 경로 
    """
    
    parentPath  = request.POST.get("parentPath")
    dirName     = request.POST.get("dirName")
    newPath     = parentPath + dirName + "/"
    
    fileManager = CELLAR_FileManager(request) 
    code = fileManager.mkdir(parentPath, dirName)
          
    message = {
        0 : "SUCCESS",
        1 : "생성 위치가 존재하지 않습니다",
        2 : "생성 위치가 파일입니다",
        3 : "허용되지 않는 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한이 없습니다",
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "newPath"   : newPath,
    }
    
    if code == 0 :
        ok("dir.create : {0}".format(fileManager.getFullPath(newPath)))
    else :
        error("dir.create : E{0} {1}".format(code, fileManager.getFullPath(newPath)))
    return HttpResponse(json.dumps(response)) 
示例#8
0
def upload(request, *args, **kwargs):
    response = { 
        "status"    : "success", 
        "message"   : "" 
    }
    
    fileManager = CELLAR_FileManager(request)
    filename    = request.POST.get("name")
    cwd         = request.POST.get("cwd")
    if cwd is None or not fileManager.isWriteable(cwd) :
        response["status"] = "error"
        response["message"] = "해당 경로에 쓰기 권한이 없습니다."
        return HttpResponseServerError(json.dumps(response))
     
    file = request.FILES["file"]
    if not file :
        response["status"] = "error"
        response["message"] = "파일이 정상적으로 업로드 되지 않았습니다."
        return HttpResponseServerError(json.dumps(response))
     
    dstPath = fileManager._root_norm + cwd + filename
    chunk   = int(request.POST.get("chunk"))
    chunks  = int(request.POST.get("chunks"))
     
    if chunk == 0 :
        info("Upload : " + dstPath + " start")
        mode = "wb"
    else :
        mode = "ab"
    
    info("Upload : " + dstPath + " ({0} / {1})".format(chunk + 1, chunks)) 
    with open(dstPath, mode) as destination:
        destination.write(file.file.read())
    file.file.close()
    
    if chunk + 1 == chunks :
        info("Upload : " + dstPath + " finished")
        
    return HttpResponse(json.dumps(response)) 
示例#9
0
def rename(request, *args, **kwargs):
    """
    * Common 
    0 : "SUCCESS",
    1 : "파일/경로를 찾을 수 없습니다",
    2 : "변경하려는 대상이 존재합니다",
    3 : "허용되지 않는 요청입니다",
    4 : "오류가 발생하였습니다",
    5 : "권한이 없습니다",
     
    * Additional 
    dst     : New name. Not valid in error.
    dstPath : New path. Not valid in error. 
    """
    
    srcPath = request.POST.get('srcPath');
    dst     = request.POST.get('dst');
    dstPath = os.path.normpath(srcPath + os.path.sep + os.pardir + os.path.sep + dst)
    fileManager = CELLAR_FileManager(request) 
    code = fileManager.rename(srcPath, dstPath)
    if code == 0 and os.path.isdir(fileManager.getFullPath(dstPath)) :
        dstPath += "/"
         
    message = {
        0 : "SUCCESS",
        1 : "파일/경로를 찾을 수 없습니다",
        2 : "변경하려는 대상이 존재합니다",
        3 : "허용되지 않는 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한이 없습니다",
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "dst"       : dst,
        "dstPath"   : dstPath
    }
    return HttpResponse(json.dumps(response))
示例#10
0
def deleteDir(request, *args, **kwargs):
    """
    0 : 성공
    1 : 대상이 파일입니다
    2 : -
    3 : 허용되지 않은 요청입니다
    4 : 오류가 발생하였습니다
    5 : 권한 없음
    """
     
    dirPath = request.POST.get("dirPath")
    
     
    fileManager = CELLAR_FileManager(request) 
    code = fileManager.rmdir(dirPath)
     
    message = {
        0 : "성공",
        1 : "대상이 파일입니다",
        2 : "",
        3 : "허용되지 않은 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한 없음"
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "dirPath"   : dirPath  
    }
    
    if code == 0 :
        ok("dir.delete : {0}".format(fileManager.getFullPath(dirPath)))
    else :
        error("dir.delete : E{0} {1}".format(code, fileManager.getFullPath(dirPath)))
        
    return HttpResponse(json.dumps(response))