Ejemplo n.º 1
0
def get_key(path, validate=True):
    """
    Retrieves a key from S3 for the given file path or None if it
    does not exist.
    """
    key_path = filepath_to_key_path(path)
    bucket = s3.get_bucket(config.get("cloudformation", "bucket"))
    key = bucket.get_key(key_path, validate=validate)
    logger.debug("get_key(%r) -> %r", key_path, key)
    return key
Ejemplo n.º 2
0
def minify(path):
    """Minify a json document and remove any comments."""
    json_data = ""
    original_size = 0

    with open(path, "r") as source:
        for line in source:
            original_size += len(line)
            if not line.strip().startswith("//"):
                json_data += line

    # Dump the json data with no spaces between separators and sorted
    # keys.  Without the key sorting you can end up with different key order
    # between runs.
    try:
        json_data = dumps(
            loads(json_data),
            separators=(",", ":"), sort_keys=True
        )
    except Exception as error:
        logger.error("Failed to convert %s: %s", path, error)
        raise
    logger.debug("minify(%r): %s -> %s", path, original_size, len(json_data))
    return json_data.encode("utf-8")
Ejemplo n.º 3
0
from os.path import expanduser
from configparser import ConfigParser
from pkg_resources import resource_filename
from awsutil.logger import logger

config = ConfigParser()
LOADED_CONFIGS = config.read([
    resource_filename("awsutil", "awsutil.ini"),
    expanduser("~/.awsutil.ini"),
    ".awsutil.ini"
])

logger.debug("Loaded config(s): %s", LOADED_CONFIGS)