CC-5709: Airtime Analyzer

* Make the airtime_analyzer config path a runtime param
This commit is contained in:
Albert Santoni 2014-04-01 12:28:40 -04:00
parent 70228a675e
commit 12c16bc120
2 changed files with 12 additions and 7 deletions

View file

@ -10,19 +10,18 @@ from message_listener import MessageListener
class AirtimeAnalyzerServer: class AirtimeAnalyzerServer:
# Constants # Constants
_CONFIG_PATH = '/etc/airtime/airtime.conf'
_LOG_PATH = "/var/log/airtime/airtime_analyzer.log" _LOG_PATH = "/var/log/airtime/airtime_analyzer.log"
# Variables # Variables
_log_level = logging.INFO _log_level = logging.INFO
def __init__(self, debug=False): def __init__(self, config_path, debug=False):
# Configure logging # Configure logging
self.setup_logging(debug) self.setup_logging(debug)
# Read our config file # Read our config file
rabbitmq_config = self.read_config_file() rabbitmq_config = self.read_config_file(config_path)
# Start listening for RabbitMQ messages telling us about newly # Start listening for RabbitMQ messages telling us about newly
# uploaded files. # uploaded files.
@ -55,9 +54,8 @@ class AirtimeAnalyzerServer:
rootLogger.addHandler(consoleHandler) rootLogger.addHandler(consoleHandler)
def read_config_file(self): def read_config_file(self, config_path):
config = ConfigParser.SafeConfigParser() config = ConfigParser.SafeConfigParser()
config_path = AirtimeAnalyzerServer._CONFIG_PATH
try: try:
config.readfp(open(config_path)) config.readfp(open(config_path))
except IOError as e: except IOError as e:

View file

@ -6,12 +6,14 @@ import os
import airtime_analyzer.airtime_analyzer as aa import airtime_analyzer.airtime_analyzer as aa
VERSION = "1.0" VERSION = "1.0"
DEFAULT_CONFIG_PATH = '/etc/airtime/airtime.conf'
print "Airtime Analyzer " + VERSION print "Airtime Analyzer " + VERSION
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true") parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true")
parser.add_argument("--debug", help="log full debugging output", action="store_true") parser.add_argument("--debug", help="log full debugging output", action="store_true")
parser.add_argument("--rmq-config-file", help="specify a configuration file with RabbitMQ settings (default is /etc/airtime/airtime.conf)")
args = parser.parse_args() args = parser.parse_args()
'''Ensure media_monitor isn't running before we start, because it'll move newly uploaded '''Ensure media_monitor isn't running before we start, because it'll move newly uploaded
@ -33,10 +35,15 @@ def check_if_media_monitor_is_running():
check_if_media_monitor_is_running() check_if_media_monitor_is_running()
#Default config file path
config_path = DEFAULT_CONFIG_PATH
if args.rmq_config_file:
config_path = args.rmq_config_file
if args.daemon: if args.daemon:
with daemon.DaemonContext(): with daemon.DaemonContext():
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug) analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)
else: else:
# Run without daemonizing # Run without daemonizing
analyzer = aa.AirtimeAnalyzerServer(debug=args.debug) analyzer = aa.AirtimeAnalyzerServer(config_path=config_path, debug=args.debug)