Commit 18c9a517 authored by Christof Schulze's avatar Christof Schulze 😎
Browse files

some improvements

parent 8e4e59cc
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -48,16 +48,16 @@ class BColors:


codeCodes = {
    'black': u'0;30', 'bright gray': u'0;37',
    'blue': u'0;34', 'white': u'1;37',
    'green': u'0;32', 'bright blue': u'1;34',
    'cyan': u'0;36', 'bright green': u'1;32',
    'red': u'0;31', 'bright cyan': u'1;36',
    'purple': u'0;35', 'bright red': u'1;31',
    'yellow': u'0;33', 'bright purple': u'1;35',
    'dark gray': u'1;30', 'bright yellow': u'1;33',
    'magenta': u'0;35', 'bright magenta': u'1;35',
    'normal': u'0',
    'black': '0;30', 'bright gray': '0;37',
    'blue': '0;34', 'white': '1;37',
    'green': '0;32', 'bright blue': '1;34',
    'cyan': '0;36', 'bright green': '1;32',
    'red': '0;31', 'bright cyan': '1;36',
    'purple': '0;35', 'bright red': '1;31',
    'yellow': '0;33', 'bright purple': '1;35',
    'dark gray': '1;30', 'bright yellow': '1;33',
    'magenta': '0;35', 'bright magenta': '1;35',
    'normal': '0',
}


+62 −6
Original line number Diff line number Diff line
@@ -4,16 +4,24 @@ import os
import sys
import errno
import time

import textwrap

from utils.color import stringc
from utils.color import BColors
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


b_COW_PATHS = (
    b"/usr/bin/cowsay",
    b"/usr/games/cowsay",
    b"/usr/local/bin/cowsay",  # BSD path for cowsay
    b"/opt/local/bin/cowsay",  # MacPorts path for cowsay
)

class Display(with_metaclass(Singleton, object)):

    def __init__(self, verbosity: int=0):
@@ -93,12 +101,60 @@ class Display(with_metaclass(Singleton, object)):
            else:
                self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, stderr=to_stderr)

    @classmethod
    def deprecated(cls, message: str):
    def deprecated(self, msg, version=None, removed=False):
        """ used to print out a deprecation message."""

        pass
        if not removed and not C.DEPRECATION_WARNINGS:
            return

        if not removed:
            if version:
                new_msg = "[DEPRECATION WARNING]: %s. This feature will be removed in version %s." % (msg, version)
            else:
                new_msg = "[DEPRECATION WARNING]: %s. This feature will be removed in a future release." % msg
            new_msg = new_msg + " Deprecation warnings can be disabled by setting deprecation_warnings=False in ammsml.cfg.\n\n"
        else:
            raise AMMSMLError("[DEPRECATED]: %s.\nPlease update your python scripts." % msg)

    @classmethod
    def warning(cls, message: str):
        wrapped = textwrap.wrap(new_msg, self.columns, drop_whitespace=False)
        new_msg = "\n".join(wrapped) + "\n"

        if new_msg not in self._deprecations:
            self.display(new_msg.strip(), color=C.COLOR_DEPRECATE, stderr=True)
            self._deprecations[new_msg] = 1
        pass

    def warning(self, msg, formatted=False):

        if not formatted:
            new_msg = "[WARNING]: %s" % msg
            wrapped = textwrap.wrap(new_msg, self.columns)
            new_msg = "\n".join(wrapped) + "\n"
        else:
            new_msg = "\n[WARNING]: \n%s" % msg

        if new_msg not in self._warns:
            self.display(new_msg, color=C.COLOR_WARN, stderr=True)
            self._warns[new_msg] = 1

    def system_warning(self, msg):
        if C.SYSTEM_WARNINGS:
            self.warning(msg)

    def banner(self, msg, color=None, cows=True):
        """
        Prints a header-looking line with cowsay or stars with length depending on terminal width (3 minimum)
        """
        if self.b_cowsay and cows:
            try:
                self.banner_cowsay(msg)
                return
            except OSError:
                self.warning("somebody cleverly deleted cowsay or something during the PB run.  heh.")

        msg = msg.strip()
        star_len = self.columns - len(msg)
        if star_len <= 3:
            star_len = 3
        stars = u"*" * star_len
        self.display(u"\n%s %s" % (msg, stars), color=color)
 No newline at end of file

requirements.txt

0 → 100644
+3 −0
Original line number Diff line number Diff line
Jinja2==2.10.3
MarkupSafe==1.1.1
PyYAML==5.1.2