import glob import importlib import os import sys from _util import logger logging = logger.fancy_logger(__name__) def test_app_names() -> bool: """Checks if the user-defined app name is already an importable Python module""" cwd = os.getcwd() while "" in sys.path: sys.path.remove("") while cwd in sys.path: sys.path.remove(cwd) for app in [appdir[:-1] for appdir in glob.glob("[a-z]*/")]: try: importlib.import_module(f"{app}") logging.warning( f"Name '{app}' intersects with a Python module, try a new one") flag = True except ModuleNotFoundError: flag = False except Exception: logging.info(f"Module {app} found but import failed") logging.warning( f"Name '{app}' intersects with a Python module, try a new one") flag = True
import re from _util import logutil # noqa from _util.logger import fancy_logger logging = fancy_logger(__name__) def pluck(input_dictionary): """Destructures a dictionary (vaguely like ES6 for JS) Results are SORTED by key alphabetically! You must sort your receiving vars """ items = sorted(input_dictionary.items()) return [item[1] for item in items] def _cid2c(cid): """Gets just the component portion of a cid string e.g. main_page/axis_controls|x_column.value => x_column """ return cid.split("|")[-1].split(".")[0] def process_inputs(input_dictionary): """Alters the keys of a dictionary by a helper function""" return {_cid2c(key): val for key, val in input_dictionary.items()} def extract(regex, input_dictionary, unique=False, pop=True): """Splits off a subset dictionary with keys matching the provided 'path' prefix""" method = "pop" if pop else "get"
"""A high-level wrapper around docker-py """ import docker import re import tqdm from _util import logger, logutil logging = logger.fancy_logger("docker") class DockerManager: def __init__(self): self.template_file = "docker_v1" self.docksock = "unix://var/run/docker.sock" @logutil.loginfo(level="debug") def build(self, context, metadata=None): metadata = metadata or {} self.completion = 0 self.linebuffer = "" client = docker.APIClient(base_url=self.docksock) output = client.build(decode=True, tag=context["tag"], path=context["path"]) if metadata.get("stream"): return output for chunk in output: result = self.process_output_chunk(chunk)
import flask import functools import inspect import os import traceback from _util import logger # logging = logger.fancy_logger(__name__) # We want to use a simple format here because we care about the wrapped function # Not the location and name of the wrapper logging = logger.fancy_logger(__name__, fmt="bare") def _parse_id(func): """Supplies the module name and functon name as a 2-tuple""" return (func.__module__.split(".")[-1], func.__name__) def loginfo(level="debug", log_route=False): def inner(func): """Wraps class methods to provide automatic log output on args/return value""" module, name = _parse_id(func) # Retrieves list of ordered arg names from the decorated function arg_names = list(inspect.signature(func).parameters.keys()) class_method = False # Removes class-related leading arg from consideration if arg_names and arg_names[0] in ("self", "cls"): class_method = True arg_names = arg_names[1:]
#!/usr/bin/env python3 import argparse import fileinput import glob import os import subprocess import sys from _util import versioning, environment from _util import file_management as FM from _util.docker_manager import DockerManager try: from _util import logger logging = logger.fancy_logger("build") except ImportError: import logging def run_command(cmd): proc = subprocess.Popen(cmd) try: logging.info(f"Running {' '.join(cmd)}") logging.debug(cmd) proc.wait() except KeyboardInterrupt: logging.info(f"Letting {cmd[0]} clean up...") proc.wait() logging.info("Done")