[projects/git-slug: 86/170] Reorganise code in preparation to be run as daemon

glen glen at pld-linux.org
Mon Sep 21 21:46:02 CEST 2015


commit fa60f5e3069fd79c08bd7f3fc9f55947d5b1a962
Author: Kacper Kornet <draenog at pld-linux.org>
Date:   Mon Mar 12 16:13:21 2012 +0000

    Reorganise code in preparation to be run as daemon
    
    Move common code to one function that will be called by both daemonized
    and not-daemonized instances.

 slug_watch | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/slug_watch b/slug_watch
index 5c0a298..2b39e2a 100755
--- a/slug_watch
+++ b/slug_watch
@@ -75,19 +75,21 @@ class EventHandler(pyinotify.ProcessEvent):
     def process_IN_CLOSE_WRITE(self, event):
         process_file(event.pathname)
 
-def run():
+def runwatch():
+    os.chdir(pwd.getpwuid(os.getuid()).pw_dir)
     for directory in (WATCHDIR, REFREPO_WDIR):
         if not os.path.isdir(directory):
             print('Creating {}'.format(directory))
             os.mkdir(directory)
-    wm = pyinotify.WatchManager()  # Watch Manager
-    mask = pyinotify.IN_CLOSE_WRITE # watched events
-    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))
-    notifier.loop()
+    with lock(LOCKFILE):
+        wm = pyinotify.WatchManager()  # Watch Manager
+        mask = pyinotify.IN_CLOSE_WRITE # watched events
+        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))
+        notifier.loop()
 
 
 parser = ArgumentParser(description='daemon to register changes in PLD repositories')
@@ -95,6 +97,4 @@ parser.add_argument('-d', '--daemon', nargs='?', choices=['start', 'stop'], defa
 parser.add_argument('-u', '--user')
 options = parser.parse_args()
 
-os.chdir(pwd.getpwuid(os.getuid()).pw_dir)
-with lock(LOCKFILE):
-    run()
+runwatch()
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list