diff --git a/acm.py b/acm.py index a199cb7..3ddead7 100755 --- a/acm.py +++ b/acm.py @@ -16,18 +16,15 @@ import click from minio import Minio, InvalidResponseError from minio.error import S3Error +from acm.logging import setup_basic_logging, update_logging_level + # Size of the buffer to read files with BUF_SIZE = 4096 # Application Version -VERSION = "1.5.0" - -LOG = logging.getLogger("acm") -LOG.setLevel(logging.ERROR) +VERSION = "2.0.0" -def setup_logging(is_debug: bool = False): - if is_debug: - LOG.setLevel(logging.DEBUG) +LOG = setup_basic_logging("acm") ########### # AsyncIO # @@ -270,12 +267,19 @@ def load_config(path: str) -> any: @click.pass_context def cli(ctx, debug, config, stdin, remove_prefix, add_prefix): ctx.ensure_object(dict) + + # Propagate the global configs ctx.obj['DEBUG'] = debug ctx.obj['CONFIG'] = load_config(config) ctx.obj['READ_STDIN'] = stdin ctx.obj['REMOVE_PREFIX'] = remove_prefix ctx.obj['ADD_PREFIX'] = add_prefix - setup_logging(debug) + + if debug: + update_logging_level(3, LOG) + + # Reduce the logging noise for library loggers + update_logging_level(0, "asyncio") #################### diff --git a/acm/__init__.py b/acm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/acm/config.py b/acm/config.py new file mode 100644 index 0000000..e255ff8 --- /dev/null +++ b/acm/config.py @@ -0,0 +1,44 @@ +import logging +import typing + +from pydantic import BaseModel, validator + +LOG = logging.getLogger("acm.config") + + +class ACMProfileTarget(BaseModel): + name: str + version: str + processors: typing.List[str] + extensions: typing.List[str] + output_extension: str + force_preserve_smaller_input: bool + command: str + signature: typing.Optional[str] + + @validator('signature', always=True) + def signature_validator(cls, v, values) -> str: + # TODO calculate the hash for the profile target + return "" + + +class ACMProfile(BaseModel): + name: str + processors: typing.List[ACMProfileTarget] + signature: typing.Optional[str] + + @validator('signature', always=True) + def hash_signature_validator(cls, v, values) -> str: + # TODO calculate the hash for the profile + return "" + + +class ACMConfig(BaseModel): + concurrency: int = 0 + profiles: typing.List[ACMProfile] + signature: typing.Optional[str] + + @validator('signature', always=True) + def signature_validator(cls, v, values) -> str: + # TODO calculate the hash for the config + return "" diff --git a/acm/logging.py b/acm/logging.py new file mode 100644 index 0000000..221d468 --- /dev/null +++ b/acm/logging.py @@ -0,0 +1,46 @@ +import logging + +LOG = logging.getLogger("acm.logging") + +def setup_basic_logging( + logger_name, + logger_level = logging.ERROR, + log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s", + date_format="%Y-%m-%dT%H:%M:%S%Z", + default_level = logging.INFO, +): + """ + Initialize logging with sane defaults + """ + logging.basicConfig( + format=log_format, + datefmt=date_format, + level=default_level + ) + configured_logger = logging.getLogger(logger_name) + configured_logger.setLevel(logger_level) + +def update_logging_level(verbosity: int = 0, *loggers): + """ + Configure logging based on the requested verbosity + """ + + if verbosity > 2: + logging_level = logging.DEBUG + elif verbosity > 1: + logging_level = logging.INFO + elif verbosity > 0: + logging_level = logging.WARN + elif verbosity == 0: + logging_level = logging.ERROR + elif verbosity < 0: + logging_level = logging.CRITICAL + + for logger in loggers: + if isinstance(logger, logging.Logger) or isinstance(logger, logging.Handler): + logger.setLevel(logging_level) + else: + logger_instance = logging.getLogger(logger) + logger_instance.setLevel(logging_level) + + LOG.debug("Set logging level for to %s", logging_level) diff --git a/acm/s3.py b/acm/s3.py new file mode 100644 index 0000000..a7b9a2d --- /dev/null +++ b/acm/s3.py @@ -0,0 +1,3 @@ +import logging + +LOG = logging.getLogger("acm.s3") \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index e47b885..2af338a 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,3 +1,9 @@ -#! /bin/sh +#!/usr/bin/env bash -acm $@ \ No newline at end of file +options="" + +if [[ "${ACM_DEBUG}" == "true" ]]; then + options="--debug $options" +fi + +acm ${options} $@ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index ba0f5f1..93bf094 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "asset-compression-manager" -version = "1.5.0" +version = "2.0.0" description = "Helper Utility For Managing Compressed Assets" authors = ["Drew Short "] license = "Apache2" diff --git a/setup.py b/setup.py index 751358b..317d21b 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from distutils.core import setup setup( name='Asset-Compression-Manager', - version='1.5.0', + version='2.0.0', description='Helper Utility For Managing Compressed Assets', author='Drew Short', author_email='warrick@sothr.com'