File: msg.py

package info (click to toggle)
pass-audit 1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: python: 798; makefile: 41; sh: 17
file content (67 lines) | stat: -rw-r--r-- 1,879 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- encoding: utf-8 -*-
# pass audit - Password Store Extension (https://www.passwordstore.org/)
# Copyright (C) 2018-2022 Alexandre PUJOL <alexandre@pujol.io>.
#

import sys


class Msg():
    """General class to manage output messages."""
    # Normal colors
    green = '\033[32m'
    yellow = '\033[33m'
    magenta = '\033[35m'
    end = '\033[0m'

    # Bold colors
    RED = '\033[1m\033[91m'
    GREEN = '\033[1m\033[92m'
    YELLOW = '\033[1m\033[93m'
    MAGENTA = '\033[1m\033[95m'
    BOLD = '\033[1m'

    def __init__(self, verbose=0, quiet=False):
        self.verb = verbose
        self.quiet = quiet
        if self.quiet:
            self.verb = 0

    def verbose(self, msg=''):
        """Verbose method."""
        if self.verb >= 1:
            out = f"{self.MAGENTA}  .  {self.end}{self.magenta}{msg}{self.end}"
            print(out, file=sys.stdout)

    def debug(self, msg=''):
        """Debug method."""
        if self.verb >= 3:
            self.verbose(msg)

    def message(self, msg=''):
        """Message method."""
        if not self.quiet:
            out = f"{self.BOLD}  .  {self.end}{msg}"
            print(out, file=sys.stdout)

    def success(self, msg=''):
        """Success method."""
        if not self.quiet:
            out = f"{self.GREEN} (*) {self.end}{self.green}{msg}{self.end}"
            print(out, file=sys.stdout)

    def warning(self, msg=''):
        """Warning method."""
        if not self.quiet:
            out = f"{self.YELLOW}  w  {self.end}{self.yellow}{msg}{self.end}"
            print(out, file=sys.stdout)

    def error(self, msg=''):
        """Error method."""
        err = f"{self.RED} [x] {self.end}{self.BOLD}Error: {self.end}{msg}"
        print(err, file=sys.stderr)

    def die(self, msg=''):
        """Show an error and exit the program."""
        self.error(msg)
        sys.exit(1)