From add322d515d11412b2146cc501a188ab1e786131 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 25 Jul 2012 17:52:06 -0400 Subject: [PATCH] cc-4105: handling airtime events like delete --- .../media-monitor2/media/monitor/airtime.py | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/airtime.py b/python_apps/media-monitor2/media/monitor/airtime.py index 0933ae85d..ffae74a92 100644 --- a/python_apps/media-monitor2/media/monitor/airtime.py +++ b/python_apps/media-monitor2/media/monitor/airtime.py @@ -2,6 +2,7 @@ from kombu.messaging import Exchange, Queue, Consumer from kombu.connection import BrokerConnection import json +import os import copy from media.monitor.exceptions import BadSongFile @@ -100,11 +101,10 @@ class AirtimeMessageReceiver(Loggable): self.logger.info("Unknown error when writing metadata to: '%s'" % md_path) def new_watch(self, msg): - # TODO : add new watched directory by bootstrapping it with an empty - # database? - pass + # TODO: "walk" the newly watched directory + self.manager.add_watch_directory(msg['directory']) def remove_watch(self, msg): - pass + self.manager.remove_watch_directory(msg['directory']) def rescan_watch(self, msg): # TODO : basically a bootstrap on the directory pass @@ -113,4 +113,22 @@ class AirtimeMessageReceiver(Loggable): new_storage_directory_id = str(msg['dir_id']) def file_delete(self, msg): - pass + # deletes should be requested only from imported folder but we don't + # verify that. + # clippy confirmation: "are you really sure?" + if msg['delete']: + self.logger.info("Clippy confirmation was received, actually deleting file...") + if os.path.exists(msg['filepath']): + try: + self.logger.info("Attempting to delete '%s'" % msg['filepath']) + os.unlink(msg['filepath']) + except Exception as e: + self.logger.info("Failed to delete '%s'" % msg['filepath']) + self.logger.info("Error: " % str(e)) + else: + self.logger.info("Attempting to delete file '%s' that does not exist. Full request coming:" % msg['filepath']) + self.logger.info(msg) + else: + self.logger.info("No clippy confirmation, ignoring event. Out of curiousity we will print some details.") + self.logger.info(msg) +