From d2ee60b35c20c8d7215882ca5b2afa4274dec0a9 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 25 Feb 2012 21:28:56 +0000
Subject: [PATCH] remove support for realtime filesystem watches to simplify
 the client even more (besides, it never worked on linux)

---
 client/djrandom_client/client.py              | 47 ++++---------------
 client/djrandom_client/linux_watcher.py       | 24 ----------
 client/djrandom_client/osx_watcher.py         | 23 ---------
 .../DJRandomUploader/ProcessController.m      |  1 -
 4 files changed, 8 insertions(+), 87 deletions(-)
 delete mode 100644 client/djrandom_client/linux_watcher.py
 delete mode 100644 client/djrandom_client/osx_watcher.py

diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py
index 3a15226..dac2f4a 100644
--- a/client/djrandom_client/client.py
+++ b/client/djrandom_client/client.py
@@ -14,20 +14,11 @@ from djrandom_client import upload
 from djrandom_client import utils
 from djrandom_client import throttle
 
-# Detect platform and selectively enable inotify/fsevents watchers.
-watcher_support = False
-try:
-    if platform.system() == 'Darwin':
-        import djrandom_client.osx_watcher as watcher
-        watcher_support = True
-    elif platform.system() == 'Linux':
-        import djrandom_client.linux_watcher as watcher
-        watcher_support = True
-except ImportError:
-    pass
-
 log = logging.getLogger(__name__)
 
+# How often we rescan the filesystem looking for new files.
+SCAN_DELAY = 1800
+
 
 class FullScan(threading.Thread):
     """Do a recursive directory scan when starting."""
@@ -55,11 +46,10 @@ class FullScan(threading.Thread):
             time.sleep(delay)
 
 
-def run_client(server_url, music_dir, excludes, api_key, run_once, bwlimit,
-               enable_watcher):
+def run_client(server_url, music_dir, excludes, api_key, run_once, bwlimit):
     log.debug('settings: server=%s, music_dir=%s, api_key=%s, '
-              'bwlimit=%s, watcher=%s' % (
-        server_url, music_dir, api_key, bwlimit, str(enable_watcher)))
+              'bwlimit=%s' % (
+        server_url, music_dir, api_key, bwlimit))
 
     # Warn if we're running without a bandwidth limit.
     bwlimit = int(bwlimit)
@@ -82,19 +72,11 @@ def run_client(server_url, music_dir, excludes, api_key, run_once, bwlimit,
             exclude_prefix += '/'
         abs_excludes.append(os.path.realpath(exclude_prefix))
 
-    if enable_watcher and not watcher_support:
-        log.warn('inotify/fsevents support not enabled on this platform')
-        enable_watcher = False
-
     upl = upload.Uploader(server_url.rstrip('/'), api_key, abs_excludes)
     upl.setDaemon(True)
 
     # Start the full filesystem scan in the background.
-    if enable_watcher:
-        scan_delay = 3 * 86400
-    else:
-        scan_delay = 9600
-    scan = FullScan(music_dir, upl.queue, scan_delay, run_once)
+    scan = FullScan(music_dir, upl.queue, SCAN_DELAY, run_once)
     scan.setDaemon(True)
 
     if not run_once:
@@ -104,15 +86,8 @@ def run_client(server_url, music_dir, excludes, api_key, run_once, bwlimit,
             # Set 'idle' I/O scheduling class, we won't disturb other programs.
             os.system('/usr/bin/ionice -c 3 -p %d' % os.getpid())
 
-        # Start the live filesystem watcher.
-        if enable_watcher:
-            wtch = watcher.Watcher(music_dir, upl.queue)
-
         # Install termination signal handlers.
         def _cleanup(signum, frame):
-            if enable_watcher:
-                log.info('stopping watcher...')
-                wtch.stop()
             log.info('got signal %d, exiting...' % signum)
             upl.stop()
             sys.exit(0)
@@ -152,8 +127,6 @@ def main():
     parser.add_option('--bwlimit', type='int', default=0,
                       help='Upload bandwidth limit, kilobytes/s (default: '
                       'unlimited)')
-    parser.add_option('--no_realtime_watch', action='store_true',
-                      help='Monitor music_dir in realtime')
     parser.add_option('--skip_version_check', action='store_true')
     daemonize.add_standard_options(parser)
     utils.read_config_defaults(
@@ -171,13 +144,9 @@ def main():
     if not opts.skip_version_check and utils.check_version():
         print >>sys.stderr, 'A new release is available! Please update.'
 
-    # Reading from the configuration file will set this variable to
-    # a string, convert it back into boolean.
-    do_realtime = not opts.no_realtime_watch
-
     daemonize.daemonize(opts, run_client, 
                         (opts.server_url, opts.music_dir, opts.exclude, 
-                         opts.api_key, opts.once, opts.bwlimit, do_realtime))
+                         opts.api_key, opts.once, opts.bwlimit))
 
 
 if __name__ == '__main__':
diff --git a/client/djrandom_client/linux_watcher.py b/client/djrandom_client/linux_watcher.py
deleted file mode 100644
index 797e1cf..0000000
--- a/client/djrandom_client/linux_watcher.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import logging
-import pyinotify
-
-log = logging.getLogger(__name__)
-
-
-class Watcher(pyinotify.ProcessEvent):
-
-    def __init__(self, base, queue):
-        self.queue = queue
-        self.wm = pyinotify.WatchManager()
-        self.notifier = pyinotify.ThreadedNotifier(self.wm, self)
-        self.notifier.setDaemon(True)
-        self.notifier.start()
-        self.wm.add_watch(base, pyinotify.IN_CLOSE_WRITE, rec=True)
-
-    def stop(self):
-        self.notifier.stop()
-
-    def process_IN_CLOSE(self, event):
-        if event.pathname.lower().endswith('.mp3'):
-            log.debug('event in %s: %x' % (event.pathname, event.mask))
-            self.queue.put(event.pathname)
-
diff --git a/client/djrandom_client/osx_watcher.py b/client/djrandom_client/osx_watcher.py
deleted file mode 100644
index e13ac86..0000000
--- a/client/djrandom_client/osx_watcher.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import logging
-from fsevents import Observer, Stream
-from djrandom_client import filescan
-
-log = logging.getLogger(__name__)
-
-
-class Watcher(object):
-
-    def __init__(self, base, queue):
-        self.queue = queue
-        self.observer = Observer()
-        self.observer.schedule(Stream(self.callback, base))
-        self.observer.setDaemon(True)
-        self.observer.start()
-
-    def callback(self, subpath, mask):
-        log.debug('event in %s: %x' % (subpath, mask))
-        filescan.directory_scan(subpath, self.queue)
-
-    def stop(self):
-        self.observer.stop()
-
diff --git a/client/osx-ui/DJRandomUploader/ProcessController.m b/client/osx-ui/DJRandomUploader/ProcessController.m
index a16033d..b346f3c 100644
--- a/client/osx-ui/DJRandomUploader/ProcessController.m
+++ b/client/osx-ui/DJRandomUploader/ProcessController.m
@@ -54,7 +54,6 @@
         NSArray *args = [NSArray 
                          arrayWithObjects:@"--api_key", curApiKey, @"--music_dir", 
                          curMusicFolder, @"--debug", @"--foreground", 
-                         @"--no_realtime_watch",
                          nil];
         if ([curBwLimit intValue] > 0) {
             args = [args arrayByAddingObjectsFromArray:[NSArray 
-- 
GitLab