mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 06:22:55 +00:00 
			
		
		
		
	Fix file observer
This commit is contained in:
		@@ -1,10 +1,6 @@
 | 
			
		||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
 | 
			
		||||
# All Rights Reserved. See LICENSE file for details.
 | 
			
		||||
 | 
			
		||||
from pwd import getpwnam
 | 
			
		||||
from grp import getgrnam
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from os import chown
 | 
			
		||||
from re import findall
 | 
			
		||||
from re import compile as compileregex
 | 
			
		||||
from abc import ABC, abstractmethod
 | 
			
		||||
@@ -30,11 +26,6 @@ class HistoryMonitor(ABC, InotifyObserver):
 | 
			
		||||
        self.history = []
 | 
			
		||||
        self._last_length = len(self.history)
 | 
			
		||||
        self.uplink = uplink
 | 
			
		||||
        uid = getpwnam('user').pw_uid
 | 
			
		||||
        gid = getgrnam('users').gr_gid
 | 
			
		||||
        path = Path(self.histfile)
 | 
			
		||||
        path.touch()
 | 
			
		||||
        chown(self.histfile, uid, gid)
 | 
			
		||||
        super().__init__(self.histfile)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
from typing import Iterable
 | 
			
		||||
from time import time
 | 
			
		||||
from os.path import abspath, dirname, isfile
 | 
			
		||||
from os.path import abspath, dirname, isdir
 | 
			
		||||
 | 
			
		||||
from watchdog.observers import Observer
 | 
			
		||||
from watchdog.events import FileSystemMovedEvent, PatternMatchingEventHandler
 | 
			
		||||
@@ -66,10 +66,10 @@ class InotifyDirDeletedEvent(InotifyEvent):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class InotifyObserver:
 | 
			
		||||
    def __init__(self, path, patterns=[], exclude=None, recursive=False):
 | 
			
		||||
    def __init__(self, path, patterns=None, exclude=None, recursive=False):
 | 
			
		||||
        self._files = []
 | 
			
		||||
        self._paths = path
 | 
			
		||||
        self._patterns = patterns
 | 
			
		||||
        self._patterns = patterns or []
 | 
			
		||||
        self._exclude = exclude
 | 
			
		||||
        self._recursive = recursive
 | 
			
		||||
        self._observer = Observer()
 | 
			
		||||
@@ -97,12 +97,12 @@ class InotifyObserver:
 | 
			
		||||
    def _extract_files_from_paths(self):
 | 
			
		||||
        files, paths = [], []
 | 
			
		||||
        for path in self._paths:
 | 
			
		||||
            if isfile(path):
 | 
			
		||||
            if isdir(path):
 | 
			
		||||
                paths.append(path)
 | 
			
		||||
            else:
 | 
			
		||||
                new_file = abspath(path)
 | 
			
		||||
                files.append(new_file)
 | 
			
		||||
                paths.append(dirname(new_file))
 | 
			
		||||
            else:
 | 
			
		||||
                paths.append(path)
 | 
			
		||||
        self._files, self._paths = files, paths
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user