From 6a0a739cef242f5342706761d95e355605d4fa97 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 22 Sep 2011 15:13:41 -0400 Subject: [PATCH 01/11] CC-2871: recorder doesn't record shows when it gets multiple shows in the schedule - fixed --- python_apps/show-recorder/recorder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index 2a6305944..178deb19b 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -256,7 +256,8 @@ class CommandListener(Thread): #remove show from shows to record. del self.shows_to_record[start_time] - self.time_till_next_show = 3600 + time_till_next_show = self.get_time_till_next_show() + self.time_till_next_show = time_till_next_show except Exception,e : self.logger.error(e) else: @@ -295,6 +296,7 @@ class CommandListener(Thread): # start recording self.start_record() except Exception, e: + self.logger.info(e) time.sleep(3) loops += 1 From a197a27d75c722fc207bdd13a29236f8f599f118 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 22 Sep 2011 16:22:47 -0400 Subject: [PATCH 02/11] -ensure liquidsoap from 1.8.2 is dead -start monit --- install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php b/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php index ebcb9358a..73931c253 100644 --- a/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php +++ b/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php @@ -763,6 +763,7 @@ exec("svc -dx /etc/service/pypo-liquidsoap/log"); exec("svc -dx /etc/service/recorder"); exec("svc -dx /etc/service/recorder/log"); exec("killall supervise"); +exec("killall liquidsoap"); $pathnames = array("/usr/bin/airtime-pypo-start", "/usr/bin/airtime-pypo-stop", @@ -819,6 +820,7 @@ AirtimeInstall::SetUniqueId(); AirtimeInstall::SetImportTimestamp(); AirtimeIni::CreateMonitFile(); +exec("/etc/init.d/monit start"); AirtimeInstall::CreateSymlinksToUtils(); From 7bb9e92ac9e32090bc57b58323079505ae6be3d9 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 22 Sep 2011 17:30:05 -0400 Subject: [PATCH 03/11] cc-2864: upgrade from 1.7 broken -fixed --- airtime_mvc/application/models/StoredFile.php | 2 +- install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 08563f98e..c66b66e97 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -730,7 +730,7 @@ class StoredFile { $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; - Logging::log(__FILE__.':uploadFile(): filename='.$fileName); + Logging::log(__FILE__.":uploadFile(): filename=$fileName to $p_targetDir"); // Clean the fileName for security reasons //this needs fixing for songs not in ascii. //$fileName = preg_replace('/[^\w\._]+/', '', $fileName); diff --git a/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php b/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php index 73931c253..38a7e8688 100644 --- a/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php +++ b/install_minimal/upgrades/airtime-1.9.0/airtime-upgrade.php @@ -677,7 +677,10 @@ class Airtime190Upgrade{ ->findOne(); /* Handle Database Changes. */ - $stor_dir = realpath($values['general']['base_files_dir']."/stor")."/"; + + $pi = pathinfo($values['general']['base_files_dir']); + $stor_dir = $pi["dirname"].DIRECTORY_SEPARATOR.$pi["basename"].DIRECTORY_SEPARATOR."stor".DIRECTORY_SEPARATOR; + echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL; $propel_stor_dir->setDirectory($stor_dir); $propel_stor_dir->save(); From cb2f4b5c7072905fe9137c6f50e24f50f13d9398 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 26 Sep 2011 17:26:48 -0400 Subject: [PATCH 04/11] CC-2889: Virtualenv fails when installing through apt repo on Ubuntu Server 10.04 -added sync commands --- install_minimal/airtime-install | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/install_minimal/airtime-install b/install_minimal/airtime-install index cf900e625..b459a5397 100755 --- a/install_minimal/airtime-install +++ b/install_minimal/airtime-install @@ -7,6 +7,11 @@ if [ `whoami` != 'root' ]; then exit 1 fi +#Sync to force flushing all buffered writes to the disk. We need to do this because +#sometimes packages that have been installed by a script before this one are +#not yet available to call. +sync + set +e DEB=$(dpkg -s airtime 2> /dev/null | grep Status) set -e @@ -59,6 +64,9 @@ else echo -e "\n*** Existing Airtime Virtualenv Found ***" fi +#Another sync to flush buffered writes to disk. +sync + virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/" . ${virtualenv_bin}activate From 6672c712caf84cd0c5e04dd388bc01cd93c95ad4 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 27 Sep 2011 15:28:00 -0400 Subject: [PATCH 05/11] CC-2889: Virtualenv fails when installing through apt repo on Ubuntu Server 10.04 -removed sync commands --- install_minimal/airtime-install | 8 -------- 1 file changed, 8 deletions(-) diff --git a/install_minimal/airtime-install b/install_minimal/airtime-install index b459a5397..cf900e625 100755 --- a/install_minimal/airtime-install +++ b/install_minimal/airtime-install @@ -7,11 +7,6 @@ if [ `whoami` != 'root' ]; then exit 1 fi -#Sync to force flushing all buffered writes to the disk. We need to do this because -#sometimes packages that have been installed by a script before this one are -#not yet available to call. -sync - set +e DEB=$(dpkg -s airtime 2> /dev/null | grep Status) set -e @@ -64,9 +59,6 @@ else echo -e "\n*** Existing Airtime Virtualenv Found ***" fi -#Another sync to flush buffered writes to disk. -sync - virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/" . ${virtualenv_bin}activate From 4e105e6151ef0106666b5aeb344c34991abc1dd5 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 28 Sep 2011 16:04:40 -0400 Subject: [PATCH 06/11] CC-2891: Unicode error with metadata that contains unicode strings -fixed --- .../application/controllers/ApiController.php | 1 + python_apps/api_clients/api_client.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 4fff61201..b74c7da94 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -112,6 +112,7 @@ class ApiController extends Zend_Controller_Action $file_base_name = substr($file_base_name, 1); header('Content-Disposition: attachment; filename="'.$file_base_name.'"'); } + $logger->info("Sending $filepath"); header("Content-Length: " . filesize($filepath)); // !! binary mode !! diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index fa1059174..194432743 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -40,10 +40,13 @@ def to_unicode(obj, encoding='utf-8'): return obj def encode_to(obj, encoding='utf-8'): - if isinstance(obj, basestring): - if not isinstance(obj, str): - obj = obj.encode(encoding) + if isinstance(obj, unicode): + obj = obj.encode(encoding) return obj + +def convert_dict_value_to_utf8: + #list comprehension to convert all values of md to utf-8 + return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()]) class ApiClientInterface: @@ -408,7 +411,9 @@ class AirTimeApiClient(ApiClientInterface): 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) - + + md = convert_dict_value_to_utf8(md) + data = urllib.urlencode(md) req = urllib2.Request(url, data) @@ -422,7 +427,7 @@ class AirTimeApiClient(ApiClientInterface): if(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'])) - url = url.replace("%%showinstanceid%%", str(md['MDATA_KEY_TRACKNUMBER'])) + url = url.replace("%%showinstanceid%%", md['MDATA_KEY_TRACKNUMBER']) logger.debug(url) url = url.replace("%%api_key%%", self.config["api_key"]) @@ -434,7 +439,7 @@ class AirTimeApiClient(ApiClientInterface): except Exception, e: response = None - logger.error("Exception with filepath %s: %s", md['MDATA_KEY_FILEPATH'], e) + logger.error("Exception with file %s: %s", md, e) return response From c7ec73e1f203769ba31caaf2eb0cace0dd722833 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 29 Sep 2011 14:45:56 -0400 Subject: [PATCH 07/11] CC-2891: Unicode error with metadata that contains unicode strings -reversed two changes talked about in code review. --- python_apps/api_clients/api_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 194432743..0064a95d5 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -44,7 +44,7 @@ def encode_to(obj, encoding='utf-8'): obj = obj.encode(encoding) return obj -def convert_dict_value_to_utf8: +def convert_dict_value_to_utf8(md): #list comprehension to convert all values of md to utf-8 return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()]) @@ -427,7 +427,7 @@ class AirTimeApiClient(ApiClientInterface): if(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'])) - url = url.replace("%%showinstanceid%%", md['MDATA_KEY_TRACKNUMBER']) + url = url.replace("%%showinstanceid%%", str(md['MDATA_KEY_TRACKNUMBER'])) logger.debug(url) url = url.replace("%%api_key%%", self.config["api_key"]) From 46146d1216ea811bca97a6e0f8173f0132a50e20 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 29 Sep 2011 15:02:30 -0400 Subject: [PATCH 08/11] cc-2882: Airtime cannot delete watched folder when is been renamed - initial commit Conflicts: airtime_mvc/application/models/MusicDir.php --- .../application/controllers/ApiController.php | 8 +++ airtime_mvc/application/models/MusicDir.php | 8 +++ airtime_mvc/application/models/StoredFile.php | 21 +++++++ python_apps/media-monitor/MediaMonitor.py | 5 +- .../airtimefilemonitor/airtimenotifier.py | 3 + .../airtimefilemonitor/airtimeprocessevent.py | 63 +++++++++++++++++-- .../airtimefilemonitor/mediaconfig.py | 1 + 7 files changed, 104 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 4fff61201..42e3f8cd1 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -518,6 +518,14 @@ class ApiController extends Zend_Controller_Action $file->delete(); } } + else if ($mode == "delete_dir") { + $filepath = $md['MDATA_KEY_FILEPATH']; + $filepath = str_replace("\\", "", $filepath); + $files = StoredFile::RecallByPartialFilepath($filepath); + foreach($files as $file){ + $file->delete(); + } + } $this->view->id = $file->getId(); } diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index d104ac268..939a40879 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -283,6 +283,14 @@ class MusicDir { public static function removeWatchedDir($p_dir){ $p_dir = realpath($p_dir)."/"; + $real_path = realpath($p_dir)."/"; + if($real_path != "/"){ + $p_dir = $real_path; + }else{ + // this is the case where user removes watched directory on + // the file system directly. + $p_dir .= "/"; + } $dir = MusicDir::getDirByPath($p_dir); if($dir == NULL){ return array("code"=>1,"error"=>"'$p_dir' doesn't exist in the watched list."); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 08563f98e..2bb59b98e 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -576,6 +576,27 @@ class StoredFile { { return StoredFile::Recall(null, null, null, $p_filepath); } + + public static function RecallByPartialFilepath($partial_path){ + $path_info = MusicDir::splitFilePath($partial_path); + + if (is_null($path_info)) { + return null; + } + $music_dir = MusicDir::getDirByPath($path_info[0]); + + $files = CcFilesQuery::create() + ->filterByDbDirectory($music_dir->getId()) + ->filterByDbFilepath("$path_info[1]%") + ->find(); + $res = array(); + foreach ($files as $file){ + $storedFile = new StoredFile(); + $storedFile->_file = $file; + $res[] = $storedFile; + } + return $res; + } public static function searchFilesForPlaylistBuilder($datatables) { global $CC_CONFIG; diff --git a/python_apps/media-monitor/MediaMonitor.py b/python_apps/media-monitor/MediaMonitor.py index 16f27a495..1b459c5f2 100644 --- a/python_apps/media-monitor/MediaMonitor.py +++ b/python_apps/media-monitor/MediaMonitor.py @@ -59,7 +59,7 @@ try: wm = WatchManager() mmc = MediaMonitorCommon(config) - pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc) + pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm, mmc=mmc, api_client=api_client) bootstrap = AirtimeMediaMonitorBootstrap(logger, pe, api_client, mmc) bootstrap.scan() @@ -89,4 +89,7 @@ except KeyboardInterrupt: notifier.stop() logger.info("Keyboard Interrupt") except Exception, e: + import traceback + top = traceback.format_exc() logger.error('Exception: %s', e) + logger.error("traceback: %s", top) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index f6952e82c..1f75f0bba 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -171,6 +171,9 @@ class AirtimeNotifier(Notifier): elif (mode == self.config.MODE_DELETE): self.api_client.update_media_metadata(md, mode) + + elif (mode == self.config.MODE_DELETE_DIR): + self.api_client.update_media_metadata(md, mode) except Exception, e: self.logger.error("failed updating filepath: %s ", event['filepath']) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 8bf25d0f6..6d891ad80 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -8,10 +8,12 @@ from pyinotify import ProcessEvent from airtimemetadata import AirtimeMetadata from airtimefilemonitor.mediaconfig import AirtimeMediaConfig +from api_clients import api_client + class AirtimeProcessEvent(ProcessEvent): #TODO - def my_init(self, queue, airtime_config=None, wm=None, mmc=None): + def my_init(self, queue, airtime_config=None, wm=None, mmc=None, api_client=api_client): """ Method automatically called from ProcessEvent.__init__(). Additional keyworded arguments passed to ProcessEvent.__init__() are then @@ -33,10 +35,63 @@ class AirtimeProcessEvent(ProcessEvent): self.wm = wm self.md_manager = AirtimeMetadata() self.mmc = mmc + self.api_client = api_client def add_filepath_to_ignore(self, filepath): self.ignore_event.add(filepath) + def process_IN_MOVE_SELF(self, event): + self.logger.info("event: %s", event) + if event.dir: + path = event.path + wd = self.wm.get_wd(path) + self.logger.info("Removing watch on: %s wd %s", path, wd) + self.wm.rm_watch(wd, rec=True) + if "-unknown-path" in path: + pos = path.find("-unknown-path") + path = path[0:pos] + + list = self.api_client.list_all_watched_dirs() + # case where the dir that is being watched is moved to somewhere + if path in list: + self.logger.info("Requesting the airtime server to remove '%s'", path) + res = self.api_client.remove_watched_dir(path) + if(res is None): + self.logger.info("Unable to connect to the Airtime server.") + # sucess + if(res['msg']['code'] == 0): + self.logger.info("%s removed from watch folder list successfully.", path) + else: + self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) + else: + self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) + + + def process_IN_DELETE_SELF(self, event): + self.logger.info("event: %s", event) + if event.dir: + path = event.path + wd = self.wm.get_wd(path) + self.logger.info("Removing watch on: %s wd %s", path, wd) + self.wm.rm_watch(wd, rec=True) + if "-unknown-path" in path: + pos = path.find("-unknown-path") + path = path[0:pos] + + list = self.api_client.list_all_watched_dirs() + if path in list: + self.logger.info("Requesting the airtime server to remove '%s'", path) + res = self.api_client.remove_watched_dir(path) + if(res is None): + self.logger.info("Unable to connect to the Airtime server.") + # sucess + if(res['msg']['code'] == 0): + self.logger.info("%s removed from watch folder list successfully.", path) + else: + self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) + else: + self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) + #event.dir: True if the event was raised against a directory. #event.name: filename #event.pathname: pathname (str): Concatenation of 'path' and 'name'. @@ -98,7 +153,7 @@ class AirtimeProcessEvent(ProcessEvent): if self.mmc.is_audio_file(event.name): self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time()) else: - self.cookies_IN_MOVED_FROM[event.cookie] = event.pathname + self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time()) #Some weird thing to note about this event: it seems that if a file is moved to a newly @@ -150,10 +205,10 @@ class AirtimeProcessEvent(ProcessEvent): for file in files: filepath = self.mmc.organize_new_file(file) if (filepath is not None): - self.file_events.append({'mode': mode, 'filepath': filepath}) + self.file_events.append({'mode': mode, 'filepath': filepath, 'is_recorded_show': False}) else: for file in files: - self.file_events.append({'mode': mode, 'filepath': file}) + self.file_events.append({'mode': mode, 'filepath': file, 'is_recorded_show': False}) def process_IN_DELETE(self, event): diff --git a/python_apps/media-monitor/airtimefilemonitor/mediaconfig.py b/python_apps/media-monitor/airtimefilemonitor/mediaconfig.py index 2b1197e24..2ddd71680 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediaconfig.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediaconfig.py @@ -8,6 +8,7 @@ class AirtimeMediaConfig: MODE_MODIFY = "modify" MODE_MOVED = "moved" MODE_DELETE = "delete" + MODE_DELETE_DIR = "delete_dir" def __init__(self, logger): From 3775e5f4a7651c3ee6a7b06d538615ea70731b04 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 28 Sep 2011 13:45:21 -0400 Subject: [PATCH 09/11] CC-2882: Airtime cannot delete watched folder when is been renamed - done --- .../application/controllers/ApiController.php | 1 + airtime_mvc/application/models/MusicDir.php | 4 -- .../airtimefilemonitor/airtimeprocessevent.py | 53 +++++++++---------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 42e3f8cd1..9e6b28d1e 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -525,6 +525,7 @@ class ApiController extends Zend_Controller_Action foreach($files as $file){ $file->delete(); } + return; } $this->view->id = $file->getId(); } diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index 939a40879..b1416ef7f 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -286,10 +286,6 @@ class MusicDir { $real_path = realpath($p_dir)."/"; if($real_path != "/"){ $p_dir = $real_path; - }else{ - // this is the case where user removes watched directory on - // the file system directly. - $p_dir .= "/"; } $dir = MusicDir::getDirByPath($p_dir); if($dir == NULL){ diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 6d891ad80..c8670bb64 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -42,44 +42,41 @@ class AirtimeProcessEvent(ProcessEvent): def process_IN_MOVE_SELF(self, event): self.logger.info("event: %s", event) + path = event.path if event.dir: - path = event.path - wd = self.wm.get_wd(path) - self.logger.info("Removing watch on: %s wd %s", path, wd) - self.wm.rm_watch(wd, rec=True) if "-unknown-path" in path: + unkown_path = path pos = path.find("-unknown-path") - path = path[0:pos] + path = path[0:pos]+"/" - list = self.api_client.list_all_watched_dirs() - # case where the dir that is being watched is moved to somewhere - if path in list: - self.logger.info("Requesting the airtime server to remove '%s'", path) - res = self.api_client.remove_watched_dir(path) - if(res is None): - self.logger.info("Unable to connect to the Airtime server.") - # sucess - if(res['msg']['code'] == 0): - self.logger.info("%s removed from watch folder list successfully.", path) + list = self.api_client.list_all_watched_dirs() + # case where the dir that is being watched is moved to somewhere + if path in list[u'dirs'].values(): + self.logger.info("Requesting the airtime server to remove '%s'", path) + res = self.api_client.remove_watched_dir(path) + if(res is None): + self.logger.info("Unable to connect to the Airtime server.") + # sucess + if(res['msg']['code'] == 0): + self.logger.info("%s removed from watch folder list successfully.", path) + else: + self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) else: - self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) - else: - self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) + # subdir being moved + # in this case, it has to remove watch manualy and also have to manually delete all records + # on cc_files table + wd = self.wm.get_wd(unkown_path) + self.logger.info("Removing watch on: %s wd %s", unkown_path, wd) + self.wm.rm_watch(wd, rec=True) + self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) def process_IN_DELETE_SELF(self, event): self.logger.info("event: %s", event) + path = event.path + '/' if event.dir: - path = event.path - wd = self.wm.get_wd(path) - self.logger.info("Removing watch on: %s wd %s", path, wd) - self.wm.rm_watch(wd, rec=True) - if "-unknown-path" in path: - pos = path.find("-unknown-path") - path = path[0:pos] - list = self.api_client.list_all_watched_dirs() - if path in list: + if path in list[u'dirs'].values(): self.logger.info("Requesting the airtime server to remove '%s'", path) res = self.api_client.remove_watched_dir(path) if(res is None): @@ -89,8 +86,6 @@ class AirtimeProcessEvent(ProcessEvent): self.logger.info("%s removed from watch folder list successfully.", path) else: self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) - else: - self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) #event.dir: True if the event was raised against a directory. #event.name: filename From ba09d712b676c2ee0ea1ba6872691ddc13cb1192 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 29 Sep 2011 10:25:38 -0400 Subject: [PATCH 10/11] CC-2882: fix misspelling - fixed --- .../media-monitor/airtimefilemonitor/airtimeprocessevent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index c8670bb64..3b3b3ac93 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -45,7 +45,7 @@ class AirtimeProcessEvent(ProcessEvent): path = event.path if event.dir: if "-unknown-path" in path: - unkown_path = path + unknown_path = path pos = path.find("-unknown-path") path = path[0:pos]+"/" @@ -65,8 +65,8 @@ class AirtimeProcessEvent(ProcessEvent): # subdir being moved # in this case, it has to remove watch manualy and also have to manually delete all records # on cc_files table - wd = self.wm.get_wd(unkown_path) - self.logger.info("Removing watch on: %s wd %s", unkown_path, wd) + wd = self.wm.get_wd(unknown_path) + self.logger.info("Removing watch on: %s wd %s", unknown_path, wd) self.wm.rm_watch(wd, rec=True) self.file_events.append({'mode': self.config.MODE_DELETE_DIR, 'filepath': path}) From 6fbf1853cee901a8b858b8e084d685bc2a159a16 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 29 Sep 2011 10:21:52 -0400 Subject: [PATCH 11/11] CC-2743: Import fails on certain files with 'Exception can't sync to an MPEG frame' - fixed by handling IN_CLOSE_WRITE instead of IN_CREATE --- .../airtimefilemonitor/airtimeprocessevent.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 3b3b3ac93..189eed7ec 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -86,16 +86,19 @@ class AirtimeProcessEvent(ProcessEvent): self.logger.info("%s removed from watch folder list successfully.", path) else: self.logger.info("Removing the watch folder failed: %s", res['msg']['error']) - + #event.dir: True if the event was raised against a directory. #event.name: filename #event.pathname: pathname (str): Concatenation of 'path' and 'name'. - def process_IN_CREATE(self, event): + # we used to use IN_CREATE event, but the IN_CREATE event gets fired before the + # copy was done. Hence, IN_CLOSE_WRITE is the correct one to handle. + def process_IN_CLOSE_WRITE(self, event): + self.logger.info("event: %s", event) self.handle_created_file(event.dir, event.pathname, event.name) - + def handle_created_file(self, dir, pathname, name): if not dir: - self.logger.debug("PROCESS_IN_CREATE: %s, name: %s, pathname: %s ", dir, name, pathname) + 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) :