Browse Source

Prepping pydantic config structure. BREAKING

acm-debugging-and-enhancements
Drew Short 2 years ago
parent
commit
def0761d96
  1. 20
      acm.py
  2. 0
      acm/__init__.py
  3. 44
      acm/config.py
  4. 46
      acm/logging.py
  5. 3
      acm/s3.py
  6. 10
      docker/entrypoint.sh
  7. 2
      pyproject.toml
  8. 2
      setup.py

20
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")
####################

0
acm/__init__.py

44
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 ""

46
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)

3
acm/s3.py

@ -0,0 +1,3 @@
import logging
LOG = logging.getLogger("acm.s3")

10
docker/entrypoint.sh

@ -1,3 +1,9 @@
#! /bin/sh
#!/usr/bin/env bash
acm $@
options=""
if [[ "${ACM_DEBUG}" == "true" ]]; then
options="--debug $options"
fi
acm ${options} $@

2
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 <warrick@sothr.com>"]
license = "Apache2"

2
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'
Loading…
Cancel
Save