Exemplo n.º 1
0
    def __init__(self, dirUriMap: DirUriMap, patch: PatchCb,
                 getSubgraph: GetSubgraph, addlPrefixes: Dict[str, URIRef]):
        self.dirUriMap = dirUriMap  # {abspath : uri prefix}
        self.patch, self.getSubgraph = patch, getSubgraph
        self.addlPrefixes = addlPrefixes

        self.graphFiles: Dict[URIRef,
                              GraphFile] = {}  # context uri : GraphFile

        self.notifier = INotify()
        self.notifier.startReading()

        self.findAndLoadFiles()
Exemplo n.º 2
0
 def watch(self):
     self._scheduler = SoftHardScheduler(reactor,
                                         self.rescan_soft_delay,
                                         self.rescan_hard_delay,
                                         self.scan)
     notifier = INotify()
     notifier.startReading()
     notifier.watch(self.wsgi_root,
                    IN_CREATE | IN_MOVED_TO | IN_DELETE | IN_MOVED_FROM
                    | IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT,
                    callbacks=[self.on_fs_change],
                    autoAdd=True,
                    recursive=True)
Exemplo n.º 3
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.next_id = 1000
        self.name = kwargs.get('name', 'my media')
        self.content = kwargs.get('content', None)
        if self.content is not None:
            if isinstance(self.content, str):
                self.content = [self.content]
            cl = []
            for a in self.content:
                cl += a.split(',')
            self.content = cl
        else:
            self.content = xdg_content()
            self.content = [x[0] for x in self.content]
        if self.content is None:
            self.content = 'tests/content'
        if not isinstance(self.content, list):
            self.content = [self.content]
        self.content = set([os.path.abspath(x) for x in self.content])
        ignore_patterns = kwargs.get('ignore_patterns', [])
        self.store = {}

        self.inotify = None

        if kwargs.get('enable_inotify', 'yes') == 'yes':
            if INotify:
                try:
                    self.inotify = INotify()
                    self.inotify.startReading()
                except Exception as msg:
                    self.error(f'inotify disabled: {msg}')
                    self.inotify = None
            else:
                self.info(f'{no_inotify_reason}')
        else:
            self.info('FSStore content auto-update disabled upon user request')

        if kwargs.get('enable_destroy', 'no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.import_folder = kwargs.get('import_folder', None)
        if self.import_folder is not None:
            self.import_folder = os.path.abspath(self.import_folder)
            if not os.path.isdir(self.import_folder):
                self.import_folder = None

        self.ignore_file_pattern = re.compile(r'|'.join([r'^\..*'] +
                                                        list(ignore_patterns)))
        parent = None
        self.update_id = 0
        if (len(self.content) > 1
                or utils.means_true(kwargs.get('create_root', False))
                or self.import_folder is not None):
            UPnPClass = classChooser('root')
            id = str(self.getnextID())
            try:
                parent = self.store[id] = FSItem(
                    id,
                    parent,
                    'media',
                    'root',
                    self.urlbase,
                    UPnPClass,
                    update=True,
                    store=self,
                )
            except Exception as e:
                self.error(
                    f'Error on setting self.store[id], Error on FSItem: {e}')
                exit(1)

        if self.import_folder is not None:
            id = str(self.getnextID())
            self.store[id] = FSItem(
                id,
                parent,
                self.import_folder,
                'directory',
                self.urlbase,
                UPnPClass,
                update=True,
                store=self,
            )
            self.import_folder_id = id
        for bytesPath in self.content:
            if isinstance(bytesPath, (list, tuple)):
                path = str(bytesPath[0])
            else:
                path = str(bytesPath)
            if self.ignore_file_pattern.match(path):
                continue
            try:
                self.walk(path, parent, self.ignore_file_pattern)
            except Exception as msg:
                self.warning(f'on walk of {path!r}: {msg!r}')
                import traceback

                self.debug(traceback.format_exc())

        self.wmc_mapping.update({'14': '0', '15': '0', '16': '0', '17': '0'})

        self.init_completed = True
Exemplo n.º 4
0
def greed_controller(pathname):
    print 'WORKING:', pathname
    process_handler(pathname)
    print 'DONE:', pathname

def created(ignored, path, mask):
    basename = path.basename()
    if re.match(r'^\.|^t$|^t_|^index\.md$', basename):
        return

    pathname = path.path
    pathname = find_root(pathname)
    if pathname not in call_ids or not call_ids[pathname].active():
        print 'SET:', pathname
        call_ids[pathname] = reactor.callLater(CALL_DELAY, greed_controller, pathname)
    else:
        print 'RESET:', pathname
        call_ids[pathname].reset(CALL_DELAY)

notifier = INotify()
notifier.watch(
    FilePath(WATCH_DIRECTORY),
    mask=IN_MODIFY|IN_CREATE,
    callbacks=[created],
    autoAdd=True,
    recursive=True
)
notifier.startReading()
reactor.run()
Exemplo n.º 5
0
    def __init__(self):
        super(FilesystemNotifier, self).__init__()

        self.notifier = INotify()
        self.notifier.startReading()