replaced inotify with watchdog
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
MAINTAINER Oggioni Walter <oggioni.walter@gmail.com>
|
MAINTAINER Oggioni Walter <oggioni.walter@gmail.com>
|
||||||
RUN apk update
|
RUN apk update
|
||||||
RUN apk add python3 uwsgi uwsgi-python3 graphviz
|
RUN apk add python3 py3-pip py3-watchdog uwsgi uwsgi-python3 graphviz
|
||||||
RUN mkdir /srv/http
|
RUN mkdir /srv/http
|
||||||
VOLUME /srv/http
|
VOLUME /srv/http
|
||||||
WORKDIR /srv/http
|
WORKDIR /srv/http
|
||||||
|
@@ -43,8 +43,8 @@ class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
|
|||||||
class MarkdownHTTPServer(ThreadingHTTPServer):
|
class MarkdownHTTPServer(ThreadingHTTPServer):
|
||||||
|
|
||||||
def __init__(self, mdfile, extensions=(), handler=BaseHTTPRequestHandler, interface="127.0.0.1", port=8080):
|
def __init__(self, mdfile, extensions=(), handler=BaseHTTPRequestHandler, interface="127.0.0.1", port=8080):
|
||||||
import inotify
|
from watchdog.observers import Observer
|
||||||
import inotify.adapters
|
from watchdog.events import PatternMatchingEventHandler
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
self.stop = False
|
self.stop = False
|
||||||
@@ -61,26 +61,23 @@ class MarkdownHTTPServer(ThreadingHTTPServer):
|
|||||||
self.hash = None
|
self.hash = None
|
||||||
self.etag = None
|
self.etag = None
|
||||||
|
|
||||||
def watch_file():
|
event_handler = PatternMatchingEventHandler(
|
||||||
watcher = inotify.adapters.Inotify()
|
patterns=[mdfile],
|
||||||
watcher.add_watch(dirname(abspath(self.mdfile)))
|
ignore_patterns=None,
|
||||||
target_file = basename(self.mdfile)
|
ignore_directories=True,
|
||||||
while True:
|
case_sensitive=True)
|
||||||
if self.stop:
|
|
||||||
break
|
|
||||||
for event in watcher.event_gen(yield_nones=True, timeout_s=1):
|
|
||||||
if not event:
|
|
||||||
continue
|
|
||||||
(_, event_type, path, filename) = event
|
|
||||||
if filename == target_file and len(set(event_type).intersection(
|
|
||||||
{'IN_CLOSE_WRITE'})):
|
|
||||||
self.condition_variable.acquire()
|
|
||||||
if self.update_file_digest():
|
|
||||||
self.condition_variable.notify_all()
|
|
||||||
self.condition_variable.release()
|
|
||||||
|
|
||||||
file_watcher = threading.Thread(target=watch_file)
|
def on_modified(evt):
|
||||||
file_watcher.start()
|
self.condition_variable.acquire()
|
||||||
|
if self.update_file_digest():
|
||||||
|
self.condition_variable.notify_all()
|
||||||
|
self.condition_variable.release()
|
||||||
|
|
||||||
|
event_handler.on_modified = on_modified
|
||||||
|
|
||||||
|
self.observer = Observer()
|
||||||
|
self.observer.schedule(event_handler, path=dirname(abspath(self.mdfile)), recursive=False)
|
||||||
|
self.observer.start()
|
||||||
super().__init__((interface, port), handler)
|
super().__init__((interface, port), handler)
|
||||||
|
|
||||||
def update_file_digest(self):
|
def update_file_digest(self):
|
||||||
@@ -180,8 +177,7 @@ def parse_args(args=None):
|
|||||||
help='Activate specified markdown extensions (defaults to "extra smarty tables")')
|
help='Activate specified markdown extensions (defaults to "extra smarty tables")')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import inotify
|
import watchdog
|
||||||
import gevent
|
|
||||||
import signal
|
import signal
|
||||||
parser.add_argument('-w', '--watch', action='store_true',
|
parser.add_argument('-w', '--watch', action='store_true',
|
||||||
help='Watch specified source file and rerun the compilation for every time it changes')
|
help='Watch specified source file and rerun the compilation for every time it changes')
|
||||||
|
2
setup.py
2
setup.py
@@ -15,7 +15,7 @@ config = {
|
|||||||
'long_description': '',
|
'long_description': '',
|
||||||
'license': "MIT",
|
'license': "MIT",
|
||||||
'keywords': "build",
|
'keywords': "build",
|
||||||
'url': "https://github.com/oggio88/md2html",
|
'url': "https://github.com/woggioni/md2html",
|
||||||
'packages': ['md2html'],
|
'packages': ['md2html'],
|
||||||
'package_data': {
|
'package_data': {
|
||||||
'md2html': ['static/*.html', 'static/*.css', 'static/*.js'],
|
'md2html': ['static/*.html', 'static/*.css', 'static/*.js'],
|
||||||
|
Reference in New Issue
Block a user