CC-3789: Need to place rejected files into /problem_files directory
-done
This commit is contained in:
parent
f769472252
commit
4caba5bdea
4 changed files with 26 additions and 8 deletions
|
@ -15,12 +15,13 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
pe -- reference to an instance of ProcessEvent
|
pe -- reference to an instance of ProcessEvent
|
||||||
api_clients -- reference of api_clients to communicate with airtime-server
|
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.logger = logger
|
||||||
self.pe = pe
|
self.pe = pe
|
||||||
self.api_client = api_client
|
self.api_client = api_client
|
||||||
self.mmc = mmc
|
self.mmc = mmc
|
||||||
self.wm = wm
|
self.wm = wm
|
||||||
|
self.config = config
|
||||||
# add /etc on watch list so we can detect mount
|
# add /etc on watch list so we can detect mount
|
||||||
self.mount_file = "/etc"
|
self.mount_file = "/etc"
|
||||||
self.curr_mtab_file = "/var/tmp/airtime/media-monitor/currMtab"
|
self.curr_mtab_file = "/var/tmp/airtime/media-monitor/currMtab"
|
||||||
|
@ -91,7 +92,8 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
all_files_set = set()
|
all_files_set = set()
|
||||||
for file_path in all_files:
|
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):])
|
all_files_set.add(file_path[len(dir):])
|
||||||
|
|
||||||
# if dir doesn't exists, update db
|
# if dir doesn't exists, update db
|
||||||
|
@ -116,7 +118,8 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
new_and_modified_files = set()
|
new_and_modified_files = set()
|
||||||
for file_path in new_files:
|
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):])
|
new_and_modified_files.add(file_path[len(dir):])
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -235,6 +235,9 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
filename = self.mount_file_dir +"/mtab"
|
filename = self.mount_file_dir +"/mtab"
|
||||||
if event.pathname in filename:
|
if event.pathname in filename:
|
||||||
self.handle_mount_change()
|
self.handle_mount_change()
|
||||||
|
|
||||||
|
if event.path in self.config.problem_directory:
|
||||||
|
return
|
||||||
|
|
||||||
if not event.dir:
|
if not event.dir:
|
||||||
if self.mmc.is_audio_file(event.name):
|
if self.mmc.is_audio_file(event.name):
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
from mediaconfig import AirtimeMediaConfig
|
from mediaconfig import AirtimeMediaConfig
|
||||||
import mediamonitorcommon
|
import mediamonitorcommon
|
||||||
import traceback
|
import traceback
|
||||||
|
import os
|
||||||
|
|
||||||
class MediaMonitorWorkerProcess:
|
class MediaMonitorWorkerProcess:
|
||||||
|
|
||||||
|
def __init__(self, config, mmc):
|
||||||
|
self.config = config
|
||||||
|
self.mmc = mmc
|
||||||
|
|
||||||
#this function is run in its own process, and continuously
|
#this function is run in its own process, and continuously
|
||||||
#checks the queue for any new file events.
|
#checks the queue for any new file events.
|
||||||
|
@ -17,6 +22,7 @@ class MediaMonitorWorkerProcess:
|
||||||
notifier.update_airtime(event)
|
notifier.update_airtime(event)
|
||||||
else:
|
else:
|
||||||
notifier.logger.warn("Liquidsoap integrity check for file at %s failed. Not adding to media library.", filepath)
|
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:
|
else:
|
||||||
notifier.update_airtime(event)
|
notifier.update_airtime(event)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
|
@ -87,9 +87,15 @@ try:
|
||||||
watched_dirs = apc.encode_to(response["watched_dirs"], 'utf-8')
|
watched_dirs = apc.encode_to(response["watched_dirs"], 'utf-8')
|
||||||
logger.info("Storage Directory is: %s", storage_directory)
|
logger.info("Storage Directory is: %s", storage_directory)
|
||||||
config.storage_directory = os.path.normpath(storage_directory)
|
config.storage_directory = os.path.normpath(storage_directory)
|
||||||
config.imported_directory = os.path.normpath(storage_directory + '/imported')
|
config.imported_directory = os.path.normpath(os.path.join(storage_directory, 'imported'))
|
||||||
config.organize_directory = os.path.normpath(storage_directory + '/organize')
|
config.organize_directory = os.path.normpath(os.path.join(storage_directory, 'organize'))
|
||||||
config.recorded_directory = os.path.normpath(storage_directory + '/recorded')
|
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()
|
multi_queue = mpQueue()
|
||||||
logger.info("Initializing event processor")
|
logger.info("Initializing event processor")
|
||||||
|
@ -98,14 +104,14 @@ try:
|
||||||
mmc = MediaMonitorCommon(config, wm=wm)
|
mmc = MediaMonitorCommon(config, wm=wm)
|
||||||
pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc, api_client=api_client)
|
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()
|
bootstrap.scan()
|
||||||
|
|
||||||
notifier = AirtimeNotifier(wm, pe, read_freq=0, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap, mmc=mmc)
|
notifier = AirtimeNotifier(wm, pe, read_freq=0, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap, mmc=mmc)
|
||||||
notifier.coalesce_events()
|
notifier.coalesce_events()
|
||||||
|
|
||||||
#create 5 worker threads
|
#create 5 worker threads
|
||||||
wp = MediaMonitorWorkerProcess()
|
wp = MediaMonitorWorkerProcess(config, mmc)
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
threadName = "Thread #%d" % i
|
threadName = "Thread #%d" % i
|
||||||
t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))
|
t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue