def _scanFolder(self, scanPath, diskPath, recursive=False, scanType='all'): folder = unicode(scanPath.replace('\\', '/')) if not os.path.exists(folder): return for sub_file in os.listdir(folder): if not recursive and not { 'folder': scanPath, 'type': scanType } in self.folders[diskPath]['folders']: return if sub_file == '.popoCloud' or sub_file == '.cameraApp': continue path = unicode(os.path.join(folder, sub_file)) if not os.path.exists(path) or sub_file[ -4:] == ".lnk" or UtilFunc.isHiddenFile(path): continue if UtilFunc.isShorcut(path): path = UtilFunc.getShortcutRealPath(path) if path and os.path.isdir(path): self.mainService.folderMoniter.addDisk(path) if os.path.isdir(path): if recursive: self._scanFolder(path, diskPath, recursive) continue ProfileFunc.addFileCache(path, scanType)
def run(self): dirName = self.dirPath hdir = win32file.CreateFile( dirName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, win32security.SECURITY_ATTRIBUTES(), OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0) filter = FILE_NOTIFY_CHANGE_FILE_NAME | \ FILE_NOTIFY_CHANGE_DIR_NAME \ | FILE_NOTIFY_CHANGE_ATTRIBUTES | \ FILE_NOTIFY_CHANGE_LAST_WRITE | \ FILE_NOTIFY_CHANGE_SIZE win32Handle = win32file.FindFirstChangeNotification( dirName, True, filter) while UtilFunc.programIsRunning(): results = win32file.ReadDirectoryChangesW( hdir, 819600, True, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | \ FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE | \ FILE_NOTIFY_CHANGE_CREATION, # FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_LAST_ACCESS |FILE_NOTIFY_CHANGE_SECURITY None, None ) for action, file in results: path = file if path == 'Thumbs.db': continue path = os.path.join(dirName, path) path = path.replace('\\', '/') if '/.popoCloud/' in path or os.path.basename( path) == '.popoCloud': continue # print str(action) + " " + path if action == 1 or action == 5: if os.path.isdir(path): ProfileFunc.addToLibrary(path) else: ProfileFunc.addFileCache(path) elif action == 2 or action == 4: ProfileFunc.delFileCache(path) elif action == 3: if not os.path.isdir(path): ProfileFunc.delFileCache(path) ProfileFunc.addFileCache(path) win32file.FindNextChangeNotification(win32Handle)
def POST(self, *arg, **params): #path = self._formatPath(arg, params, False) path = UtilFunc.getDefaultPath(self._formatPath(arg, params, False)) onExist, intent = params.get('onExist', None), params.get('intent', None) if intent == 'newFolder': return _createFolder(path, params) elif intent == 'newFile': return _createFile(path, onExist, params) elif intent == 'traversal': return self._traversalFolder(path) if not intent and os.path.isdir(path): raise cherrypy.HTTPError(460, 'Bad Parameter') if os.path.exists(path) and onExist == 'error': raise cherrypy.HTTPError(469, 'Already Exist') parentfolder = os.path.dirname(path) lcHDRS = { key.lower(): val for key, val in cherrypy.request.headers.iteritems() } size = int(lcHDRS.get('content-length')) free, capacity = UtilFunc.getRemainSpace(path) if free < size / 1024: raise cherrypy.HTTPError(467, 'Not Enough Disk Space') try: if not os.path.exists(parentfolder): os.makedirs(parentfolder) tmp_file = self._upload(path, size) if not tmp_file: raise cherrypy.HTTPError(463, 'Not Permitted') if not onExist or onExist == 'overwrite': if os.path.exists(path): os.remove(path) elif onExist == 'rename': path = UtilFunc.setFileName(path) os.renames(tmp_file, path) ProfileFunc.addFileCache(path) UtilFunc.setFileTime(path, params.get('lastModify', None)) # image_md5 = params.get('isAutoUpload',False) # if image_md5: # ProfileFunc.execImageCacheSql(parentfolder, "insert into imageCache(name) values(?)", (image_md5,)) except Exception, e: Log.exception('Upload File Failed! Reason[%s]' % e) raise cherrypy.HTTPError(463, 'Not Permitted')
if statInfo: fileInfo['lastModify'] = getUtcTime(statInfo.st_mtime) fileInfo['creationTime'] = getUtcTime(statInfo.st_ctime) else: fileInfo['lastModify'] = 0 fileInfo['creationTime'] = 0 if os.path.isfile(fileFullPath): fileInfo['isFolder'] = 'False' fileInfo['contentLength'] = statInfo.st_size fileInfo['contentType'] = getFileExt(fileFullPath) fileInfo['ETag'] = getFileEtag(fileFullPath) fileInfo['id'] = encryptDesKey(fileFullPath) if flag: ProfileFunc.addFileCache(fileFullPath) ret = SqliteFunc.tableSelect(SqliteFunc.TB_CACHE, ['remarks'], 'url = ?', (fileFullPath, )) if ret: fileInfo['remarks'] = ret[0]['remarks'] else: fileInfo['isFolder'] = 'True' return fileInfo def formatFilesRet(datas, params): ret = [] for fileInfo in iter(datas): path = unicode(fileInfo['url'])