CC-1799 Put Airtime Storage into a Human Readable File Naming Convention
adding setup to get stor folder etc.
This commit is contained in:
parent
71d853567e
commit
8d9c0dab1a
5 changed files with 47 additions and 12 deletions
|
@ -359,6 +359,25 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
|
||||
return response
|
||||
|
||||
def setup_media_monitor(self):
|
||||
logger = logging.getLogger()
|
||||
|
||||
response = None
|
||||
try:
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["media_setup_url"])
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
|
||||
response = urllib.urlopen(url)
|
||||
response = json.loads(response.read())
|
||||
logger.debug("Json Media Setup %s", response)
|
||||
|
||||
except Exception, e:
|
||||
response = None
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
def check_media_status(self, md5):
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ MODE_CREATE = "create"
|
|||
MODE_MODIFY = "modify"
|
||||
|
||||
global storage_directory
|
||||
storage_directory = "/srv/airtime/stor"
|
||||
global plupload_directory
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
|
@ -136,7 +136,7 @@ class MediaMonitor(ProcessEvent):
|
|||
connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
||||
channel = connection.channel()
|
||||
|
||||
self.producer = Producer(channel, exchange=schedule_exchange, serializer="json")
|
||||
#self.producer = Producer(channel, exchange=schedule_exchange, serializer="json")
|
||||
#producer.publish({"name": "/tmp/lolcat1.avi", "size": 1301013})
|
||||
|
||||
def get_md5(self, filepath):
|
||||
|
@ -280,9 +280,6 @@ class MediaMonitor(ProcessEvent):
|
|||
else :
|
||||
return False
|
||||
|
||||
def setUpMediaMonitor(self, event):
|
||||
pass
|
||||
|
||||
def process_IN_CREATE(self, event):
|
||||
if not event.dir:
|
||||
#file created is a tmp file which will be modified and then moved back to the original filename.
|
||||
|
@ -335,7 +332,7 @@ class MediaMonitor(ProcessEvent):
|
|||
|
||||
def process_IN_DELETE(self, event):
|
||||
|
||||
self.producer.publish({"name": "Hi!"})
|
||||
#self.producer.publish({"name": "Hi!"})
|
||||
|
||||
self.logger.info("%s: %s", event.maskname, event.pathname)
|
||||
|
||||
|
@ -366,14 +363,27 @@ if __name__ == '__main__':
|
|||
pyinotify.IN_DELETE_SELF
|
||||
#mask = pyinotify.ALL_EVENTS
|
||||
|
||||
wm = WatchManager()
|
||||
wdd = wm.add_watch(storage_directory, mask, rec=True, auto_add=True)
|
||||
|
||||
logger = logging.getLogger('root')
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
|
||||
mm = MediaMonitor()
|
||||
|
||||
response = None
|
||||
while response is None:
|
||||
response = mm.api_client.setup_media_monitor()
|
||||
time.sleep(5)
|
||||
|
||||
storage_directory = response["stor"]
|
||||
plupload_directory = response["plupload"]
|
||||
|
||||
wm = WatchManager()
|
||||
|
||||
wdd = wm.add_watch(storage_directory, mask, rec=True, auto_add=True)
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
logger.info("wdd result %s", wdd[storage_directory])
|
||||
|
||||
wdd = wm.add_watch(plupload_directory, mask, rec=False, auto_add=True)
|
||||
logger.info("Added watch to %s", plupload_directory)
|
||||
logger.info("wdd result %s", wdd[plupload_directory])
|
||||
|
||||
notifier = AirtimeNotifier(wm, mm, read_freq=int(config["check_filesystem_events"]), timeout=1)
|
||||
notifier.coalesce_events()
|
||||
notifier.loop(callback=mm.check_rabbit_MQ)
|
||||
|
|
|
@ -19,6 +19,9 @@ api_base = 'api'
|
|||
# URL to get the version number of the server API
|
||||
version_url = 'version/api_key/%%api_key%%'
|
||||
|
||||
# URL to setup the media monitor
|
||||
media_setup_url = 'media-monitor-setup/format/json/api_key/%%api_key%%'
|
||||
|
||||
# URL to check Airtime's status of a file
|
||||
media_status_url = 'media-item-status/format/json/api_key/%%api_key%%/md5/%%md5%%'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue