# Path: media_nommer/conf/settings.py
# AWS_ACCESS_KEY_ID = None
# AWS_SECRET_ACCESS_KEY = None
# CONFIG_S3_BUCKET = 'nommer_config'
# SQS_NEW_JOB_QUEUE_NAME = 'media_nommer'
# SQS_JOB_STATE_CHANGE_QUEUE_NAME = 'media_nommer_jstate'
# SIMPLEDB_JOB_STATE_DOMAIN = 'media_nommer'
# SIMPLEDB_EC2_NOMMER_STATE_DOMAIN = 'media_nommer_ec2nommer_state'
# EC2_KEY_NAME = None
# EC2_SECURITY_GROUPS = ['media_nommer']
# EC2_AMI_ID = 'ami-eb558182'
# EC2_INSTANCE_TYPE = 'm1.large'
# MAX_ENCODING_JOBS_PER_EC2_INSTANCE = 2
# MAX_NUM_EC2_INSTANCES = 3
# JOB_OVERFLOW_THRESH = 2
# FEEDERD_JOB_STATE_CHANGE_CHECK_INTERVAL = 60
# FEEDERD_PRUNE_JOBS_INTERVAL = 60 * 5
# FEEDERD_ALLOW_EC2_LAUNCHES = True
# FEEDERD_ABANDON_INACTIVE_JOBS_THRESH = 3600 * 9
# FEEDERD_AUTO_SCALE_INTERVAL = 60
# NOMMERD_TERMINATE_WHEN_IDLE = True
# NOMMERD_MAX_INACTIVITY = 60 * 10
# NOMMERD_HEARTBEAT_INTERVAL = 60
# NOMMERD_NEW_JOB_CHECK_INTERVAL = 60
# NOMMERD_QTFASTSTART_BIN_PATH = '/home/nom/.virtualenvs/media_nommer/bin/qtfaststart'
# STORAGE_BACKENDS = {
#     's3': 'media_nommer.core.storage_backends.s3.S3Backend',
#     'http': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'https': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'file': 'media_nommer.core.storage_backends.file.FileBackend',
# }
# 
# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/core/storage_backends/s3.py
# class S3Backend(BaseStorageBackend):
#     """
#     Abstracts access to S3 via the common set of file storage backend methods.
#     """
#     @classmethod
#     def _get_aws_s3_connection(cls, access_key, secret_access_key):
#         """
#         Lazy-loading of the S3 boto connection. Refer to this instead of
#         referencing self._aws_s3_connection directly.
# 
#         :param str access_key: The AWS_ Access Key needed to get to the
#             file in question.
#         :param str secret_access_key: The AWS_ Secret Access Key needed to get
#             to the file in question.
#         :rtype: :py:class:`boto.s3.connection.Connection`
#         :returns: A boto connection to Amazon's S3 interface.
#         """
#         return boto.connect_s3(access_key, secret_access_key)
# 
#     @classmethod
#     def download_file(cls, uri, fobj):
#         """
#         Given a URI, download the file to the ``fobj`` file-like object.
# 
#         :param str uri: The URI of a file to download.
#         :param file fobj: A file-like object to download the file to.
#         :rtype: file
#         :returns: A file handle to the downloaded file.
#         """
#         # Breaks the URI into usable componenents.
#         values = get_values_from_media_uri(uri)
# 
#         conn = cls._get_aws_s3_connection(values['username'],
#                                           values['password'])
#         bucket = conn.get_bucket(values['host'])
#         key = bucket.get_key(values['path'])
# 
#         logger.debug("S3Backend.download_file(): " \
#                      "Downloading: %s" % uri)
# 
#         try:
#             key.get_contents_to_file(fobj)
#         except AttributeError:
#             # Raised by ResumableDownloadHandler in boto when the given S3
#             # key can't be found.
#             message = "The specified input file cannot be found."
#             raise InfileNotFoundException(message)
# 
#         logger.debug("S3Backend.download_file(): " \
#                      "Download of %s completed." % uri)
#         return fobj
# 
#     @classmethod
#     def upload_file(cls, uri, fobj):
#         """
#         Given a file-like object, upload it to the specified URI.
# 
#         :param str uri: The URI to upload the file to.
#         :param file fobj: The file-like object to populate the S3 key from.
#         :rtype: :py:class:`boto.s3.key.Key`
#         :returns: The newly set boto key.
#         """
#         # Breaks the URI into usable componenents.
#         values = get_values_from_media_uri(uri)
#         logger.debug("S3Backend.upload_file(): Received: %s" % values)
# 
#         conn = cls._get_aws_s3_connection(values['username'],
#                                           values['password'])
#         bucket = conn.create_bucket(values['host'])
#         key = bucket.new_key(values['path'])
# 
#         logger.debug("S3Backend.upload_file(): "\
#                      "Settings contents of '%s' key from %s" % (
#             values['path'], fobj.name))
#         key.set_contents_from_filename(fobj.name)
# 
#         logger.debug("S3Backend.upload_file(): Upload complete.")
#         return key


