Beispiel #1
0
    def walk_filesystem(self):
        candidates = {}
        rootpath = utils.from_unicode(self.ROOTPATH)
        for dirpath, dirnames, files in os.walk(rootpath):
            try:
                dirpath = utils.to_unicode(dirpath)
            except UnicodeDecodeError as e:
                continue
            rel_dirpath = os.path.relpath(dirpath, start=self.ROOTPATH)
            logger.debug("'%s' '%s'" % (dirpath, rel_dirpath))
            if rel_dirpath != '.':
                objname = utils.to_standard_sep(rel_dirpath)
                candidates[objname] = self.none_info()
            for filename in files:
                try:
                    filename = utils.to_unicode(filename)
                except UnicodeDecodeError as e:
                    continue
                if rel_dirpath == '.':
                    prefix = ""
                else:
                    prefix = utils.to_standard_sep(rel_dirpath)
                objname = utils.join_objname(prefix, filename)
                candidates[objname] = self.none_info()

        db_cands = dict((name, self.none_info()) for name in self.list_files())
        candidates.update(db_cands)
        logger.debug("Candidates: %s" % candidates)
        return candidates
Beispiel #2
0
    def walk_filesystem(self):
        candidates = {}
        rootpath = utils.from_unicode(self.ROOTPATH)
        for dirpath, dirnames, files in os.walk(rootpath):
            try:
                dirpath = utils.to_unicode(dirpath)
            except UnicodeDecodeError as e:
                continue
            rel_dirpath = os.path.relpath(dirpath, start=self.ROOTPATH)
            logger.debug("'%s' '%s'" % (dirpath, rel_dirpath))
            if rel_dirpath != ".":
                objname = utils.to_standard_sep(rel_dirpath)
                candidates[objname] = self.none_info()
            for filename in files:
                try:
                    filename = utils.to_unicode(filename)
                except UnicodeDecodeError as e:
                    continue
                if rel_dirpath == ".":
                    prefix = ""
                else:
                    prefix = utils.to_standard_sep(rel_dirpath)
                objname = utils.join_objname(prefix, filename)
                candidates[objname] = self.none_info()

        db_cands = dict((name, self.none_info()) for name in self.list_files())
        candidates.update(db_cands)
        logger.debug("Candidates: %s" % candidates)
        return candidates
Beispiel #3
0
    def notifier(self):
        def handle_path(path, rec=False):
            try:
                path = utils.to_unicode(path)
            except UnicodeDecodeError as e:
                return
            if path.startswith(self.CACHEPATH):
                return
            rel_path = os.path.relpath(path, start=self.ROOTPATH)
            if rel_path == '.':
                return
            objname = utils.to_standard_sep(rel_path)
            leaves = self.get_dir_contents(objname) if rec else None
            with self.probe_candidates.lock() as d:
                d[objname] = self.none_info()
                if rec:
                    for leaf in leaves:
                        d[leaf] = self.none_info()

        root_path = utils.from_unicode(self.ROOTPATH)

        class EventHandler(FileSystemEventHandler):
            def on_created(this, event):
                # if not event.is_directory:
                #     return
                path = event.src_path
                logger.debug("Handling %s" % event)
                handle_path(path)

            def on_deleted(this, event):
                path = event.src_path
                logger.debug("Handling %s" % event)
                if utils.normalize_local_suffix(path) == root_path:
                    self.settings.set_localfs_enabled(False)
                    msg = messaging.LocalfsSyncDisabled(logger=logger)
                    self.settings.messager.put(msg)
                    return
                handle_path(path, rec=utils.iswin())

            def on_modified(this, event):
                if event.is_directory:
                    return
                path = event.src_path
                logger.debug("Handling %s" % event)
                handle_path(path)

            def on_moved(this, event):
                src_path = event.src_path
                dest_path = event.dest_path
                logger.debug("Handling %s" % event)
                handle_path(src_path)
                handle_path(dest_path)

        event_handler = EventHandler()
        observer = Observer()
        observer.schedule(event_handler, root_path, recursive=True)
        observer.start()
        return observer
Beispiel #4
0
    def notifier(self):
        def handle_path(path, rec=False):
            try:
                path = utils.to_unicode(path)
            except UnicodeDecodeError as e:
                return
            if path.startswith(self.CACHEPATH):
                return
            rel_path = os.path.relpath(path, start=self.ROOTPATH)
            if rel_path == ".":
                return
            objname = utils.to_standard_sep(rel_path)
            leaves = self.get_dir_contents(objname) if rec else None
            with self.probe_candidates.lock() as d:
                d[objname] = self.none_info()
                if rec:
                    for leaf in leaves:
                        d[leaf] = self.none_info()

        root_path = utils.from_unicode(self.ROOTPATH)

        class EventHandler(FileSystemEventHandler):
            def on_created(this, event):
                # if not event.is_directory:
                #     return
                path = event.src_path
                logger.debug("Handling %s" % event)
                handle_path(path)

            def on_deleted(this, event):
                path = event.src_path
                logger.debug("Handling %s" % event)
                if utils.normalize_local_suffix(path) == root_path:
                    self.settings.set_localfs_enabled(False)
                    msg = messaging.LocalfsSyncDisabled(logger=logger)
                    self.settings.messager.put(msg)
                    return
                handle_path(path, rec=utils.iswin())

            def on_modified(this, event):
                if event.is_directory:
                    return
                path = event.src_path
                logger.debug("Handling %s" % event)
                handle_path(path)

            def on_moved(this, event):
                src_path = event.src_path
                dest_path = event.dest_path
                logger.debug("Handling %s" % event)
                handle_path(src_path)
                handle_path(dest_path)

        event_handler = EventHandler()
        observer = Observer()
        observer.schedule(event_handler, root_path, recursive=True)
        observer.start()
        return observer