configure locale for pypo

This commit is contained in:
Martin Konecny 2012-04-27 17:25:12 -04:00
parent 47051c460e
commit cf1e9e7615
3 changed files with 45 additions and 10 deletions

View file

@ -88,10 +88,10 @@ class AirtimeMediaMonitorBootstrap():
for file in files['files']:
db_known_files_set.add(file)
new_files = self.mmc.scan_dir_for_new_files(dir)
all_files = self.mmc.scan_dir_for_new_files(dir)
all_files_set = set()
for file_path in new_files:
for file_path in all_files:
if len(file_path.strip(" \n")) > 0:
all_files_set.add(file_path[len(dir):])
@ -106,8 +106,8 @@ class AirtimeMediaMonitorBootstrap():
else:
command = "find %s -type f -iname '*.ogg' -o -iname '*.mp3' -readable" % dir
self.logger.debug(command)
stdout = self.mmc.exec_command(command)
#self.logger.info(stdout)
new_files = stdout.splitlines()
@ -150,7 +150,6 @@ class AirtimeMediaMonitorBootstrap():
if os.path.exists(full_file_path):
self.pe.handle_created_file(False, full_file_path, os.path.basename(full_file_path))
for file_path in modified_files_set:
self.logger.debug("modified file")
full_file_path = "%s%s" % (dir, file_path)

View file

@ -25,7 +25,7 @@ from airtimefilemonitor.mediaconfig import AirtimeMediaConfig
from airtimefilemonitor.workerprocess import MediaMonitorWorkerProcess
from airtimefilemonitor.airtimemediamonitorbootstrap import AirtimeMediaMonitorBootstrap
def get_locale():
def configure_locale():
current_locale = locale.getlocale()
if current_locale[1] is None:
@ -70,7 +70,7 @@ logger.info("\n\n*** Media Monitor bootup ***\n\n")
try:
get_locale()
configure_locale()
config = AirtimeMediaConfig(logger)
api_client = apc.api_client_factory(config.cfg)

View file

@ -9,6 +9,8 @@ import signal
import logging
import logging.config
import logging.handlers
import locale
import os
from Queue import Queue
from threading import Lock
@ -44,14 +46,48 @@ parser.add_option("-c", "--check", help="Check the cached schedule and exit", de
# parse options
(options, args) = parser.parse_args()
# configure logging
logging.config.fileConfig("logging.cfg")
logger = logging.getLogger()
LogWriter.override_std_err(logger)
#need to wait for Python 2.7 for this..
#logging.captureWarnings(True)
def configure_locale():
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"):
config = ConfigObj('/etc/default/locale')
lang = config.get('LANG')
new_locale = lang
else:
logger.error("/etc/default/locale could not be found! Please run 'sudo update-locale' from command-line.")
sys.exit(1)
else:
new_locale = default_locale
logger.debug("New locale set to: " + locale.setlocale(locale.LC_ALL, new_locale))
current_locale_encoding = locale.getlocale()[1].lower()
if current_locale_encoding not in ['utf-8', 'utf8']:
logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding)
# 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()
configure_locale()
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')