cc-4105: code cleanup

This commit is contained in:
Rudi Grinberg 2012-08-14 15:07:56 -04:00
parent a3b71d7ae3
commit c2b65b187c
1 changed files with 29 additions and 33 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from kombu.messaging import Exchange, Queue, Consumer
from kombu.connection import BrokerConnection
import json
import os
import copy
@ -16,11 +17,6 @@ from media.monitor.listeners import FileMediator
from api_clients import api_client as apc
# Do not confuse with media monitor 1's AirtimeNotifier class that more related
# to pyinotify's Notifier class. AirtimeNotifier just notifies when events come
# from Airtime itself. I.E. changes made in the web UI that must be updated
# through media monitor
class AirtimeNotifier(Loggable):
"""
AirtimeNotifier is responsible for interecepting RabbitMQ messages and
@ -77,7 +73,7 @@ class AirtimeMessageReceiver(Loggable):
"""
This method is called by an AirtimeNotifier instance that
consumes the Rabbit MQ events that trigger this. The method
return true when the event was executed and false when it wasn't
return true when the event was executed and false when it wasn't.
"""
msg = copy.deepcopy(msg)
if msg['event_type'] in self.dispatch_table:
@ -175,8 +171,13 @@ class AirtimeMessageReceiver(Loggable):
def file_delete(self, msg):
# Deletes should be requested only from imported folder but we
# don't verify that. Security risk perhaps?
self.logger.info("Attempting to delete(maybe) '%s'" % msg['filepath'])
if msg['delete']:
# we only delete if we are passed the special delete flag that is
# necessary with every "delete_file" request
if not msg['delete']:
self.logger.info("No clippy confirmation, ignoring event. \
Out of curiousity we will print some details.")
self.logger.info(msg)
return
if os.path.exists(msg['filepath']):
try:
self.logger.info("Attempting to delete '%s'" %
@ -188,6 +189,7 @@ class AirtimeMessageReceiver(Loggable):
# thing anyway so this might not be necessary after all
FileMediator.ignore(msg['filepath'])
os.unlink(msg['filepath'])
# Verify deletion:
if not os.path.exists(msg['filepath']):
self.logger.info("Successfully deleted: '%s'" %
msg['filepath'])
@ -198,9 +200,3 @@ class AirtimeMessageReceiver(Loggable):
self.logger.info("Attempting to delete file '%s' that does not \
exist. Full request coming:" % msg['filepath'])
self.logger.info(msg)
else: # we did not get the special 'delete' tag. no deleting
self.logger.info("No clippy confirmation, ignoring event. \
Out of curiousity we will print some details.")
self.logger.info(msg)