Skip to content
Snippets Groups Projects
Commit d2ee60b3 authored by ale's avatar ale
Browse files

remove support for realtime filesystem watches to simplify the client even...

remove support for realtime filesystem watches to simplify the client even more (besides, it never worked on linux)
parent 3ae7e9d1
No related branches found
No related tags found
No related merge requests found
......@@ -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__':
......
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)
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()
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment