Removed usesless try catch from send_media_monitor_requests.

This commit is contained in:
Rudi Grinberg 2012-10-29 11:40:41 -04:00
parent 35a9e77062
commit 31a7b8f943
1 changed files with 39 additions and 46 deletions

View File

@ -422,53 +422,46 @@ class AirtimeApiClient():
def send_media_monitor_requests(self, action_list, dry=False): def send_media_monitor_requests(self, action_list, dry=False):
""" """
Send a gang of media monitor events at a time. actions_list is a list Send a gang of media monitor events at a time. actions_list is a
of dictionaries where every dictionary is representing an action. Every list of dictionaries where every dictionary is representing an
action dict must contain a 'mode' key that says what kind of action it action. Every action dict must contain a 'mode' key that says
is and an optional 'is_record' key that says whether the show was what kind of action it is and an optional 'is_record' key that
recorded or not. The value of this key does not matter, only if it's says whether the show was recorded or not. The value of this key
present or not. does not matter, only if it's present or not.
""" """
logger = self.logger url = self.construct_url('reload_metadata_group')
try: # We are assuming that action_list is a list of dictionaries such
url = self.construct_url('reload_metadata_group') # that every dictionary represents the metadata of a file along
# We are assuming that action_list is a list of dictionaries such # with a special mode key that is the action to be executed by the
# that every dictionary represents the metadata of a file along # controller.
# with a special mode key that is the action to be executed by the valid_actions = []
# controller. # We could get a list of valid_actions in a much shorter way using
valid_actions = [] # filter but here we prefer a little more verbosity to help
# We could get a list of valid_actions in a much shorter way using # debugging
# filter but here we prefer a little more verbosity to help for action in action_list:
# debugging if not 'mode' in action:
for action in action_list: self.logger.debug("Warning: Trying to send a request element without a 'mode'")
if not 'mode' in action: self.logger.debug("Here is the the request: '%s'" % str(action) )
self.logger.debug("Warning: Trying to send a request element without a 'mode'") else:
self.logger.debug("Here is the the request: '%s'" % str(action) ) # We alias the value of is_record to true or false no
else: # matter what it is based on if it's absent in the action
# We alias the value of is_record to true or false no if 'is_record' not in action:
# matter what it is based on if it's absent in the action action['is_record'] = 0
if 'is_record' not in action: valid_actions.append(action)
action['is_record'] = 0 # Note that we must prefix every key with: mdX where x is a number
valid_actions.append(action) # Is there a way to format the next line a little better? The
# Note that we must prefix every key with: mdX where x is a number # parenthesis make the code almost unreadable
# Is there a way to format the next line a little better? The md_list = dict((("md%d" % i), json.dumps(convert_dict_value_to_utf8(md))) \
# parenthesis make the code almost unreadable for i,md in enumerate(valid_actions))
md_list = dict((("md%d" % i), json.dumps(convert_dict_value_to_utf8(md))) \ # For testing we add the following "dry" parameter to tell the
for i,md in enumerate(valid_actions)) # controller not to actually do any changes
# For testing we add the following "dry" parameter to tell the if dry: md_list['dry'] = 1
# controller not to actually do any changes self.logger.info("Pumping out %d requests..." % len(valid_actions))
if dry: md_list['dry'] = 1 data = urllib.urlencode(md_list)
self.logger.info("Pumping out %d requests..." % len(valid_actions)) req = urllib2.Request(url, data)
data = urllib.urlencode(md_list) response = self.get_response_from_server(req)
req = urllib2.Request(url, data) response = json.loads(response)
response = self.get_response_from_server(req) return response
response = json.loads(response)
return response
except ValueError: raise
except Exception, e:
logger.error('Exception: %s', e)
logger.error("traceback: %s", traceback.format_exc())
raise
#returns a list of all db files for a given directory in JSON format: #returns a list of all db files for a given directory in JSON format:
#{"files":["path/to/file1", "path/to/file2"]} #{"files":["path/to/file1", "path/to/file2"]}