2024-07-31 11:33:45 -07:00
|
|
|
import argparse
|
|
|
|
import inotify.adapters
|
|
|
|
import logging
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2024-07-31 11:18:34 -07:00
|
|
|
def main():
|
2024-07-31 11:33:45 -07:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Enable verbose logging.")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
|
|
|
|
try:
|
|
|
|
run(Path("/mnt/shares/scans"))
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
LOGGER.info("Quitting")
|
|
|
|
|
|
|
|
def run(path: Path) -> None:
|
|
|
|
i = inotify.adapters.Inotify()
|
|
|
|
i.add_watch(str(path))
|
|
|
|
for event in i.event_gen(yield_nones=False):
|
|
|
|
(_, type_names, path, filename) = event
|
|
|
|
if "IN_CLOSE_WRITE" in type_names:
|
|
|
|
_handle_write_complete(Path(filename))
|
|
|
|
|
|
|
|
def _handle_write_complete(path: Path) -> None:
|
|
|
|
if path.suffix == ".test":
|
|
|
|
LOGGER.info("Ignoring scanner test write '%s'", path)
|
|
|
|
return
|
|
|
|
LOGGER.info("Pretend I uploaded %s", path)
|