[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][ftp-team/dak][master] 2 commits: Add daklib/termcolor.py and partially colorize print_new()



Title: GitLab

Joerg Jaspert pushed to branch master at Debian FTP Team / dak

Commits:

2 changed files:

Changes:

  • dak/process_new.py
    ... ... @@ -69,6 +69,7 @@ from daklib.dak_exceptions import CantOpenError, AlreadyLockedError, CantGetLock
    69 69
     from daklib.summarystats import SummaryStats
    
    70 70
     from daklib.config import Config
    
    71 71
     from daklib.policy import UploadCopy, PolicyQueueUploadHandler
    
    72
    +from daklib.termcolor import colorize as Color
    
    72 73
     
    
    73 74
     # Globals
    
    74 75
     Options = None
    
    ... ... @@ -162,7 +163,7 @@ def print_new(upload, missing, indexed, session, file=sys.stdout):
    162 163
             section = m['section']
    
    163 164
             priority = m['priority']
    
    164 165
             if m["type"] == 'deb' and priority != 'optional':
    
    165
    -            priority = '\033[31m' + priority + '\033[0m'
    
    166
    +            priority = Color(priority, "red")
    
    166 167
             included = "" if m['included'] else "NOT UPLOADED"
    
    167 168
             if indexed:
    
    168 169
                 line = "(%s): %-20s %-20s %-20s %s" % (index, package, priority, section, included)
    
    ... ... @@ -179,8 +180,12 @@ def print_new(upload, missing, indexed, session, file=sys.stdout):
    179 180
                 print('%s: %s' % (t[0], t[1]))
    
    180 181
         notes = get_new_comments(upload.policy_queue, upload.changes.source)
    
    181 182
         for note in notes:
    
    182
    -        print("\nAuthor: %s\nVersion: %s\nTimestamp: %s\n\n%s"
    
    183
    -              % (note.author, note.version, note.notedate, note.comment))
    
    183
    +        print("\n")
    
    184
    +        print(Color("Author:", "yellow"), "%s" % note.author)
    
    185
    +        print(Color("Version:", "yellow"), "%s" % note.version)
    
    186
    +        print(Color("Timestamp:", "yellow"), "%s" % note.timestamp)
    
    187
    +        print("\n\n")
    
    188
    +        print(note.comment)
    
    184 189
             print("-" * 72)
    
    185 190
         return len(notes) > 0
    
    186 191
     
    

  • daklib/termcolor.py
    1
    +#!/usr/bin/env python
    
    2
    +# vim:set et sw=4:
    
    3
    +"""
    
    4
    +TermColor utils for dak
    
    5
    +
    
    6
    +@contact: Debian FTP Master <ftpmaster@debian.org>
    
    7
    +@copyright: 2019 Mo Zhou <lumin@debian.org>
    
    8
    +@license: GNU General Public License version 2 or later
    
    9
    +"""
    
    10
    +
    
    11
    +# This program is free software; you can redistribute it and/or modify
    
    12
    +# it under the terms of the GNU General Public License as published by
    
    13
    +# the Free Software Foundation; either version 2 of the License, or
    
    14
    +# (at your option) any later version.
    
    15
    +
    
    16
    +# This program is distributed in the hope that it will be useful,
    
    17
    +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    18
    +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    19
    +# GNU General Public License for more details.
    
    20
    +
    
    21
    +# You should have received a copy of the GNU General Public License
    
    22
    +# along with this program; if not, write to the Free Software
    
    23
    +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
    24
    +
    
    25
    +###############################################################################
    
    26
    +
    
    27
    +import sys
    
    28
    +
    
    29
    +###############################################################################
    
    30
    +
    
    31
    +__all__ = []
    
    32
    +
    
    33
    +###############################################################################
    
    34
    +
    
    35
    +_COLORS_ = ('red', 'green', 'yellow', 'blue', 'violet', 'cyan', 'white')
    
    36
    +_COLOR_CODES_ = {k: 31 + _COLORS_.index(k) for k in _COLORS_}
    
    37
    +
    
    38
    +
    
    39
    +def colorize(s, fg, bg=None, bold=False, ul=False):
    
    40
    +    '''
    
    41
    +    s: str -- string to be colorized
    
    42
    +    fg: str/int -- foreground color. See _COLORS_ for choices
    
    43
    +    bg: str/int -- background color. See _COLORS_ for choices
    
    44
    +    bold: bool -- bold font?
    
    45
    +    ul: bool -- underline?
    
    46
    +    '''
    
    47
    +    if fg not in _COLORS_:
    
    48
    +        raise ValueError("Unsupported foreground Color!")
    
    49
    +    if (bg is not None) or any((bold, ul)):
    
    50
    +        raise NotImplementedError
    
    51
    +    return "\x1b[{}m{}\x1b[0;m".format(_COLOR_CODES_[fg], s)


  • Reply to: