Example #1
0
def setup_logger(log_config, logpath):
    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(logpath)
    setup_logging(logfile)
    log = get_logger()
    return log
Example #2
0
def setup_logger(log_config, logpath):
    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(logpath)
    setup_logging(logfile)
    log = get_logger()
    return log
Example #3
0
    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)

logger.info("\n\n*** Media Monitor bootup ***\n\n")


try:
    configure_locale()

    config = AirtimeMediaConfig(logger)
    api_client = apc.AirtimeApiClient()
    api_client.register_component("media-monitor")
Example #4
0
                  action="store_true",
                  dest="check")

# parse options
(options, args) = parser.parse_args()

LIQUIDSOAP_MIN_VERSION = "1.1.1"

#need to wait for Python 2.7 for this..
#logging.captureWarnings(True)

# configure logging
try:
    logging.config.fileConfig("logging.cfg")
    logger = logging.getLogger()
    LogWriter.override_std_err(logger)
except Exception, e:
    print "Couldn't configure logging"
    sys.exit(1)


def configure_locale():
    """
    Silly hacks to force Python 2.x to run in UTF-8 mode. Not portable at all,
    however serves our purpose at the moment.

    More information available here:
    http://stackoverflow.com/questions/3828723/why-we-need-sys-setdefaultencodingutf-8-in-a-py-script
    """
    logger.debug("Before %s", locale.nl_langinfo(locale.CODESET))
    current_locale = locale.getlocale()
Example #5
0
def main(global_config, api_client_config, log_config,
        index_create_attempt=False):
    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
    # itself users of MMConfig instances to modify any config options
    # directly through the dictionary. Users of this object muse use the
    # correct methods designated for modification
    try: config = MMConfig(global_config)
    except NoConfigFile as e:
        print("Cannot run mediamonitor2 without configuration file.")
        print("Current config path: '%s'" % global_config)
        sys.exit(1)
    except Exception as e:
        print("Unknown error reading configuration file: '%s'" % global_config)
        print(str(e))


    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()

    if not index_create_attempt:
        if not os.path.exists(config['index_path']):
            log.info("Attempting to create index file:...")
            try:
                with open(config['index_path'], 'w') as f: f.write(" ")
            except Exception as e:
                log.info("Failed to create index file with exception: %s" % str(e))
            else:
                log.info("Created index file, reloading configuration:")
                main( global_config,  api_client_config, log_config,
                        index_create_attempt=True )
    else:
        log.info("Already tried to create index. Will not try again ")

    if not os.path.exists(config['index_path']):
        log.info("Index file does not exist. Terminating")

    log.info("Attempting to set the locale...")

    try:
        mmp.configure_locale(mmp.get_system_locale())
    except FailedToSetLocale as e:
        log.info("Failed to set the locale...")
        sys.exit(1)
    except FailedToObtainLocale as e:
        log.info("Failed to obtain the locale form the default path: \
                '/etc/default/locale'")
        sys.exit(1)
    except Exception as e:
        log.info("Failed to set the locale for unknown reason. \
                Logging exception.")
        log.info(str(e))

    watch_syncer = WatchSyncer(signal='watch',
                               chunking_number=config['chunking_number'],
                               timeout=config['request_max_wait'])

    apiclient = apc.AirtimeApiClient.create_right_config(log=log,
            config_path=api_client_config)

    ReplayGainUpdater.start_reply_gain(apiclient)

    sdb = AirtimeDB(apiclient)

    manager = Manager()

    airtime_receiver = AirtimeMessageReceiver(config,manager)
    airtime_notifier = AirtimeNotifier(config, airtime_receiver)

    store = apiclient.setup_media_monitor()
    airtime_receiver.change_storage({ 'directory':store[u'stor'] })

    for watch_dir in store[u'watched_dirs']:
        if not os.path.exists(watch_dir):
            # Create the watch_directory here
            try: os.makedirs(watch_dir)
            except Exception as e:
                log.error("Could not create watch directory: '%s' \
                        (given from the database)." % watch_dir)
        if os.path.exists(watch_dir):
            airtime_receiver.new_watch({ 'directory':watch_dir }, restart=True)

    bs = Bootstrapper( db=sdb, watch_signal='watch' )

    ed = EventDrainer(airtime_notifier.connection,
            interval=float(config['rmq_event_wait']))

    # Launch the toucher that updates the last time when the script was
    # ran every n seconds.
    # TODO : verify that this does not interfere with bootstrapping because the
    # toucher thread might update the last_ran variable too fast
    tt = ToucherThread(path=config['index_path'],
                       interval=int(config['touch_interval']))

    apiclient.register_component('media-monitor')

    manager.loop()