Created
January 30, 2023 22:22
-
-
Save johnmaguire/b5577159f6c5ea041898de9e3ed247af to your computer and use it in GitHub Desktop.
inotify wrapper - Use inotify to watch for changes (saved from a 2019 repo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3 | |
WORKDIR /usr/src/app | |
COPY requirements.txt ./ | |
RUN pip install --no-cache-dir -r requirements.txt | |
COPY . . | |
ENTRYPOINT [ "python", "./main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import subprocess | |
from inotify_simple import INotify, flags | |
if __name__ == "__main__": | |
# Look for arguments | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-d', dest='directory', | |
help='directory to watch for file changes') | |
parser.add_argument('-c', dest='command', | |
help='command to run when changes are detected') | |
args = parser.parse_args() | |
# Setup inotify | |
inotify = INotify() | |
watch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | \ | |
flags.DELETE_SELF | |
wd = inotify.add_watch(args.directory, watch_flags) | |
# Wait for inotify events | |
while True: | |
_ = inotify.read(read_delay=1000) | |
subprocess.call(args.command, shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inotify-simple==1.1.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment