small fixes
This commit is contained in:
@@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Pyinotifyd",
|
"Pyinotifyd",
|
||||||
"daemon_from_config",
|
"DaemonInstance",
|
||||||
]
|
"main",
|
||||||
|
"scheduler",
|
||||||
|
"watch"]
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -26,7 +28,7 @@ import logging.handlers
|
|||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pyinotifyd.watch import Watch, EventMap
|
from pyinotifyd.watch import EventMap, Watch
|
||||||
from pyinotifyd._install import install, uninstall
|
from pyinotifyd._install import install, uninstall
|
||||||
|
|
||||||
__version__ = "0.0.2"
|
__version__ = "0.0.2"
|
||||||
@@ -46,9 +48,10 @@ class Pyinotifyd:
|
|||||||
def from_cfg_file(config_file):
|
def from_cfg_file(config_file):
|
||||||
config = {}
|
config = {}
|
||||||
name = Pyinotifyd.name
|
name = Pyinotifyd.name
|
||||||
|
exec(f"import logging", {}, config)
|
||||||
exec(f"from {name} import Pyinotifyd", {}, config)
|
exec(f"from {name} import Pyinotifyd", {}, config)
|
||||||
exec(f"from {name}.scheduler import *", {}, config)
|
exec(f"from {name}.scheduler import *", {}, config)
|
||||||
exec(f"from {name}.watch import EventMap, Watch", {}, config)
|
exec(f"from {name}.watch import *", {}, config)
|
||||||
with open(config_file, "r") as fh:
|
with open(config_file, "r") as fh:
|
||||||
exec(fh.read(), {}, config)
|
exec(fh.read(), {}, config)
|
||||||
instance = config[f"{name}"]
|
instance = config[f"{name}"]
|
||||||
|
|||||||
@@ -12,6 +12,13 @@
|
|||||||
# along with pyinotifyd. If not, see <http://www.gnu.org/licenses/>.
|
# along with pyinotifyd. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"Task",
|
||||||
|
"TaskScheduler",
|
||||||
|
"ShellScheduler",
|
||||||
|
"FileManagerRule",
|
||||||
|
"FileManagerScheduler"]
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -24,7 +31,7 @@ from shlex import quote as shell_quote
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
|
||||||
def event_to_str(event):
|
def _event_to_str(event):
|
||||||
return f"maskname={event.maskname}, pathname={event.pathname}"
|
return f"maskname={event.maskname}, pathname={event.pathname}"
|
||||||
|
|
||||||
|
|
||||||
@@ -81,16 +88,16 @@ class TaskScheduler(Task):
|
|||||||
if self._delay > 0:
|
if self._delay > 0:
|
||||||
task_state.waiting = True
|
task_state.waiting = True
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
f"schedule task ({event_to_str(event)}, "
|
f"schedule task ({_event_to_str(event)}, "
|
||||||
f"task_id={task_id}, delay={self._delay})")
|
f"task_id={task_id}, delay={self._delay})")
|
||||||
await asyncio.sleep(self._delay)
|
await asyncio.sleep(self._delay)
|
||||||
task_state.waiting = False
|
task_state.waiting = False
|
||||||
|
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
f"start task ({event_to_str(event)}, task_id={task_id})")
|
f"start task ({_event_to_str(event)}, task_id={task_id})")
|
||||||
await self._delayed_task(event, task_id)
|
await self._delayed_task(event, task_id)
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
f"task finished ({event_to_str(event)}, task_id={task_id})")
|
f"task finished ({_event_to_str(event)}, task_id={task_id})")
|
||||||
del self._tasks[event.pathname]
|
del self._tasks[event.pathname]
|
||||||
|
|
||||||
def start(self, event, *args, **kwargs):
|
def start(self, event, *args, **kwargs):
|
||||||
@@ -111,7 +118,7 @@ class TaskScheduler(Task):
|
|||||||
|
|
||||||
if task_state.waiting:
|
if task_state.waiting:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
f"cancel task ({event_to_str(event)}, "
|
f"cancel task ({_event_to_str(event)}, "
|
||||||
f"task_id={task_state.task_id})")
|
f"task_id={task_state.task_id})")
|
||||||
task_state.task.cancel()
|
task_state.task.cancel()
|
||||||
del self._tasks[event.pathname]
|
del self._tasks[event.pathname]
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
# along with pyinotifyd. If not, see <http://www.gnu.org/licenses/>.
|
# along with pyinotifyd. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"EventMap",
|
||||||
|
"Watch"]
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import pyinotify
|
import pyinotify
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user