Fixed a cloud file download bug where it was downloading the wrong track. Working on amazon s3 signed urls for private objects. Added cloud storage configuration to install script.
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import os
|
|
import logging
|
|
import ConfigParser
|
|
import sys
|
|
|
|
from libcloud.storage.types import Provider, ObjectDoesNotExistError
|
|
from libcloud.storage.providers import get_driver
|
|
|
|
CONFIG_PATH = '/etc/airtime/airtime.conf'
|
|
|
|
class CloudStorageDownloader:
|
|
def __init__(self):
|
|
config = self.read_config_file(CONFIG_PATH)
|
|
|
|
CLOUD_STORAGE_CONFIG_SECTION = "cloud_storage"
|
|
self._provider = config.get(CLOUD_STORAGE_CONFIG_SECTION, 'provider')
|
|
self._bucket = config.get(CLOUD_STORAGE_CONFIG_SECTION, 'bucket')
|
|
self._api_key = config.get(CLOUD_STORAGE_CONFIG_SECTION, 'api_key')
|
|
self._api_key_secret = config.get(CLOUD_STORAGE_CONFIG_SECTION, 'api_key_secret')
|
|
|
|
def download_obj(self, dst, obj_name):
|
|
cls = get_driver(getattr(Provider, self._provider))
|
|
driver = cls(self._api_key, self._api_key_secret)
|
|
|
|
try:
|
|
cloud_obj = driver.get_object(container_name=self._bucket,
|
|
object_name=obj_name)
|
|
except ObjectDoesNotExistError:
|
|
logging.info("Could not find object: %s" % obj_name)
|
|
|
|
logging.info('Downloading: %s to %s' % (cloud_obj.name, dst))
|
|
cloud_obj.download(destination_path=dst)
|
|
|
|
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:
|
|
print "Failed to open config file at " + config_path + ": " + e.strerror
|
|
sys.exit()
|
|
except Exception:
|
|
print e.strerror
|
|
sys.exit()
|
|
|
|
return config
|