From 0c6144a0f6ccf3207b57e2acacefad2eb04fffe2 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 9 May 2012 01:02:49 -0400 Subject: [PATCH] CC-3789: Need to place rejected files into /problem_files directory -make test_file_playability() a class method --- .../airtimefilemonitor/mediamonitorcommon.py | 22 ++++++------------- .../airtimefilemonitor/workerprocess.py | 3 +-- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index d6d0798f4..11a44ae02 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -138,7 +138,6 @@ class MediaMonitorCommon: #moves file from source to dest but also recursively removes the #the source file's parent directories if they are now empty. def move_file(self, source, dest): - try: omask = os.umask(0) os.rename(source, dest) @@ -321,22 +320,15 @@ class MediaMonitorCommon: return filepath -def test_file_playability(pathname): - """ - Test if the file can be played by Liquidsoap. Return "True" if Liquidsoap - can play it, or if Liquidsoap is not found. - """ - liquidsoap_found = subprocess.call("which liquidsoap", shell=True) - if liquidsoap_found == 0: - #return_code = subprocess.call("liquidsoap -r \"%s\"" % pathname.replace('"', '\\"'), shell=True) - + def test_file_playability(self, pathname): #when there is an single apostrophe inside of a string quoted by apostrophes, we can only escape it by replace that apostrophe #with '\''. This breaks the string into two, and inserts an escaped single quote in between them. #We run the command as pypo because otherwise the target file is opened with write permissions, and this causes an inotify ON_CLOSE_WRITE event #to be fired :/ - command = "sudo -u pypo liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))'" % pathname.replace("'", "'\\''") + command = "sudo -u pypo liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))' > /dev/null 2>&1" % pathname.replace("'", "'\\''") return_code = subprocess.call(command, shell=True) - else: - return_code = 0 - - return (return_code == 0) + if return_code != 0: + #print pathname for py-interpreter.log + print pathname + + return (return_code == 0) diff --git a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py index ec98e0924..e29749ad9 100644 --- a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py +++ b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py @@ -1,5 +1,4 @@ from mediaconfig import AirtimeMediaConfig -import mediamonitorcommon import traceback import os @@ -18,7 +17,7 @@ class MediaMonitorWorkerProcess: notifier.logger.info("received event %s", event) if event['mode'] == AirtimeMediaConfig.MODE_CREATE: filepath = event['filepath'] - if mediamonitorcommon.test_file_playability(filepath): + if self.mmc.test_file_playability(filepath): notifier.update_airtime(event) else: notifier.logger.warn("Liquidsoap integrity check for file at %s failed. Not adding to media library.", filepath)