CC-3789: Need to place rejected files into /problem_files directory

-done
This commit is contained in:
Martin Konecny 2012-05-09 00:02:02 -04:00
parent f769472252
commit 4caba5bdea
4 changed files with 26 additions and 8 deletions

View file

@ -15,12 +15,13 @@ class AirtimeMediaMonitorBootstrap():
pe -- reference to an instance of ProcessEvent
api_clients -- reference of api_clients to communicate with airtime-server
"""
def __init__(self, logger, pe, api_client, mmc, wm):
def __init__(self, logger, pe, api_client, mmc, wm, config):
self.logger = logger
self.pe = pe
self.api_client = api_client
self.mmc = mmc
self.wm = wm
self.config = config
# add /etc on watch list so we can detect mount
self.mount_file = "/etc"
self.curr_mtab_file = "/var/tmp/airtime/media-monitor/currMtab"
@ -91,7 +92,8 @@ class AirtimeMediaMonitorBootstrap():
all_files_set = set()
for file_path in all_files:
if len(file_path.strip(" \n")) > 0:
file_path = file_path.strip(" \n")
if len(file_path) > 0 and self.config.problem_directory not in file_path:
all_files_set.add(file_path[len(dir):])
# if dir doesn't exists, update db
@ -116,7 +118,8 @@ class AirtimeMediaMonitorBootstrap():
new_and_modified_files = set()
for file_path in new_files:
if len(file_path.strip(" \n")) > 0:
file_path = file_path.strip(" \n")
if len(file_path) > 0 and self.config.problem_directory not in file_path:
new_and_modified_files.add(file_path[len(dir):])
"""

View file

@ -235,6 +235,9 @@ class AirtimeProcessEvent(ProcessEvent):
filename = self.mount_file_dir +"/mtab"
if event.pathname in filename:
self.handle_mount_change()
if event.path in self.config.problem_directory:
return
if not event.dir:
if self.mmc.is_audio_file(event.name):

View file

@ -1,8 +1,13 @@
from mediaconfig import AirtimeMediaConfig
import mediamonitorcommon
import traceback
import os
class MediaMonitorWorkerProcess:
def __init__(self, config, mmc):
self.config = config
self.mmc = mmc
#this function is run in its own process, and continuously
#checks the queue for any new file events.
@ -17,6 +22,7 @@ class MediaMonitorWorkerProcess:
notifier.update_airtime(event)
else:
notifier.logger.warn("Liquidsoap integrity check for file at %s failed. Not adding to media library.", filepath)
self.mmc.move_file(filepath, os.path.join(self.config.problem_directory, os.path.basename(filepath)))
else:
notifier.update_airtime(event)
except Exception, e:

View file

@ -87,9 +87,15 @@ try:
watched_dirs = apc.encode_to(response["watched_dirs"], 'utf-8')
logger.info("Storage Directory is: %s", storage_directory)
config.storage_directory = os.path.normpath(storage_directory)
config.imported_directory = os.path.normpath(storage_directory + '/imported')
config.organize_directory = os.path.normpath(storage_directory + '/organize')
config.recorded_directory = os.path.normpath(storage_directory + '/recorded')
config.imported_directory = os.path.normpath(os.path.join(storage_directory, 'imported'))
config.organize_directory = os.path.normpath(os.path.join(storage_directory, 'organize'))
config.recorded_directory = os.path.normpath(os.path.join(storage_directory, 'recorded'))
config.problem_directory = os.path.normpath(os.path.join(storage_directory, 'problem_files'))
dirs = [config.imported_directory, config.organize_directory, config.recorded_directory, config.problem_directory]
for d in dirs:
if not os.path.exists(d):
os.makedirs(d, 02775)
multi_queue = mpQueue()
logger.info("Initializing event processor")
@ -98,14 +104,14 @@ try:
mmc = MediaMonitorCommon(config, wm=wm)
pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc, api_client=api_client)
bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc, wm)
bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc, wm, config)
bootstrap.scan()
notifier = AirtimeNotifier(wm, pe, read_freq=0, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap, mmc=mmc)
notifier.coalesce_events()
#create 5 worker threads
wp = MediaMonitorWorkerProcess()
wp = MediaMonitorWorkerProcess(config, mmc)
for i in range(5):
threadName = "Thread #%d" % i
t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))