the-paperless-project / paperless

Scan, index, and archive all of your paper documents
GNU General Public License v3.0
7.85k stars 498 forks source link

macOS Compatibility - inotify #491

Open nasdas-dev opened 5 years ago

nasdas-dev commented 5 years ago

inotify is incompatible with macOS and I'd suggest a mac build with fswatch instead.

ovv commented 5 years ago

There is a --no-inotify argument that fall back on a time loop.

I have no idea if there is an easy way to interface python with fswatch. If there is it might be a good thing to explore.

erikarvstedt commented 5 years ago

Also, inotify is automatically disabled on non-Linux systems.

fswatch (or watchdog for Python) aren't directly usable in Paperless. For detecting new docs to consume, we want to react to the event that a file has been closed after being written to. This can't be expressed by the more general event types (created, modified) of common cross-platform fs monitoring libs.

kuhnchris commented 5 years ago

Well, a very "stupid" consumer script would be to create a small python script that simply scans the /consume directory, keeps a list, and compares it. If the entries are different - read the directory again (or the list delta). We could provide this as a fall-back option (for example configurable as environment variable for docker-compose.env).

Let me know if you need a quick write up for that.

kuhnchris commented 5 years ago

As a real quick POC:

import os
import time

dirToWatch = "./watch/"
fileList = []
timeToSleep = 5

while True:
    newFileList = os.listdir(dirToWatch)
    if fileList != newFileList:
        print(f"changes detected in {dirToWatch}:")
        changes = set(newFileList) - set(fileList)
        print(changes)
        fileList = newFileList
    else:
        print("no new changes")
    time.sleep(timeToSleep)
➜  others python3 watchdog.py
changes detected in ./watch/:
{'me', 'menot'}
no new changes
no new changes
changes detected in ./watch/:
{'file', 'new'}
no new changes
erikarvstedt commented 5 years ago

a very "stupid" consumer script would be to ...

How is this different from the existing, fall-back consumer script?

kuhnchris commented 5 years ago

Oh, I wasn't aware there was an consumer script already, my bad. Please ignore what I said then.