[projects/git-slug: 73/170] Redesign slug_watch to be run from cron

glen glen at pld-linux.org
Mon Sep 21 21:44:57 CEST 2015


commit fbac467a791ece3dcb887ed9ea17e3303c87b229
Author: Kacper Kornet <draenog at pld-linux.org>
Date:   Sat Dec 17 16:45:42 2011 +0000

    Redesign slug_watch to be run from cron

 slug_watch | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/slug_watch b/slug_watch
index 7a9df6f..ab75aa4 100755
--- a/slug_watch
+++ b/slug_watch
@@ -1,5 +1,6 @@
 #!/usr/bin/python3
 
+import fcntl
 import heapq
 import os
 import pyinotify
@@ -9,7 +10,6 @@ from git_slug.serverconst import WATCHDIR
 from git_slug.refsdata import RemoteRefsData
 from git_slug.gitrepo import GitRepo
 
-
 PIDFILE = os.path.expanduser('~/watch.pid')
 REFFILE_NEW = REFFILE + '.new'
 REFREPO_WDIR = os.path.expanduser('~/Refs')
@@ -59,14 +59,20 @@ class EventHandler(pyinotify.ProcessEvent):
     def process_IN_CLOSE_WRITE(self, event):
         process_file(event.pathname)
 
-if not os.path.isdir(WATCHDIR):
-    print('Creating {}'.format(WATCHDIR))
-    os.mkdir(WATCHDIR)
-notifier = pyinotify.Notifier(wm, EventHandler())
-wdd = wm.add_watch(WATCHDIR, mask, rec=False)
+def run():
+    if not os.path.isdir(WATCHDIR):
+        print('Creating {}'.format(WATCHDIR))
+        os.mkdir(WATCHDIR)
+    notifier = pyinotify.Notifier(wm, EventHandler())
+    wdd = wm.add_watch(WATCHDIR, mask, rec=False)
 
-for filename in sorted(os.listdir(WATCHDIR), key=lambda f: os.stat(os.path.join(WATCHDIR, f)).st_mtime):
-    process_file(os.path.join(WATCHDIR,filename))
+    for filename in sorted(os.listdir(WATCHDIR), key=lambda f: os.stat(os.path.join(WATCHDIR, f)).st_mtime):
+        process_file(os.path.join(WATCHDIR,filename))
+    notifier.loop()
 
-notifier.loop(daemonize=True, pid_file=os.path.expanduser(PIDFILE),
-            stdout=os.path.expanduser('~/watch.stdout'))
+with open(os.path.expanduser(PIDFILE), "a") as f:
+    try: 
+        fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        run()
+    except IOError:
+        pass
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5



More information about the pld-cvs-commit mailing list