From 88bb473f0bcf407544b5d63cf2e3e014ffca77e0 Mon Sep 17 00:00:00 2001 From: Christof Schulze Date: Tue, 15 Oct 2019 21:22:45 +0200 Subject: [PATCH] better modularisation (preparation for python package) --- color.py | 28 +++++++++++++++------------- display.py | 14 +++++++------- parseing_yaml.py | 2 +- path.py | 6 +++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/color.py b/color.py index 6743511..29c31c2 100644 --- a/color.py +++ b/color.py @@ -18,6 +18,8 @@ import sys import re +from ammsml.config import constants as C + IS_COLOR: bool = True @@ -40,16 +42,16 @@ else: # IS_COLOR = True -class BColors: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - CHANGED = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - ERROR = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' +# class BColors: +# HEADER = '\033[95m' +# OKBLUE = '\033[94m' +# CHANGED = '\033[94m' +# OKGREEN = '\033[92m' +# WARNING = '\033[93m' +# ERROR = '\033[91m' +# ENDC = '\033[0m' +# BOLD = '\033[1m' +# UNDERLINE = '\033[4m' # --- begin "pretty" # @@ -115,9 +117,9 @@ def colorize(lead, num, color): def hostcolor(host: str, stats: list, color: bool = True) -> str: if IS_COLOR and color: if stats['failures'] != 0 or stats['unreachable'] != 0: - return "%-37s" % stringc(host, BColors.ERROR) + return "%-37s" % stringc(host, C.COLOR_ERROR) elif stats['changed'] != 0: - return "%-37s" % stringc(host, BColors.CHANGED) + return "%-37s" % stringc(host, C.COLOR_CHANGED) else: - return "%-37s" % stringc(host, BColors.OKGREEN) + return "%-37s" % stringc(host, C.COLOR_OKGREEN) return "%-26s" % host diff --git a/display.py b/display.py index ad5bfae..064a40c 100644 --- a/display.py +++ b/display.py @@ -28,13 +28,13 @@ import subprocess from struct import unpack, pack from termios import TIOCGWINSZ -from utils.color import stringc -from utils.parsing import to_text -from utils.errors import AMMSMLError -from utils.singleton import Singleton -from config import constants as C -from utils.six import with_metaclass -from utils.wrap import wrap_var +from ammsml.utils.color import stringc +from ammsml.utils.parsing import to_text +from ammsml.utils.errors import AMMSMLError +from ammsml.utils.singleton import Singleton +from ammsml.config import constants as C +from ammsml.utils.six import with_metaclass +from ammsml.utils.wrap import wrap_var b_COW_PATHS = ( diff --git a/parseing_yaml.py b/parseing_yaml.py index 0fa3d0a..df1355d 100644 --- a/parseing_yaml.py +++ b/parseing_yaml.py @@ -18,7 +18,7 @@ import yaml -from utils.parsing import to_text +# from ammsml.utils.parsing import to_text class AMMSMLBaseYAMLObject(object): diff --git a/path.py b/path.py index fdd5843..defe961 100644 --- a/path.py +++ b/path.py @@ -20,8 +20,8 @@ import os import shutil from errno import EEXIST -from utils.parsing import to_text -from utils.errors import AMMSMLError +from ammsml.utils.parsing import to_text +from ammsml.utils.errors import AMMSMLError __all__ = ['unfrackpath', 'makedirs_safe', 'resolve_path', 'cleanup_tmp_file'] @@ -129,7 +129,7 @@ def cleanup_tmp_file(path, warn=False): except Exception as e: if warn: # Importing here to avoid circular import - from utils.display import Display + from ammsml.utils.display import Display display = Display() display.display(u'Unable to remove temporary file {0}'.format(to_text(e))) except Exception: -- GitLab