Пример #1
0
    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)
Пример #2
0
    def DELETE(self, *arg, **params):
        intent = params.get('intent', None)
        if intent == 'traversal':
            return self._cancelTraversalFolder(arg)
        path = self._formatPath(arg, params)
        try:
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.remove(path)
                ProfileFunc.delFileCache(path)
#                 removeSql = "delete from fileCache where url='%s'"%path
#                 ProfileFunc.execSubLibrarySqlbyPath(path, removeSql)
        except Exception, e:
            Log.exception('Files DELETE Excepted! Reason[%s]' % e)
            raise cherrypy.HTTPError(463, 'Not Permitted')