cc-4105: code cleanup
This commit is contained in:
parent
a3b71d7ae3
commit
c2b65b187c
1 changed files with 29 additions and 33 deletions
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from kombu.messaging import Exchange, Queue, Consumer
|
from kombu.messaging import Exchange, Queue, Consumer
|
||||||
from kombu.connection import BrokerConnection
|
from kombu.connection import BrokerConnection
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
|
@ -16,11 +17,6 @@ from media.monitor.listeners import FileMediator
|
||||||
|
|
||||||
from api_clients import api_client as apc
|
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):
|
class AirtimeNotifier(Loggable):
|
||||||
"""
|
"""
|
||||||
AirtimeNotifier is responsible for interecepting RabbitMQ messages and
|
AirtimeNotifier is responsible for interecepting RabbitMQ messages and
|
||||||
|
@ -77,7 +73,7 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
"""
|
"""
|
||||||
This method is called by an AirtimeNotifier instance that
|
This method is called by an AirtimeNotifier instance that
|
||||||
consumes the Rabbit MQ events that trigger this. The method
|
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)
|
msg = copy.deepcopy(msg)
|
||||||
if msg['event_type'] in self.dispatch_table:
|
if msg['event_type'] in self.dispatch_table:
|
||||||
|
@ -175,8 +171,13 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
def file_delete(self, msg):
|
def file_delete(self, msg):
|
||||||
# Deletes should be requested only from imported folder but we
|
# Deletes should be requested only from imported folder but we
|
||||||
# don't verify that. Security risk perhaps?
|
# don't verify that. Security risk perhaps?
|
||||||
self.logger.info("Attempting to delete(maybe) '%s'" % msg['filepath'])
|
# we only delete if we are passed the special delete flag that is
|
||||||
if msg['delete']:
|
# 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']):
|
if os.path.exists(msg['filepath']):
|
||||||
try:
|
try:
|
||||||
self.logger.info("Attempting to delete '%s'" %
|
self.logger.info("Attempting to delete '%s'" %
|
||||||
|
@ -188,6 +189,7 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
# thing anyway so this might not be necessary after all
|
# thing anyway so this might not be necessary after all
|
||||||
FileMediator.ignore(msg['filepath'])
|
FileMediator.ignore(msg['filepath'])
|
||||||
os.unlink(msg['filepath'])
|
os.unlink(msg['filepath'])
|
||||||
|
# Verify deletion:
|
||||||
if not os.path.exists(msg['filepath']):
|
if not os.path.exists(msg['filepath']):
|
||||||
self.logger.info("Successfully deleted: '%s'" %
|
self.logger.info("Successfully deleted: '%s'" %
|
||||||
msg['filepath'])
|
msg['filepath'])
|
||||||
|
@ -198,9 +200,3 @@ class AirtimeMessageReceiver(Loggable):
|
||||||
self.logger.info("Attempting to delete file '%s' that does not \
|
self.logger.info("Attempting to delete file '%s' that does not \
|
||||||
exist. Full request coming:" % msg['filepath'])
|
exist. Full request coming:" % msg['filepath'])
|
||||||
self.logger.info(msg)
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue