aboutsummaryrefslogtreecommitdiff
blob: c070a0feb107a9aaacaf450ab6a8ceb61b40b147 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
#
# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright 2004-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
# $Header$

"""Provides a consistent color scheme for Gentoolkit scripts."""

__all__ = (
	'command',
	'cpv',
	'die',
	'emph',
	'error',
	'globaloption',
	'installedflag',
	'localoption',
	'number',
	'path',
	'path_symlink',
	'pkgquery',
	'productname',
	'regexpquery',
	'section',
	'slot',
	'subsection',
	'useflag',
	'warn'
)

# =======
# Imports
# =======

import sys

import portage.output as output

# =========
# Functions
# =========

# output creates color functions on the fly, which confuses pylint.
# E1101: *%s %r has no %r member*
# pylint: disable-msg=E1101

def command(string):
	"""Returns a program command string."""
	return output.green(string)

def cpv(string):
	"""Returns a category/package-<version> string."""
	return output.green(string)

def die(err, string):
	"""Returns an error string and die with an error code."""
	sys.stderr.write(error(string))
	sys.exit(err)

def emph(string):
	"""Returns a string as emphasized."""
	return output.bold(string)

def error(string):
	"""Prints an error string."""
	return output.red("!!! ") + string + "\n"

def globaloption(string):
	"""Returns a global option string, i.e. the program global options."""
	return output.yellow(string)

def localoption(string):
	"""Returns a local option string, i.e. the program local options."""
	return output.green(string)

def number(string):
	"""Returns a number string."""
	return output.turquoise(string)

def path(string):
	"""Returns a file or directory path string."""
	return output.bold(string)

def path_symlink(string):
	"""Returns a symlink string."""
	return output.turquoise(string)

def pkgquery(string):
	"""Returns a package query string."""
	return output.bold(string)

def productname(string):
	"""Returns a product name string, i.e. the program name."""
	return output.turquoise(string)

def regexpquery(string):
	"""Returns a regular expression string."""
	return output.bold(string)

def section(string):
	"""Returns a string as a section header."""
	return output.turquoise(string)

def slot(string):
	"""Returns a slot string"""
	return output.bold(string)

def subsection(string):
	"""Returns a string as a subsection header."""
	return output.turquoise(string)

def useflag(string, enabled=True):
	"""Returns a USE flag string."""
	return output.blue(string) if enabled else output.red(string)

def keyword(string, stable=True, hard_masked=False):
	"""Returns a keyword string."""
	if stable:
		return output.green(string)
	if hard_masked:
		return output.red(string)
	# keyword masked:
	return output.blue(string)

def warn(string):
	"""Returns a warning string."""
	return "!!! " + string + "\n"

# vim: set ts=4 sw=4 tw=79: