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
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))
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))
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))
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))