mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:21:31 +00:00
Fix file observer
This commit is contained in:
parent
6cc3d32097
commit
da19769362
@ -1,10 +1,6 @@
|
|||||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
||||||
# All Rights Reserved. See LICENSE file for details.
|
# 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 findall
|
||||||
from re import compile as compileregex
|
from re import compile as compileregex
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
@ -30,11 +26,6 @@ class HistoryMonitor(ABC, InotifyObserver):
|
|||||||
self.history = []
|
self.history = []
|
||||||
self._last_length = len(self.history)
|
self._last_length = len(self.history)
|
||||||
self.uplink = uplink
|
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)
|
super().__init__(self.histfile)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
from time import time
|
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.observers import Observer
|
||||||
from watchdog.events import FileSystemMovedEvent, PatternMatchingEventHandler
|
from watchdog.events import FileSystemMovedEvent, PatternMatchingEventHandler
|
||||||
@ -66,10 +66,10 @@ class InotifyDirDeletedEvent(InotifyEvent):
|
|||||||
|
|
||||||
|
|
||||||
class InotifyObserver:
|
class InotifyObserver:
|
||||||
def __init__(self, path, patterns=[], exclude=None, recursive=False):
|
def __init__(self, path, patterns=None, exclude=None, recursive=False):
|
||||||
self._files = []
|
self._files = []
|
||||||
self._paths = path
|
self._paths = path
|
||||||
self._patterns = patterns
|
self._patterns = patterns or []
|
||||||
self._exclude = exclude
|
self._exclude = exclude
|
||||||
self._recursive = recursive
|
self._recursive = recursive
|
||||||
self._observer = Observer()
|
self._observer = Observer()
|
||||||
@ -97,12 +97,12 @@ class InotifyObserver:
|
|||||||
def _extract_files_from_paths(self):
|
def _extract_files_from_paths(self):
|
||||||
files, paths = [], []
|
files, paths = [], []
|
||||||
for path in self._paths:
|
for path in self._paths:
|
||||||
if isfile(path):
|
if isdir(path):
|
||||||
|
paths.append(path)
|
||||||
|
else:
|
||||||
new_file = abspath(path)
|
new_file = abspath(path)
|
||||||
files.append(new_file)
|
files.append(new_file)
|
||||||
paths.append(dirname(new_file))
|
paths.append(dirname(new_file))
|
||||||
else:
|
|
||||||
paths.append(path)
|
|
||||||
self._files, self._paths = files, paths
|
self._files, self._paths = files, paths
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user