prepare for packaging
This commit is contained in:
3
MANIFEST.in
Normal file
3
MANIFEST.in
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
include LICENSE README.md
|
||||||
|
recursive-include docs *
|
||||||
|
recursive-include misc *
|
||||||
63
docs/config.py
Normal file
63
docs/config.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# Example usage of TaskScheduler #
|
||||||
|
####################################
|
||||||
|
|
||||||
|
#def custom_job(event, task_id):
|
||||||
|
# logging.info(f"{task_id}: execute task for {event}")
|
||||||
|
#
|
||||||
|
#s = TaskScheduler(delay=10, job=custom_job)
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Example usage of TaskScheduler with FileManager #
|
||||||
|
#####################################################
|
||||||
|
|
||||||
|
#fm = FileManager(
|
||||||
|
# rules=[
|
||||||
|
# {"action": "move",
|
||||||
|
# "src_re": r"^(?P<path>.*)",
|
||||||
|
# "dst_re": r"\g<path>.processed"}
|
||||||
|
# ]
|
||||||
|
#)
|
||||||
|
#
|
||||||
|
#s = TaskScheduler(delay=10, job=fm.job)
|
||||||
|
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
# Example usage of ShellScheduler #
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
#s = ShellScheduler(cmd="/usr/local/bin/task.sh {maskname} {pathname} {src_pathname}")
|
||||||
|
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# Example pyinotifyd config #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
#pyinotifyd_config = {
|
||||||
|
# "watches": [
|
||||||
|
# {"path": "/tmp",
|
||||||
|
# "rec": True,
|
||||||
|
# "auto_add": True,
|
||||||
|
# "event_map": {
|
||||||
|
# "IN_ACCESS": None,
|
||||||
|
# "IN_ATTRIB": None,
|
||||||
|
# "IN_CLOSE_NOWRITE": None,
|
||||||
|
# "IN_CLOSE_WRITE": s.schedule,
|
||||||
|
# "IN_CREATE": None,
|
||||||
|
# "IN_DELETE": s.cancel,
|
||||||
|
# "IN_DELETE_SELF": s.cancel,
|
||||||
|
# "IN_IGNORED": None,
|
||||||
|
# "IN_MODIFY": s.cancel,
|
||||||
|
# "IN_MOVE_SELF": None,
|
||||||
|
# "IN_MOVED_FROM": s.cancel,
|
||||||
|
# "IN_MOVED_TO": s.schedule,
|
||||||
|
# "IN_OPEN": None,
|
||||||
|
# "IN_Q_OVERFLOW": None,
|
||||||
|
# "IN_UNMOUNT": s.cancel}
|
||||||
|
# }
|
||||||
|
# ],
|
||||||
|
# "loglevel": logging.INFO,
|
||||||
|
# "shutdown_timeout": 15}
|
||||||
11
misc/pyinotifyd.service
Normal file
11
misc/pyinotifyd.service
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=pyinotifyd
|
||||||
|
After=fs.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/pyinotifyd
|
||||||
|
TimeoutStopSec=300
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -27,6 +27,7 @@ import sys
|
|||||||
from shlex import quote as shell_quote
|
from shlex import quote as shell_quote
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
__version__ = "0.0.1"
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
def __init__(self, event, delay, task_id, job, callback=None,
|
def __init__(self, event, delay, task_id, job, callback=None,
|
||||||
@@ -129,16 +130,19 @@ class ShellScheduler(TaskScheduler):
|
|||||||
cmd = cmd.replace("{maskname}", shell_quote(maskname))
|
cmd = cmd.replace("{maskname}", shell_quote(maskname))
|
||||||
cmd = cmd.replace("{pathname}", shell_quote(event.pathname))
|
cmd = cmd.replace("{pathname}", shell_quote(event.pathname))
|
||||||
if hasattr(event, "src_pathname"):
|
if hasattr(event, "src_pathname"):
|
||||||
cmd = cmd.replace(
|
src_pathname = event.src_pathname
|
||||||
"{src_pathname}", shell_quote(event.src_pathname))
|
else:
|
||||||
|
src_pathname = ""
|
||||||
|
|
||||||
|
cmd = cmd.replace(
|
||||||
|
"{src_pathname}", shell_quote(src_pathname))
|
||||||
self._log.info(f"{task_id}: execute shell command: {cmd}")
|
self._log.info(f"{task_id}: execute shell command: {cmd}")
|
||||||
proc = await asyncio.create_subprocess_shell(cmd)
|
proc = await asyncio.create_subprocess_shell(cmd)
|
||||||
await proc.communicate()
|
await proc.communicate()
|
||||||
|
|
||||||
|
|
||||||
class FileManager:
|
class FileManager:
|
||||||
def __init__(self, rules, auto_create=False, rec=False,
|
def __init__(self, rules, auto_create=True, rec=False,
|
||||||
logname="FileManager"):
|
logname="FileManager"):
|
||||||
self._rules = []
|
self._rules = []
|
||||||
if not isinstance(rules, list):
|
if not isinstance(rules, list):
|
||||||
@@ -260,21 +264,27 @@ def main():
|
|||||||
description="pyinotifyd",
|
description="pyinotifyd",
|
||||||
formatter_class=lambda prog: argparse.HelpFormatter(
|
formatter_class=lambda prog: argparse.HelpFormatter(
|
||||||
prog, max_help_position=45, width=140))
|
prog, max_help_position=45, width=140))
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
"--config",
|
"--config",
|
||||||
help="path to config file (defaults to /etc/pyinotifyd/config.py)",
|
help="path to config file (defaults to /etc/pyinotifyd/config.py)",
|
||||||
default="/etc/pyinotifyd/config.py")
|
default="/etc/pyinotifyd/config.py")
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--debug",
|
"--debug",
|
||||||
help="Log debugging messages.",
|
help="log debugging messages",
|
||||||
|
action="store_true")
|
||||||
|
parser.add_argument(
|
||||||
|
"-v",
|
||||||
|
"--version",
|
||||||
|
help="show version and exit",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.version:
|
||||||
|
print(f"pyinotifyd ({__version__})")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
default_config = {
|
default_config = {
|
||||||
"watches": [],
|
"watches": [],
|
||||||
"loglevel": logging.INFO,
|
"loglevel": logging.INFO,
|
||||||
|
|||||||
40
setup.py
Normal file
40
setup.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
def read_file(fname):
|
||||||
|
with open(fname, 'r') as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
setup(name = "pyinotifyd",
|
||||||
|
author = "Thomas Oettli",
|
||||||
|
author_email = "spacefreak@noop.ch",
|
||||||
|
description = "Monitoring filesystems events with inotify on Linux and execute tasks.",
|
||||||
|
license = "GPL 3",
|
||||||
|
keywords = "inotify daemon",
|
||||||
|
url = "https://github.com/spacefreak86/pyinotifyd",
|
||||||
|
py_modules = ["pyinotifyd"],
|
||||||
|
long_description = read_file("README.md"),
|
||||||
|
long_description_content_type = "text/markdown",
|
||||||
|
classifiers = [
|
||||||
|
# 3 - Alpha
|
||||||
|
# 4 - Beta
|
||||||
|
# 5 - Production/Stable
|
||||||
|
"Development Status :: 3 - Alpha",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Topic :: Utilities"
|
||||||
|
],
|
||||||
|
include_package_data = True,
|
||||||
|
entry_points = {
|
||||||
|
"console_scripts": [
|
||||||
|
"pyinotifyd=pyinotifyd:main"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
data_files = [
|
||||||
|
("/etc/pyinotifyd", ["docs/config.py"]),
|
||||||
|
("/usr/lib/systemd/system", ["misc/pyinotifyd.service"])
|
||||||
|
],
|
||||||
|
install_requires = ["pyinotify"],
|
||||||
|
python_requires = ">=3.7"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user