From 7376e1607746b4fffde01fd557302e6175c411f1 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 8 May 2012 16:26:33 -0400 Subject: [PATCH] CC-3784: Some media files can be added twice when trying to upload 200 media files -should be fixed --- install_full/ubuntu/airtime-full-install | 2 +- .../ubuntu/airtime-full-install-nginx | 2 +- python_apps/api_clients/api_client.py | 6 ---- .../airtimefilemonitor/airtimeprocessevent.py | 28 +++++++++++-------- .../airtimefilemonitor/mediamonitorcommon.py | 4 ++- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/install_full/ubuntu/airtime-full-install b/install_full/ubuntu/airtime-full-install index 613f9ba5b..792a5682f 100755 --- a/install_full/ubuntu/airtime-full-install +++ b/install_full/ubuntu/airtime-full-install @@ -39,7 +39,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \ libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \ libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \ php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \ -libpulse0 vorbis-tools lsb-release lsof +libpulse0 vorbis-tools lsb-release lsof sudo #install packages with --force-yes option (this is useful in the case #of Debian, where these packages are unauthorized) diff --git a/install_full/ubuntu/airtime-full-install-nginx b/install_full/ubuntu/airtime-full-install-nginx index c474f255d..6bfaa9d82 100755 --- a/install_full/ubuntu/airtime-full-install-nginx +++ b/install_full/ubuntu/airtime-full-install-nginx @@ -42,7 +42,7 @@ php-pear php5-gd postgresql odbc-postgresql python libsoundtouch-ocaml \ libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \ libesd0 libportaudio2 libsamplerate0 rabbitmq-server patch \ php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data \ -libpulse0 vorbis-tools lsb-release lsof +libpulse0 vorbis-tools lsb-release lsof sudo #install packages with --force-yes option (this is useful in the case #of Debian, where these packages are unauthorized) diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index b2aa1d586..619e10c72 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -406,9 +406,6 @@ class AirTimeApiClient(ApiClientInterface): logger = self.logger response = None try: - - start = time.time() - url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_media_url"]) url = url.replace("%%api_key%%", self.config["api_key"]) url = url.replace("%%mode%%", mode) @@ -422,9 +419,6 @@ class AirTimeApiClient(ApiClientInterface): logger.info("update media %s, filepath: %s, mode: %s", response, md['MDATA_KEY_FILEPATH'], mode) response = json.loads(response) - elapsed = (time.time() - start) - logger.info("time taken to get response %s", elapsed) - if("error" not in response and is_record): url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"]) url = url.replace("%%fileid%%", str(response[u'id'])) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 43a665a59..fc7720692 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -117,15 +117,15 @@ class AirtimeProcessEvent(ProcessEvent): self.logger.info("event: %s", event) self.logger.info("create_dict: %s", self.create_dict) - if event.pathname in self.create_dict: - # detele corresponding entry from create_dict - self.create_dict.pop(event.pathname) + try: + del self.create_dict[event.pathname] self.handle_created_file(event.dir, event.pathname, event.name) + except KeyError, e: + self.logger.error("%s does not exist in create_dict", event.pathname) def handle_created_file(self, dir, pathname, name): if not dir: self.logger.debug("PROCESS_IN_CLOSE_WRITE: %s, name: %s, pathname: %s ", dir, name, pathname) - #event is because of a created file if self.mmc.is_temp_file(name) : #file created is a tmp file which will be modified and then moved back to the original filename. @@ -150,10 +150,13 @@ class AirtimeProcessEvent(ProcessEvent): except Exception, e: self.logger.error('Exception: %s', e) self.logger.error("traceback: %s", traceback.format_exc()) - return - - is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory) - self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded}) + finally: + return + else: + # only append to self.file_events if the file isn't going to be altered by organize_new_file(). If file is going + # to be altered by organize_new_file(), then process_IN_MOVED_TO event will handle appending it to self.file_events + is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory) + self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': pathname, 'is_recorded_show': is_recorded}) def process_IN_MODIFY(self, event): @@ -239,7 +242,7 @@ class AirtimeProcessEvent(ProcessEvent): self.file_events.append({'filepath': event.pathname, 'mode': self.config.MODE_MODIFY}) del self.temp_files[event.cookie] elif event.cookie in self.cookies_IN_MOVED_FROM: - #files original location was also in a watched directory + #file's original location was also in a watched directory del self.cookies_IN_MOVED_FROM[event.cookie] if self.mmc.is_parent_directory(event.pathname, self.config.organize_directory): filepath = self.mmc.organize_new_file(event.pathname) @@ -263,17 +266,18 @@ class AirtimeProcessEvent(ProcessEvent): if self.mmc.is_parent_directory(event.pathname, self.config.organize_directory): filepath = self.mmc.organize_new_file(event.pathname) - #delete files from organize if they can not be read properly. + #delete files from organize if they cannot be read properly. if filepath is None: try: self.logger.info("Deleting file because it cannot be read properly: %s", event.pathname) os.remove(event.pathname) - return except Exception, e: self.logger.error('Exception: %s', e) self.logger.error("traceback: %s", traceback.format_exc()) + finally: + return else: - #show dragged from unwatched folder into a watched folder. Do not "organize".:q! + #show moved from unwatched folder into a watched folder. Do not "organize". if self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory): is_recorded = True else: diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index 786c3888f..3b9060fec 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -335,7 +335,9 @@ def test_file_playability(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. - command = "liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))'" % pathname.replace("'", "'\\''") + #We run the command as pypo because otherwise the target file is opened with write permissions, and this causes an ON_CLOSE_WRITE event + #to be fired :/ + command = "sudo -u pypo liquidsoap -c 'output.dummy(audio_to_stereo(single(\"%s\")))'" % pathname.replace("'", "'\\''") return_code = subprocess.call(command, shell=True) else: return_code = 0