summaryrefslogtreecommitdiff
path: root/megapixels/commands/site/watch.py
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2019-02-28 18:50:22 +0100
committeradamhrv <adam@ahprojects.com>2019-02-28 18:50:22 +0100
commit6c631c88c9ecc2683b95534cfd15e82650c1b501 (patch)
tree786d993a57c8c4d6fba26cad5fbda056c346c418 /megapixels/commands/site/watch.py
parent9e3bb35630349847bc005389c408f3072e0e22db (diff)
parente845766d970f4afefc2fc47367c3478413f98ff2 (diff)
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'megapixels/commands/site/watch.py')
-rw-r--r--megapixels/commands/site/watch.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/megapixels/commands/site/watch.py b/megapixels/commands/site/watch.py
new file mode 100644
index 00000000..7bd71038
--- /dev/null
+++ b/megapixels/commands/site/watch.py
@@ -0,0 +1,46 @@
+"""
+Watch for changes in the static site and build them
+"""
+
+import click
+import time
+from watchdog.observers import Observer
+from watchdog.events import PatternMatchingEventHandler
+
+import app.settings.app_cfg as cfg
+from app.site.builder import build_site, build_file
+
+class SiteBuilder(PatternMatchingEventHandler):
+ """
+ Handler for filesystem changes to the content path
+ """
+ patterns = ["*.md"]
+
+ def on_modified(self, event):
+ print(event.src_path, event.event_type)
+ build_file(event.src_path)
+
+ def on_created(self, event):
+ print(event.src_path, event.event_type)
+ build_file(event.src_path)
+
+@click.command()
+@click.pass_context
+def cli(ctx):
+ """
+ Run the observer and start watching for changes
+ """
+ print("{} is now being watched for changes.".format(cfg.DIR_SITE_CONTENT))
+ observer = Observer()
+ observer.schedule(SiteBuilder(), path=cfg.DIR_SITE_CONTENT, recursive=True)
+ observer.start()
+
+ build_file(cfg.DIR_SITE_CONTENT + "/datasets/lfw/index.md")
+
+ try:
+ while True:
+ time.sleep(1)
+ except KeyboardInterrupt:
+ observer.stop()
+
+ observer.join()