File: pretty.py

package info (click to toggle)
roc-toolkit 0.4.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,700 kB
  • sloc: cpp: 102,987; ansic: 8,959; python: 6,125; sh: 942; makefile: 19; javascript: 9
file content (78 lines) | stat: -rw-r--r-- 2,438 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
68
69
70
71
72
73
74
75
76
77
78
import SCons.Script
import sys
import re

_COLORS = {}
_COMPACT = False

def _init_colors():
    global _COLORS

    if sys.stdout.isatty():
        _COLORS['cyan']   = '\033[0;36m'
        _COLORS['purple'] = '\033[0;35m'
        _COLORS['blue']   = '\033[0;34m'
        _COLORS['green']  = '\033[0;32m'
        _COLORS['yellow'] = '\033[0;33m'
        _COLORS['red']    = '\033[0;31m'
        _COLORS['end']    = '\033[0m'
    else:
        for k in ['cyan', 'purple', 'blue', 'green', 'yellow', 'red', 'end']:
           _COLORS[k] = ''

def _init_compact():
    global _COMPACT

    for arg in sys.argv:
        if re.match('^-([^-].*)?Q.*$', arg):
            _COMPACT = True
            break

def _init_pretty(env):
    global _COMPACT

    if not _COMPACT:
        return

    def _subst(env, string, raw=1, target=None, source=None, conv=None, executor=None):
        raw = 1
        gvars = env.gvars()
        lvars = env.lvars()
        lvars['__env__'] = env
        if executor:
            lvars.update(executor.get_lvars())
        return SCons.Subst.scons_subst(string, env, raw, target, source, gvars, lvars, conv)

    env.AddMethod(_subst, 'subst_target_source')

    env['CCCOMSTR']       = env.PrettyCommand('CC', '$SOURCE', 'blue')
    env['SHCCCOMSTR']     = env.PrettyCommand('CC', '$SOURCE', 'blue')

    env['CXXCOMSTR']      = env.PrettyCommand('CXX', '$SOURCE', 'blue')
    env['SHCXXCOMSTR']    = env.PrettyCommand('CXX', '$SOURCE', 'blue')

    env['RCCOMSTR']       = env.PrettyCommand('RC', '$SOURCE', 'red')
    env['ARCOMSTR']       = env.PrettyCommand('AR', '$TARGET', 'red')
    env['SHLINKCOMSTR']   = env.PrettyCommand('LD', '$TARGET', 'red')
    env['LDMODULECOMSTR'] = env.PrettyCommand('LD', '$TARGET', 'red')
    env['LINKCOMSTR']     = env.PrettyCommand('LD', '$TARGET', 'red')
    env['RANLIBCOMSTR']   = env.PrettyCommand('RANLIB', '$TARGET', 'red')
    env['MTCOMSTR']       = env.PrettyCommand('MT', '$TARGET', 'green')

    env['INSTALLSTR']     = env.PrettyCommand('INSTALL', '$TARGET', 'yellow')

def PrettyCommand(env, command, args, color, cmdline=None):
    global _COMPACT

    if _COMPACT:
        return ' {}{:>8s}{}   {}'.format(_COLORS[color], command, _COLORS['end'], args)
    elif cmdline:
        return cmdline
    else:
        return '$CMDLINE'

def init(env):
    env.AddMethod(PrettyCommand, 'PrettyCommand')
    _init_colors()
    _init_compact()
    _init_pretty(env)