code cleanup
-changed module name to correct naming convention -remove some unused imports
This commit is contained in:
parent
9612adf72e
commit
dec68649c1
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import replay_gain
|
||||
import replaygain
|
||||
|
||||
import os
|
||||
import hashlib
|
||||
|
@ -126,7 +126,7 @@ class AirtimeMetadata:
|
|||
|
||||
md = {}
|
||||
|
||||
replay_gain_val = replay_gain.calculate_replay_gain(filepath)
|
||||
replay_gain_val = replaygain.calculate_replay_gain(filepath)
|
||||
self.logger.info('ReplayGain calculated as %s for %s' % (replay_gain_val, filepath))
|
||||
md['MDATA_KEY_REPLAYGAIN'] = replay_gain_val
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class MediaMonitorCommon:
|
|||
def is_readable(self, item, is_dir):
|
||||
try:
|
||||
return self.is_user_readable(item, 'www-data', 'www-data')
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
self.logger.warn(u"Failed to check owner/group/permissions for %s", item)
|
||||
return False
|
||||
|
||||
|
@ -162,7 +162,7 @@ class MediaMonitorCommon:
|
|||
try:
|
||||
os.rmdir(dir)
|
||||
self.cleanup_empty_dirs(os.path.dirname(dir))
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
#non-critical exception because we probably tried to delete a non-empty dir.
|
||||
#Don't need to log this, let's just "return"
|
||||
pass
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
import logging
|
||||
import logging.config
|
||||
import sys
|
||||
import os
|
||||
import signal
|
||||
import traceback
|
||||
import locale
|
||||
|
||||
|
@ -14,7 +12,7 @@ from configobj import ConfigObj
|
|||
from api_clients import api_client as apc
|
||||
from std_err_override import LogWriter
|
||||
|
||||
from multiprocessing import Process, Queue as mpQueue
|
||||
from multiprocessing import Queue as mpQueue
|
||||
|
||||
from threading import Thread
|
||||
|
||||
|
@ -30,11 +28,11 @@ from airtimefilemonitor.airtimemediamonitorbootstrap import AirtimeMediaMonitorB
|
|||
def configure_locale():
|
||||
logger.debug("Before %s", locale.nl_langinfo(locale.CODESET))
|
||||
current_locale = locale.getlocale()
|
||||
|
||||
|
||||
if current_locale[1] is None:
|
||||
logger.debug("No locale currently set. Attempting to get default locale.")
|
||||
default_locale = locale.getdefaultlocale()
|
||||
|
||||
|
||||
if default_locale[1] is None:
|
||||
logger.debug("No default locale exists. Let's try loading from /etc/default/locale")
|
||||
if os.path.exists("/etc/default/locale"):
|
||||
|
@ -46,31 +44,31 @@ def configure_locale():
|
|||
sys.exit(1)
|
||||
else:
|
||||
new_locale = default_locale
|
||||
|
||||
|
||||
logger.info("New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("UTF-8")
|
||||
current_locale_encoding = locale.getlocale()[1].lower()
|
||||
logger.debug("sys default encoding %s", sys.getdefaultencoding())
|
||||
logger.debug("After %s", locale.nl_langinfo(locale.CODESET))
|
||||
|
||||
|
||||
if current_locale_encoding not in ['utf-8', 'utf8']:
|
||||
logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
|
||||
|
||||
#need to wait for Python 2.7 for this..
|
||||
#logging.captureWarnings(True)
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
LogWriter.override_std_err(logger)
|
||||
|
||||
|
||||
except Exception, e:
|
||||
print 'Error configuring logging: ', e
|
||||
sys.exit(1)
|
||||
|
@ -80,17 +78,17 @@ logger.info("\n\n*** Media Monitor bootup ***\n\n")
|
|||
|
||||
try:
|
||||
configure_locale()
|
||||
|
||||
|
||||
config = AirtimeMediaConfig(logger)
|
||||
api_client = apc.api_client_factory(config.cfg)
|
||||
api_client.register_component("media-monitor")
|
||||
|
||||
|
||||
logger.info("Setting up monitor")
|
||||
response = None
|
||||
while response is None:
|
||||
response = api_client.setup_media_monitor()
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
storage_directory = response["stor"]
|
||||
watched_dirs = response["watched_dirs"]
|
||||
logger.info("Storage Directory is: %s", storage_directory)
|
||||
|
@ -99,12 +97,12 @@ try:
|
|||
config.organize_directory = os.path.normpath(os.path.join(storage_directory, 'organize'))
|
||||
config.recorded_directory = os.path.normpath(os.path.join(storage_directory, 'recorded'))
|
||||
config.problem_directory = os.path.normpath(os.path.join(storage_directory, 'problem_files'))
|
||||
|
||||
|
||||
dirs = [config.imported_directory, config.organize_directory, config.recorded_directory, config.problem_directory]
|
||||
for d in dirs:
|
||||
if not os.path.exists(d):
|
||||
os.makedirs(d, 02775)
|
||||
|
||||
|
||||
multi_queue = mpQueue()
|
||||
logger.info("Initializing event processor")
|
||||
|
||||
|
@ -114,7 +112,7 @@ try:
|
|||
|
||||
bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc, wm, config)
|
||||
bootstrap.scan()
|
||||
|
||||
|
||||
notifier = AirtimeNotifier(wm, pe, read_freq=0, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap, mmc=mmc)
|
||||
notifier.coalesce_events()
|
||||
|
||||
|
@ -124,18 +122,18 @@ try:
|
|||
threadName = "Thread #%d" % i
|
||||
t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))
|
||||
t.start()
|
||||
|
||||
|
||||
wdd = notifier.watch_directory(storage_directory)
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
logger.info("wdd result %s", wdd[storage_directory])
|
||||
|
||||
|
||||
for dir in watched_dirs:
|
||||
wdd = notifier.watch_directory(dir)
|
||||
logger.info("Added watch to %s", dir)
|
||||
logger.info("wdd result %s", wdd[dir])
|
||||
|
||||
notifier.loop(callback=pe.notifier_loop_callback)
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
notifier.stop()
|
||||
logger.info("Keyboard Interrupt")
|
||||
|
|
Loading…
Reference in New Issue