import os
import boto
from media_nommer.conf import settings
from media_nommer.utils import logger
from media_nommer.core.storage_backends.s3 import S3Backend
"""
Various configuration-related utility methods.
"""

def upload_settings(nomconf_module):
    """
    Given a user-defined nomconf module (already imported), push said file
    to the S3 conf bucket, as defined by settings.CONFIG_S3_BUCKET. 
    This is used by the nommers that require access to the config, like 
    FFmpegNommer.
    
    :param module nomconf_module: The user's ``nomconf`` module. This may
        be called something other than ``nomconf``, but the uploaded filename 
        will always be ``nomconf.py``, so the EC2 nodes can find it in your 
        settings.CONFIG_S3_BUCKET.
    """

# Path: media_nommer/conf/settings.py
# AWS_ACCESS_KEY_ID = None
# AWS_SECRET_ACCESS_KEY = None
# CONFIG_S3_BUCKET = 'nommer_config'
# SQS_NEW_JOB_QUEUE_NAME = 'media_nommer'
# SQS_JOB_STATE_CHANGE_QUEUE_NAME = 'media_nommer_jstate'
# SIMPLEDB_JOB_STATE_DOMAIN = 'media_nommer'
# SIMPLEDB_EC2_NOMMER_STATE_DOMAIN = 'media_nommer_ec2nommer_state'
# EC2_KEY_NAME = None
# EC2_SECURITY_GROUPS = ['media_nommer']
# EC2_AMI_ID = 'ami-eb558182'
# EC2_INSTANCE_TYPE = 'm1.large'
# MAX_ENCODING_JOBS_PER_EC2_INSTANCE = 2
# MAX_NUM_EC2_INSTANCES = 3
# JOB_OVERFLOW_THRESH = 2
# FEEDERD_JOB_STATE_CHANGE_CHECK_INTERVAL = 60
# FEEDERD_PRUNE_JOBS_INTERVAL = 60 * 5
# FEEDERD_ALLOW_EC2_LAUNCHES = True
# FEEDERD_ABANDON_INACTIVE_JOBS_THRESH = 3600 * 9
# FEEDERD_AUTO_SCALE_INTERVAL = 60
# NOMMERD_TERMINATE_WHEN_IDLE = True
# NOMMERD_MAX_INACTIVITY = 60 * 10
# NOMMERD_HEARTBEAT_INTERVAL = 60
# NOMMERD_NEW_JOB_CHECK_INTERVAL = 60
# NOMMERD_QTFASTSTART_BIN_PATH = '/home/nom/.virtualenvs/media_nommer/bin/qtfaststart'
# STORAGE_BACKENDS = {
#     's3': 'media_nommer.core.storage_backends.s3.S3Backend',
#     'http': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'https': 'media_nommer.core.storage_backends.http.HTTPBackend',
#     'file': 'media_nommer.core.storage_backends.file.FileBackend',
# }
# 
# Path: media_nommer/utils/logger.py
# def debug(message):
# def info(message):
# def warning(message):
# def error(message_or_obj=None):
# 
# Path: media_nommer/core/storage_backends/s3.py
# class S3Backend(BaseStorageBackend):
#     """
#     Abstracts access to S3 via the common set of file storage backend methods.
#     """
#     @classmethod
#     def _get_aws_s3_connection(cls, access_key, secret_access_key):
#         """
#         Lazy-loading of the S3 boto connection. Refer to this instead of
#         referencing self._aws_s3_connection directly.
# 
#         :param str access_key: The AWS_ Access Key needed to get to the
#             file in question.
#         :param str secret_access_key: The AWS_ Secret Access Key needed to get
#             to the file in question.
#         :rtype: :py:class:`boto.s3.connection.Connection`
#         :returns: A boto connection to Amazon's S3 interface.
#         """
#         return boto.connect_s3(access_key, secret_access_key)
# 
#     @classmethod
#     def download_file(cls, uri, fobj):
#         """
#         Given a URI, download the file to the ``fobj`` file-like object.
# 
#         :param str uri: The URI of a file to download.
#         :param file fobj: A file-like object to download the file to.
#         :rtype: file
#         :returns: A file handle to the downloaded file.
#         """
#         # Breaks the URI into usable componenents.
#         values = get_values_from_media_uri(uri)
# 
#         conn = cls._get_aws_s3_connection(values['username'],
#                                           values['password'])
#         bucket = conn.get_bucket(values['host'])
#         key = bucket.get_key(values['path'])
# 
#         logger.debug("S3Backend.download_file(): " \
#                      "Downloading: %s" % uri)
# 
#         try:
#             key.get_contents_to_file(fobj)
#         except AttributeError:
#             # Raised by ResumableDownloadHandler in boto when the given S3
#             # key can't be found.
#             message = "The specified input file cannot be found."
#             raise InfileNotFoundException(message)
# 
#         logger.debug("S3Backend.download_file(): " \
#                      "Download of %s completed." % uri)
#         return fobj
# 
#     @classmethod
#     def upload_file(cls, uri, fobj):
#         """
#         Given a file-like object, upload it to the specified URI.
# 
#         :param str uri: The URI to upload the file to.
#         :param file fobj: The file-like object to populate the S3 key from.
#         :rtype: :py:class:`boto.s3.key.Key`
#         :returns: The newly set boto key.
#         """
#         # Breaks the URI into usable componenents.
#         values = get_values_from_media_uri(uri)
#         logger.debug("S3Backend.upload_file(): Received: %s" % values)
# 
#         conn = cls._get_aws_s3_connection(values['username'],
#                                           values['password'])
#         bucket = conn.create_bucket(values['host'])
#         key = bucket.new_key(values['path'])
# 
#         logger.debug("S3Backend.upload_file(): "\
#                      "Settings contents of '%s' key from %s" % (
#             values['path'], fobj.name))
#         key.set_contents_from_filename(fobj.name)
# 
#         logger.debug("S3Backend.upload_file(): Upload complete.")
#         return key


# Path: media_nommer/conf/utils.py
import os
import boto
from media_nommer.conf import settings
from media_nommer.utils import logger
from media_nommer.core.storage_backends.s3 import S3Backend

"""
Various configuration-related utility methods.
"""

def upload_settings(nomconf_module):
    """
    Given a user-defined nomconf module (already imported), push said file
    to the S3 conf bucket, as defined by settings.CONFIG_S3_BUCKET. 
    This is used by the nommers that require access to the config, like 
    FFmpegNommer.
    
    :param module nomconf_module: The user's ``nomconf`` module. This may
        be called something other than ``nomconf``, but the uploaded filename 
        will always be ``nomconf.py``, so the EC2 nodes can find it in your 
        settings.CONFIG_S3_BUCKET.
    """

    logger.info("Uploading nomconf.py to S3.")