File: utils.py

package info (click to toggle)
pyqt-distutils 0.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: python: 293; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,122 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
try:
    import colorama
except ImportError:
    has_colorama = False
else:
    has_colorama = True

import shlex
try:
    # Python 3
    from shlex import quote
except ImportError:
    # Python 2
    from pipes import quote


def build_args(cmd, src, dst):
    """
        Build arguments list for passing to subprocess.call_check

        :param cmd str: Command string to interpolate src and dst filepaths into.
            Typically the output of `config.Config.uic_command` or `config.Config.rcc_command`.
        :param src str: Source filepath.
        :param dst str: Destination filepath.
    """
    cmd = cmd % (quote(src), quote(dst))
    args = shlex.split(cmd)

    return [arg for arg in args if arg]


def write_message(text, color=None):
    if has_colorama:
        colors = {
            'red': colorama.Fore.RED,
            'green': colorama.Fore.GREEN,
            'yellow': colorama.Fore.YELLOW,
            'blue': colorama.Fore.BLUE
        }
        try:
            print(colors[color] + text + colorama.Fore.RESET)
        except KeyError:
            print(text)
    else:
        print(text)