cc-4105: modularized mm2.py. fixed little bug where proper last ran time wasn't being used
This commit is contained in:
parent
517730e012
commit
76bc290623
|
@ -3,7 +3,6 @@ from kombu.messaging import Exchange, Queue, Consumer
|
||||||
from kombu.connection import BrokerConnection
|
from kombu.connection import BrokerConnection
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
if directory == None: directory = sdb.to_directory(directory_id)
|
if directory == None: directory = sdb.to_directory(directory_id)
|
||||||
try:
|
try:
|
||||||
bs = Bootstrapper( sdb, self.manager.watch_signal() )
|
bs = Bootstrapper( sdb, self.manager.watch_signal() )
|
||||||
bs.flush_watch( directory=directory, last_ran=time.time() )
|
bs.flush_watch( directory=directory, last_ran=self.cfg.last_ran() )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.info( "Exception bootstrapping: (dir,id)=(%s,%s)" %
|
self.logger.info( "Exception bootstrapping: (dir,id)=(%s,%s)" %
|
||||||
(directory, directory_id) )
|
(directory, directory_id) )
|
||||||
|
|
|
@ -18,82 +18,91 @@ import media.monitor.pure as mmp
|
||||||
|
|
||||||
from api_clients import api_client as apc
|
from api_clients import api_client as apc
|
||||||
|
|
||||||
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
|
|
||||||
global_config = os.path.join(base_path,u'live_client.cfg')
|
|
||||||
api_client_config = global_config
|
|
||||||
|
|
||||||
# MMConfig is a proxy around ConfigObj instances. it does not allow itself
|
def main(global_config, api_client_config):
|
||||||
# users of MMConfig instances to modify any config options directly through the
|
for cfg in [global_config, api_client_config]:
|
||||||
# dictionary. Users of this object muse use the correct methods designated for
|
if not os.path.exists(cfg): raise NoConfigFile(cfg)
|
||||||
# modification
|
# MMConfig is a proxy around ConfigObj instances. it does not allow
|
||||||
try: config = MMConfig(global_config)
|
# itself users of MMConfig instances to modify any config options
|
||||||
except NoConfigFile as e:
|
# directly through the dictionary. Users of this object muse use the
|
||||||
print("Cannot run mediamonitor2 without configuration file.")
|
# correct methods designated for modification
|
||||||
print("Current config path: '%s'" % global_config)
|
try: config = MMConfig(global_config)
|
||||||
sys.exit(1)
|
except NoConfigFile as e:
|
||||||
except Exception as e:
|
print("Cannot run mediamonitor2 without configuration file.")
|
||||||
print("Unknown error reading configuration file: '%s'" % global_config)
|
print("Current config path: '%s'" % global_config)
|
||||||
print(str(e))
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print("Unknown error reading configuration file: '%s'" % global_config)
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
logfile = unicode( config['logpath'] )
|
logfile = unicode( config['logpath'] )
|
||||||
setup_logging(logfile)
|
setup_logging(logfile)
|
||||||
log = get_logger()
|
log = get_logger()
|
||||||
log.info("Attempting to set the locale...")
|
log.info("Attempting to set the locale...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mmp.configure_locale(mmp.get_system_locale())
|
mmp.configure_locale(mmp.get_system_locale())
|
||||||
except FailedToSetLocale as e:
|
except FailedToSetLocale as e:
|
||||||
log.info("Failed to set the locale...")
|
log.info("Failed to set the locale...")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except FailedToObtainLocale as e:
|
except FailedToObtainLocale as e:
|
||||||
log.info("Failed to obtain the locale form the default path: \
|
log.info("Failed to obtain the locale form the default path: \
|
||||||
'/etc/default/locale'")
|
'/etc/default/locale'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.info("Failed to set the locale for unknown reason. Logging exception.")
|
log.info("Failed to set the locale for unknown reason. \
|
||||||
log.info(str(e))
|
Logging exception.")
|
||||||
|
log.info(str(e))
|
||||||
|
|
||||||
watch_syncer = WatchSyncer(signal='watch',
|
watch_syncer = WatchSyncer(signal='watch',
|
||||||
chunking_number=config['chunking_number'],
|
chunking_number=config['chunking_number'],
|
||||||
timeout=config['request_max_wait'])
|
timeout=config['request_max_wait'])
|
||||||
|
|
||||||
apiclient = apc.AirtimeApiClient.create_right_config(log=log,
|
apiclient = apc.AirtimeApiClient.create_right_config(log=log,
|
||||||
config_path=api_client_config)
|
config_path=api_client_config)
|
||||||
|
|
||||||
ReplayGainUpdater.start_reply_gain(apiclient)
|
ReplayGainUpdater.start_reply_gain(apiclient)
|
||||||
|
|
||||||
sdb = AirtimeDB(apiclient)
|
sdb = AirtimeDB(apiclient)
|
||||||
|
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
|
|
||||||
airtime_receiver = AirtimeMessageReceiver(config,manager)
|
airtime_receiver = AirtimeMessageReceiver(config,manager)
|
||||||
airtime_notifier = AirtimeNotifier(config, airtime_receiver)
|
airtime_notifier = AirtimeNotifier(config, airtime_receiver)
|
||||||
|
|
||||||
store = apiclient.setup_media_monitor()
|
store = apiclient.setup_media_monitor()
|
||||||
airtime_receiver.change_storage({ 'directory':store[u'stor'] })
|
airtime_receiver.change_storage({ 'directory':store[u'stor'] })
|
||||||
|
|
||||||
for watch_dir in store[u'watched_dirs']:
|
for watch_dir in store[u'watched_dirs']:
|
||||||
if not os.path.exists(watch_dir):
|
if not os.path.exists(watch_dir):
|
||||||
# Create the watch_directory here
|
# Create the watch_directory here
|
||||||
try: os.makedirs(watch_dir)
|
try: os.makedirs(watch_dir)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Could not create watch directory: '%s' \
|
log.error("Could not create watch directory: '%s' \
|
||||||
(given from the database)." % watch_dir)
|
(given from the database)." % watch_dir)
|
||||||
if os.path.exists(watch_dir):
|
if os.path.exists(watch_dir):
|
||||||
airtime_receiver.new_watch({ 'directory':watch_dir })
|
airtime_receiver.new_watch({ 'directory':watch_dir })
|
||||||
|
|
||||||
last_ran=config.last_ran()
|
last_ran=config.last_ran()
|
||||||
bs = Bootstrapper( db=sdb, watch_signal='watch' )
|
bs = Bootstrapper( db=sdb, watch_signal='watch' )
|
||||||
|
|
||||||
#bs.flush_all( config.last_ran() )
|
#bs.flush_all( config.last_ran() )
|
||||||
|
|
||||||
ed = EventDrainer(airtime_notifier.connection,
|
ed = EventDrainer(airtime_notifier.connection,
|
||||||
interval=float(config['rmq_event_wait']))
|
interval=float(config['rmq_event_wait']))
|
||||||
|
|
||||||
# Launch the toucher that updates the last time when the script was ran every n
|
# Launch the toucher that updates the last time when the script was
|
||||||
# seconds.
|
# ran every n seconds.
|
||||||
tt = ToucherThread(path=config['index_path'],
|
tt = ToucherThread(path=config['index_path'],
|
||||||
interval=int(config['touch_interval']))
|
interval=int(config['touch_interval']))
|
||||||
|
|
||||||
pyi = manager.pyinotify()
|
pyi = manager.pyinotify()
|
||||||
pyi.loop()
|
pyi.loop()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# TODO : parse these from command line arguments
|
||||||
|
# TODO : add log config stuff
|
||||||
|
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
|
||||||
|
global_config = os.path.join(base_path, u'live_client.cfg')
|
||||||
|
api_client_config = global_config
|
||||||
|
main(global_config, api_client_config)
|
||||||
|
|
Loading…
Reference in New Issue