From 4b6350dc2e068bd7169b361e6175d8d36db6e1b5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 14 Aug 2012 10:20:03 -0400 Subject: [PATCH] cc-4105: added some changes to ease installation --- .../install/media-monitor-copy-files.py | 23 ++++++++++--------- .../{media_monitor.py => mm1.py} | 0 python_apps/media-monitor2/mm1.99.sh | 2 +- python_apps/media-monitor2/mm2.py | 18 +++++++++++---- 4 files changed, 27 insertions(+), 16 deletions(-) rename python_apps/media-monitor/{media_monitor.py => mm1.py} (100%) diff --git a/python_apps/media-monitor/install/media-monitor-copy-files.py b/python_apps/media-monitor/install/media-monitor-copy-files.py index d47cd1811..abef74632 100644 --- a/python_apps/media-monitor/install/media-monitor-copy-files.py +++ b/python_apps/media-monitor/install/media-monitor-copy-files.py @@ -9,34 +9,35 @@ from configobj import ConfigObj if os.geteuid() != 0: print "Please run this as root." sys.exit(1) - + def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') return current_script_dir[0:index] - + def copy_dir(src_dir, dest_dir): if (os.path.exists(dest_dir)) and (dest_dir != "/"): shutil.rmtree(dest_dir) if not (os.path.exists(dest_dir)): #print "Copying directory "+os.path.realpath(src_dir)+" to "+os.path.realpath(dest_dir) shutil.copytree(src_dir, dest_dir) - + def create_dir(path): try: os.makedirs(path) + # TODO : fix this, at least print the error except Exception, e: pass - + def get_rand_string(length=10): return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length)) - + PATH_INI_FILE = '/etc/airtime/media-monitor.cfg' try: # Absolute path this script is in current_script_dir = get_current_script_dir() - + if not os.path.exists(PATH_INI_FILE): shutil.copy('%s/../media-monitor.cfg'%current_script_dir, PATH_INI_FILE) @@ -46,22 +47,22 @@ try: except Exception, e: print 'Error loading config file: ', e sys.exit(1) - + #copy monit files shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') subprocess.call('sed -i "s/\$admin_pass/%s/g" /etc/monit/conf.d/monit-airtime-generic.cfg' % get_rand_string(), shell=True) shutil.copy('%s/../monit-airtime-media-monitor.cfg'%current_script_dir, '/etc/monit/conf.d/') - + #create log dir create_dir(config['log_dir']) #copy python files copy_dir("%s/.."%current_script_dir, config["bin_dir"]) + # mm2 + #copy_dir("%s/../../media-monitor2/"%current_script_dir, config["bin_dir"]) #copy init.d script shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor") - + except Exception, e: print e - - diff --git a/python_apps/media-monitor/media_monitor.py b/python_apps/media-monitor/mm1.py similarity index 100% rename from python_apps/media-monitor/media_monitor.py rename to python_apps/media-monitor/mm1.py diff --git a/python_apps/media-monitor2/mm1.99.sh b/python_apps/media-monitor2/mm1.99.sh index 7285bdf1b..b3f9621e6 100755 --- a/python_apps/media-monitor2/mm1.99.sh +++ b/python_apps/media-monitor2/mm1.99.sh @@ -1,4 +1,4 @@ #export PYTHONPATH="/home/rudi/Airtime/python_apps/:/home/rudi/Airtime/python_apps/media-monitor2/" PYTHONPATH='/home/rudi/Airtime/python_apps/:/home/rudi/Airtime/python_apps/media-monitor2/' export PYTHONPATH -python ./mm2.py --config="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --apiclient="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --log="/home/rudi/throwaway/mm2.log" +python ./mm2.py --config="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --apiclient="/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg" --log="/home/rudi/Airtime/python_apps/media-monitor/logging.cfg" diff --git a/python_apps/media-monitor2/mm2.py b/python_apps/media-monitor2/mm2.py index 762f7ad67..923836ae3 100644 --- a/python_apps/media-monitor2/mm2.py +++ b/python_apps/media-monitor2/mm2.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import sys import os +import logging +import logging.config from media.monitor.manager import Manager from media.monitor.bootstrap import Bootstrapper @@ -16,12 +18,13 @@ from media.monitor.airtime import AirtimeNotifier, \ from media.monitor.watchersyncer import WatchSyncer from media.monitor.eventdrainer import EventDrainer from media.update.replaygainupdater import ReplayGainUpdater +from std_err_override import LogWriter import media.monitor.pure as mmp from api_clients import api_client as apc -def main(global_config, api_client_config): +def main(global_config, api_client_config, log_config): for cfg in [global_config, api_client_config]: if not os.path.exists(cfg): raise NoConfigFile(cfg) # MMConfig is a proxy around ConfigObj instances. it does not allow @@ -38,6 +41,13 @@ def main(global_config, api_client_config): print(str(e)) # TODO : use the logging config file. + logging.config.fileConfig(log_config) + + #need to wait for Python 2.7 for this.. + #logging.captureWarnings(True) + + logger = logging.getLogger() + LogWriter.override_std_err(logger) logfile = unicode( config['logpath'] ) setup_logging(logfile) log = get_logger() @@ -107,7 +117,7 @@ Options: -h --help Show this screen --config= path to mm2 config --apiclient= path to apiclient config - --log= log at + --log= log config at """ #original debugging paths @@ -118,9 +128,9 @@ Options: if __name__ == '__main__': from docopt import docopt args = docopt(__doc__,version="mm1.99") - for k in ['--apiclient','--config']: + for k in ['--apiclient','--config','--log']: if not os.path.exists(args[k]): print("'%s' must exist" % args[k]) sys.exit(0) print("Running mm1.99") - main(args['--config'],args['--apiclient']) + main(args['--config'],args['--apiclient'],args['--log'])