def createfolder(): if request.method == "POST": userId = RetrieveSessionDetails('userId') currentFolderId = RetrieveSessionDetails('currentFolderId') foldername = request.form.get('folder') folderobj = BusinessLayer.createfolder(userId,currentFolderId,foldername) if folderobj != None: UserData = BusinessLayer.getFolderContents(userId,currentFolderId) path = BusinessLayer.getPathForFolder(userId,currentFolderId) print("APP_STORAGE_PATH: ",APP_STORAGE_PATH) target = APP_STORAGE_PATH+path destination = target+foldername if not os.path.isdir(destination): os.mkdir(destination) return redirect(url_for('index',folderId = currentFolderId)) else: return render_template("404.html") else: return render_template("404.html")
def deleteFile(fileId, filename): userId = RetrieveSessionDetails('userId') currentFolderId = RetrieveSessionDetails('currentFolderId') parentFolderId, parentfolderName = BusinessLayer.getParentFolderForFile( fileId, userId) print("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk: ", parentFolderId) print("llllllllllllllllllllllllllllllllllllllllll: ", parentfolderName) flag = BusinessLayer.RemoveExisitngFile(userId, currentFolderId, fileId, filename) if flag == True: try: path = BusinessLayer.getPathForFolder(userId, parentFolderId) target = os.path.join(APP_STORAGE_PATH, path) destination = "/".join([target, filename]) os.remove(destination) AddToSession('TotalSize', BusinessLayer.getTotalSize(userId)) except OSError: pass return redirect(url_for('index', folderId=currentFolderId))
def index(folderId): userId = RetrieveSessionDetails('userId') AddToSession('currentFolderId', folderId) foldername = BusinessLayer.getPathForFolder(userId, folderId) foldername = foldername[:-1] AddToSession('currentFolderName', foldername) #keyToAdd = 'PFDEL_'+foldername #AddToSession('directory_home',foldername) UserData = BusinessLayer.getFolderContents(userId, folderId) UserData["sourceParameter"] = "NotsearchIndex" UserData["AllFilesource"] = "NotAllFileSource" # if BusinessLayer.getHomeFolderId(folderId) == folderId: # UserData["homefolder"] = "home" # else: # UserData["homefolder"] = "nothome" userclassInstance = UserClass() userclassInstance.setUserDetails(RetrieveSessionDetails('userId'), RetrieveSessionDetails('userName'), "passwd", "name", "email", "phone") userclassInstance.setCurrentFolderId( RetrieveSessionDetails('currentFolderId')) userclassInstance.setCurrentFolderName( RetrieveSessionDetails('currentFolderName')) userclassInstance.setHomeFolderId(RetrieveSessionDetails('homeFolderId')) UserData['TotalSize'] = RetrieveSessionDetails('TotalSize') UserData['UserDetails'] = userclassInstance return render_template('index.html', **UserData)
def moveFile(fileId, fileName): print("File id to move is: ", fileId, " and filename to move is: ", fileName) currentFolderId = RetrieveSessionDetails('currentFolderId') userId = RetrieveSessionDetails('userId') if 'newParentFolderId' in session: newParentFolderId = session['newParentFolderId'] if BusinessLayer.CheckFilePresent(fileName, newParentFolderId, userId) == True: print( "File cannot be moved at destination as a file with same name already present at destination...." ) session.pop('newParentFolderId', None) return redirect(url_for('index', folderId=currentFolderId)) if BusinessLayer.setNewParentFolderForFile(fileId, userId, newParentFolderId) == False: print("---Unable to update new Parent folder of file in DB") session.pop('newParentFolderId', None) return redirect(url_for('index', folderId=currentFolderId)) srcPath = APP_STORAGE_PATH srcPath += BusinessLayer.getPathForFolder(userId, currentFolderId) srcPath += fileName print("-------File src path is: ", srcPath) destPath = APP_STORAGE_PATH destPath += BusinessLayer.getPathForFolder(userId, newParentFolderId) destPath += fileName print("------Destination path is: ", destPath) try: os.rename(srcPath, destPath) session.pop('newParentFolderId', None) print("----OH YEAH!! File successfully moved----") except OSError: print("-------OH NO!!! Unable to move file---------") else: print("Key not present in session") return redirect(url_for('index', folderId=currentFolderId))
def upload(): if request.method == "POST": userId = RetrieveSessionDetails('userId') currentFolderId = RetrieveSessionDetails('currentFolderId') print("userId: ", userId) print("currentFolderId: ", currentFolderId) path = BusinessLayer.getPathForFolder(userId, currentFolderId) print("path: ", path) target = os.path.join(APP_STORAGE_PATH, path) print("Target path: ", target) if not os.path.isdir(target): os.mkdir(target) for upload in request.files.getlist("file"): filename = upload.filename destination = "/".join([target, filename]) upload.save(destination) file_size = os.stat(destination).st_size print("file size: ", file_size) fileObj = FileClass() fileObj.setFileDetails(46, filename, 0, file_size, userId, currentFolderId) fileObj = BusinessLayer.createFile(fileObj, userId, currentFolderId) print(fileObj) UserData = BusinessLayer.getFolderContents(userId, currentFolderId) AddToSession('TotalSize', BusinessLayer.getTotalSize(userId)) return redirect(url_for('index', folderId=currentFolderId)) else: return render_template("404.html")
def deleteFolder(folderId, foldername): userId = RetrieveSessionDetails('userId') currentFolderId = RetrieveSessionDetails('currentFolderId') path = BusinessLayer.getPathForFolder(userId, folderId) flag = BusinessLayer.RemoveExisitngFolder(userId, currentFolderId, folderId, foldername) if flag == 1: target = os.path.join(APP_STORAGE_PATH, path) print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa target: ", target) shutil.rmtree(target) AddToSession('TotalSize', BusinessLayer.getTotalSize(userId)) AddToSession('TotalSize', BusinessLayer.getTotalSize(userId)) return redirect(url_for('index', folderId=currentFolderId))
def index(folderId): userId = RetrieveSessionDetails('userId') AddToSession('currentFolderId',folderId) foldername = BusinessLayer.getPathForFolder(userId,folderId) foldername = foldername[:-1] AddToSession('currentFolderName',foldername) #keyToAdd = 'PFDEL_'+foldername #AddToSession('directory_home',foldername) UserData = BusinessLayer.getFolderContents(userId, folderId) userclassInstance = UserClass() userclassInstance.setUserDetails(RetrieveSessionDetails('userId'),RetrieveSessionDetails('userName'),"passwd","name","email","phone") userclassInstance.setCurrentFolderId(RetrieveSessionDetails('currentFolderId')) userclassInstance.setCurrentFolderName(RetrieveSessionDetails('currentFolderName')) userclassInstance.setHomeFolderId(RetrieveSessionDetails('homeFolderId')) UserData['TotalSize'] = RetrieveSessionDetails('TotalSize') UserData['UserDetails'] = userclassInstance return render_template('index.html', **UserData)
def openfile(fileId, fileName): userId = RetrieveSessionDetails('userId') parentFolderId, parentfolderName = BusinessLayer.getParentFolderForFile( fileId, userId) print("///////////////////////////////////////", parentFolderId, parentfolderName) path = BusinessLayer.getPathForFolder(userId, parentFolderId) target = os.path.join(APP_STORAGE_PATH, path) mime = MimeTypes() url = urllib.request.pathname2url(target) mime_type = mime.guess_type(url) print(mime_type) return send_from_directory(directory=target, filename=fileName, mimetype=mime_type[0])