From 3422eb3cc063142e769129b7dfd62de77a0c4f7f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 27 Jul 2012 10:27:30 -0400 Subject: [PATCH] cc-4105: added event packing to event objects --- .../application/controllers/ApiController.php | 3 +++ python_apps/api_clients/api_client.py | 7 ++++--- .../media-monitor2/media/monitor/events.py | 17 +++++++++++++++++ .../media-monitor2/media/monitor/metadata.py | 1 + .../media/monitor/watchersyncer.py | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 4d6ae2f9e..5a9c547ae 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -468,6 +468,7 @@ class ApiController extends Zend_Controller_Action ); } Application_Model_Preference::SetImportTimestamp(); + Logging::log("--->Mode: $mode and file: {$md['MDATA_KEY_FILEPATH']} "); if ($mode == "create") { $filepath = $md['MDATA_KEY_FILEPATH']; $filepath = Application_Common_OsPath::normpath($filepath); @@ -539,6 +540,7 @@ class ApiController extends Zend_Controller_Action return $return_hash; } $return_hash['fileid'] = $file->getId(); + Logging::log("Have we returned jack shit???"); return $return_hash; } @@ -591,6 +593,7 @@ class ApiController extends Zend_Controller_Action $this->uploadRecordedActionParam($info_json['showinstanceid'],$info_json['fileid'],$dry_run=$dry); } } + Logging::log("returning response ><<><><><><><><"); die( json_encode($responses) ); } diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index bb5fbe737..04865b783 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -51,8 +51,8 @@ class AirtimeApiClient(): # file @staticmethod def create_right_config(log=None,config_path=None): - if config_path: default_config = config_path - return AirtimeApiClient( logger=None, config_path=default_config ) + if config_path: AirtimeApiClient.default_config = config_path + return AirtimeApiClient( logger=None, config_path=AirtimeApiClient.default_config ) def __init__(self, logger=None,config_path='/etc/airtime/api_client.cfg'): if logger is None: @@ -403,7 +403,7 @@ class AirtimeApiClient(): # debugging for action in action_list: if not 'mode' in action: - self.logger.debug("Warning: Sending a request element without a 'mode'") + self.logger.debug("Warning: Trying to send a request element without a 'mode'") self.logger.debug("Here is the the request: '%s'" % str(action) ) else: # We alias the value of is_record to true or false no @@ -428,6 +428,7 @@ class AirtimeApiClient(): response = json.loads(response) return response except Exception, e: + import ipdb; ipdb.set_trace() logger.error('Exception: %s', e) logger.error("traceback: %s", traceback.format_exc()) raise diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 4e7490c9f..402a10621 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -35,7 +35,24 @@ class BaseEvent(object): class OrganizeFile(BaseEvent, HasMetaData): def __init__(self, *args, **kwargs): super(OrganizeFile, self).__init__(*args, **kwargs) + def pack(self): + raise AttributeError("What the hell are you doing? You can't send organize events to airtime!!!") + class NewFile(BaseEvent, HasMetaData): def __init__(self, *args, **kwargs): super(NewFile, self).__init__(*args, **kwargs) + def pack(self): + """ + packs turns an event into a media monitor request + """ + req_dict = self.metadata.extract() + req_dict['mode'] = 'create' + req_dict['MDATA_KEY_FILEPATH'] = self.path + return req_dict + class DeleteFile(BaseEvent): def __init__(self, *args, **kwargs): super(DeleteFile, self).__init__(*args, **kwargs) + def pack(self): + req_dict = {} + req_dict['mode'] = 'delete' + req_dict['MDATA_KEY_FILEPATH'] = self.path + return req_dict diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 41be0fddb..66caccbd2 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -92,6 +92,7 @@ def truncate_to_length(item, length): else: return item class Metadata(Loggable): + @staticmethod def write_unsafe(path,md): if not os.path.exists(path): diff --git a/python_apps/media-monitor2/media/monitor/watchersyncer.py b/python_apps/media-monitor2/media/monitor/watchersyncer.py index 45bc7f3b1..1095b52c9 100644 --- a/python_apps/media-monitor2/media/monitor/watchersyncer.py +++ b/python_apps/media-monitor2/media/monitor/watchersyncer.py @@ -28,7 +28,7 @@ class RequestSync(threading.Thread,Loggable): # Not forget to attach the 'is_record' to any requests that are related # to recorded shows # A simplistic request would like: - self.apiclient.send_media_monitor_requests(self.requests) + self.apiclient.send_media_monitor_requests([ req.pack() for req in self.requests ]) self.watcher.flag_done() class TimeoutWatcher(threading.Thread,Loggable):