ff92a26247974a3e88ef1533d482bd1017565c0b
[gentoolkit.git] / trunk / src / gentoolkit / pprinter.py
1 #!/usr/bin/python
2 #
3 # Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
4 # Copyright 2004 Gentoo Foundation
5 # Distributed under the terms of the GNU General Public License v2
6 #
7 # $Header$
8
9 import sys
10 import gentoolkit
11
12 try:
13         import portage.output as output
14 except ImportError:
15         import output
16
17
18 def print_error(s):
19         """Prints an error string to stderr."""
20         sys.stderr.write(output.red("!!! ") + s + "\n")
21
22 def print_info(lv, s, line_break = True):
23         """Prints an informational string to stdout."""
24         if gentoolkit.Config["verbosityLevel"] >= lv:
25                 sys.stdout.write(s)
26                 if line_break:
27                         sys.stdout.write("\n")
28
29 def print_warn(s):
30         """Print a warning string to stderr."""
31         sys.stderr.write("!!! " + s + "\n")
32         
33 def die(err, s):
34         """Print an error string and die with an error code."""
35         print_error(s)
36         sys.exit(err)
37
38 # Colour settings
39
40 def cpv(s):
41         """Print a category/package-<version> string."""
42         return output.green(s)
43
44 def slot(s):
45         """Print a slot string"""
46         return output.bold(s)
47         
48 def useflag(s):
49         """Print a USE flag strign"""
50         return output.blue(s)
51
52 def useflagon(s):
53         """Print an enabled USE flag string"""
54         # FIXME: Collapse into useflag with parameter
55         return output.red(s)
56
57 def useflagoff(s):
58         """Print a disabled USE flag string"""
59         # FIXME: Collapse into useflag with parameter
60         return output.blue(s)
61         
62 def maskflag(s):
63         """Print a masking flag string"""
64         return output.red(s)
65
66 def installedflag(s):
67         """Print an installed flag string"""
68         return output.bold(s)
69         
70 def number(s):
71         """Print a number string"""
72         return output.turquoise(s)
73
74 def pkgquery(s):
75         """Print a package query string."""
76         return output.bold(s)
77
78 def regexpquery(s):
79         """Print a regular expression string"""
80         return output.bold(s)
81
82 def path(s):
83         """Print a file or directory path string"""
84         return output.bold(s)
85
86 def path_symlink(s):
87         """Print a symlink string."""
88         return output.turquoise(s)
89
90 def productname(s):
91         """Print a product name string, i.e. the program name."""
92         return output.turquoise(s)
93         
94 def globaloption(s):
95         """Print a global option string, i.e. the program global options."""
96         return output.yellow(s)
97
98 def localoption(s):
99         """Print a local option string, i.e. the program local options."""
100         return output.green(s)
101
102 def command(s):
103         """Print a program command string."""
104         return output.green(s)
105         
106 def section(s):
107         """Print a string as a section header."""
108         return output.turquoise(s)      
109
110 def subsection(s):
111         """Print a string as a subsection header."""
112         return output.turquoise(s)
113         
114 def emph(s):
115         """Print a string as emphasized."""
116         return output.bold(s)