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

made the full filesystem scan delay dependant on whether the realtime fs...

made the full filesystem scan delay dependant on whether the realtime fs scanning is active; added a cli option to enable/disable realtime fs scanning
parent 062aa0b7
No related branches found
No related tags found
No related merge requests found
......@@ -15,13 +15,13 @@ from djrandom_client import utils
from djrandom_client import throttle
# Detect platform and selectively enable inotify/fsevents watchers.
enable_watcher = True
watcher_support = True
if platform.system() == 'Darwin':
import djrandom_client.osx_watcher as watcher
elif platform.system() == 'Linux':
import djrandom_client.linux_watcher as watcher
else:
enable_watcher = False
watcher_support = False
log = logging.getLogger(__name__)
......@@ -29,35 +29,44 @@ log = logging.getLogger(__name__)
class FullScan(threading.Thread):
"""Do a recursive directory scan when starting."""
def __init__(self, basedir, queue, exit_when_done=False):
def __init__(self, basedir, queue, base_delay, exit_when_done=False):
threading.Thread.__init__(self)
self.basedir = basedir
self.base_delay = base_delay
self.queue = queue
self.exit_when_done = exit_when_done
def run(self):
while True:
# Do a full scan every 3 days.
delay = 86400 * 3
delay = self.base_delay
try:
filescan.recursive_scan(self.basedir, self.queue)
except Exception, e:
log.error('Error in file scan: %s' % e)
delay = 3600
# Retry 30 minutes after an error.
delay = 1800
if self.exit_when_done:
self.queue.put(None)
break
time.sleep(delay)
def run_client(server_url, music_dir, api_key, run_once, bwlimit):
def run_client(server_url, music_dir, api_key, run_once, bwlimit, enable_watcher):
if bwlimit:
throttle.set_rate_limit(bwlimit)
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)
# Start the full filesystem scan in the background.
scan = FullScan(music_dir, upl.queue, run_once)
if enable_watcher:
scan_delay = 3 * 86400
else:
scan_delay = 9600
scan = FullScan(music_dir, upl.queue, scan_delay, run_once)
scan.setDaemon(True)
scan.start()
......@@ -71,8 +80,6 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit):
# Start the live filesystem watcher.
if enable_watcher:
wtch = watcher.Watcher(music_dir, upl.queue)
else:
log.warn('inotify/fsevents support not enabled on this platform')
# Install termination signal handlers.
def _cleanup(signum, frame):
......@@ -102,6 +109,9 @@ def main():
help='URL to the API endpoint')
parser.add_option('--bwlimit', type='int',
help='Bandwidth limit (in KBps, default unlimited)')
parser.add_option('--realtime_watch', action='store_true',
default=True,
help='Monitor music_dir in realtime')
daemonize.add_standard_options(parser)
utils.read_config_defaults(
parser, os.path.join(os.getenv('HOME'), '.djrandom.conf'))
......@@ -115,9 +125,15 @@ def main():
if args:
parser.error('Too many arguments')
# Reading from the configuration file will set this variable to
# a string, convert it back into boolean.
do_realtime = opts.realtime_watch
if isinstance(do_realtime, basestring):
do_realtime = (do_realtime.lower() in ('true', 'on', 'yes'))
daemonize.daemonize(opts, run_client,
(opts.server_url, opts.music_dir, opts.api_key,
opts.once, opts.bwlimit))
opts.once, opts.bwlimit, do_realtime))
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment