Merge branch 'cc-5709-airtime-analyzer-cloud-storage' into cc-5709-airtime-analyzer-cloud-storage-saas

Conflicts:
	airtime_mvc/application/Bootstrap.php
	airtime_mvc/application/models/Schedule.php
	airtime_mvc/application/modules/rest/controllers/MediaController.php
	airtime_mvc/build/sql/schema.sql
	python_apps/airtime_analyzer/airtime_analyzer/analyzer_pipeline.py
This commit is contained in:
drigato 2014-12-03 13:35:32 -05:00
commit cf9eabbc74
42 changed files with 5355 additions and 1681 deletions

View file

@ -2,17 +2,19 @@
from threading import Thread
from Queue import Empty
from cloud_storage_downloader import CloudStorageDownloader
import logging
import shutil
import os
import sys
import stat
import requests
import ConfigParser
from std_err_override import LogWriter
CONFIG_PATH = '/etc/airtime/airtime.conf'
# configure logging
logging.config.fileConfig("logging.cfg")
logger = logging.getLogger()
@ -37,12 +39,8 @@ class PypoFile(Thread):
"""
src = media_item['uri']
dst = media_item['dst']
try:
src_size = os.path.getsize(src)
except Exception, e:
self.logger.error("Could not get size of source file: %s", src)
return
src_size = media_item['filesize']
dst_exists = True
try:
@ -68,7 +66,23 @@ class PypoFile(Thread):
"""
copy will overwrite dst if it already exists
"""
shutil.copy(src, dst)
#shutil.copy(src, dst)
config = self.read_config_file(CONFIG_PATH)
CONFIG_SECTION = "general"
username = config.get(CONFIG_SECTION, 'api_key')
url = media_item['download_url']
with open(dst, "wb") as handle:
response = requests.get(url, auth=requests.auth.HTTPBasicAuth(username, ''), stream=True)
if not response.ok:
raise Exception("%s - Error occurred downloading file" % response.status_code)
for chunk in response.iter_content(1024):
if not chunk:
break
handle.write(chunk)
#make file world readable
os.chmod(dst, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
@ -108,6 +122,19 @@ class PypoFile(Thread):
return media_item
def read_config_file(self, config_path):
"""Parse the application's config file located at config_path."""
config = ConfigParser.SafeConfigParser()
try:
config.readfp(open(config_path))
except IOError as e:
logging.debug("Failed to open config file at %s: %s" % (config_path, e.strerror))
sys.exit()
except Exception:
logging.debug(e.strerror)
sys.exit()
return config
def main(self):
while True:
@ -133,15 +160,7 @@ class PypoFile(Thread):
media_item = self.get_highest_priority_media_item(self.media)
if media_item is not None:
"""
If an object_name exists the file is stored on Amazon S3
"""
if 'amazonS3_resource_id' in media_item:
csd = CloudStorageDownloader()
csd.download_obj(media_item['dst'], media_item['amazonS3_resource_id'])
media_item['file_ready'] = True
else:
self.copy_file(media_item)
self.copy_file(media_item)
except Exception, e:
import traceback
top = traceback.format_exc()