aboutsummaryrefslogtreecommitdiff
path: root/0.4.0/ebuild/echo_functions.bash.in
blob: 4c9978cff459b1f54814da6c3d083aecf2e81db1 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# vim: set sw=4 sts=4 et :

@GENERATED_FILE@

# Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
#
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
# Gentoo Foundation and distributed under the terms of the GNU General
# Public License v2.
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA

[[ -z ${PALUDIS_COLOURS} ]] && PALUDIS_COLOURS=@COLOURSCHEME@

COLOUR_GREEN=$'\e[32;01m'
COLOUR_YELLOW=$'\e[33;01m'
COLOUR_RED=$'\e[31;01m'
COLOUR_BLUE=$'\e[34;01m'
COLOUR_PINK=$'\e[35;01m'

if [[ ${PALUDIS_COLOURS} == pink ]]; then
    COLOUR_GOOD=${COLOUR_PINK}
    COLOUR_WARN=${COLOUR_YELLOW}
    COLOUR_BAD=${COLOUR_RED}
    COLOUR_BRACKET=${COLOUR_PINK}
else
    COLOUR_GOOD=${COLOUR_GREEN}
    COLOUR_WARN=${COLOUR_YELLOW}
    COLOUR_BAD=${COLOUR_RED}
    COLOUR_BRACKET=${COLOUR_BLUE}
fi

COLOUR_NORMAL=$'\e[0m'
PALUDIS_ENDCOL=$'\e[A\e['$(( ${COLUMNS:-80} - 7 ))'G'

einfon()
{
    echo -ne " ${COLOUR_GOOD}*${COLOUR_NORMAL} $*"
    PALUDIS_LAST_E_CMD=einfon
}

einfo()
{
    einfon "$*\n"
    PALUDIS_LAST_E_CMD=einfo
}

elog()
{
    einfo "$@"
}

ewarn()
{
    echo -e " ${COLOUR_WARN}*${COLOUR_NORMAL} $*"
    PALUDIS_LAST_E_CMD=ewarn
}

eerror()
{
    echo -e " ${COLOUR_BAD}*${COLOUR_NORMAL} $*"
    PALUDIS_LAST_E_CMD=eerror
}

ebegin()
{
    einfo "$* ..."
    PALUDIS_LAST_E_CMD=ebegin
    PALUDIS_LAST_E_LEN=$(( 4 + ${#msg} ))
}

_eend()
{
    local retval=${1:-0} efunc=${2:-eerror} msg
    shift 2

    if [[ ${retval} == 0 ]]; then
        msg="${COLOUR_BRACKET}[ ${COLOUR_GOOD}ok${COLOUR_BRACKET} ]${COLOUR_NORMAL}"
    else
        if [[ -n "$*" ]]; then
            ${efunc} $*
        fi
        msg="${COLOUR_BRACKET}[ ${COLOUR_BAD}!!${COLOUR_BRACKET} ]${COLOUR_NORMAL}"
    fi

#    printf "%$(( ${COLUMNS:-80} - PALUDIS_LAST_E_LEN - 6))s%b\n" '' "${msg}"
    echo -e "${PALUDIS_ENDCOL} ${msg}"

    return ${retval}
}

eend()
{
    local retval=${1:-0}
    shift
    _eend ${retval} eerror "$*"
    PALUDIS_LAST_E_CMD=eend
    return ${retval}
}

ewend()
{
    local retval=${1:-0}
    shift
    _eend ${retval} ewarn "$*"
    PALUDIS_LAST_E_CMD=ewend
    return ${retval}
}

use_with()
{
    if useq "${1}" ; then
        echo "--with-${2:-${1}}${3+=${3}}"
    else
        echo "--without-${2:-${1}}"
    fi
}

use_enable()
{
    if useq "${1}" ; then
        echo "--enable-${2:-${1}}${3+=${3}}"
    else
        echo "--disable-${2:-${1}}"
    fi
}

ebuild_notice_level()
{
    case "$1" in
        debug)
            echo "1";
            ;;

        qa)
            echo "2";
            ;;

        warning)
            echo "3";
            ;;

        silent)
            echo "4";
            ;;

        *)
            echo "[WARNING.EBUILD] Bad value '$1' for qa level" 1>&2
            echo "2";
            ;;
    esac
}

ebuild_notice()
{
    local level="$1"
    shift

    local level_num=$(ebuild_notice_level "${level}" )
    local min_level_num=$(ebuild_notice_level "${PALUDIS_EBUILD_LOG_LEVEL}" )

    if [[ "${level_num}" -ge "${min_level_num}" ]] ; then
        local upper_level=$(echo ${level} | ${ebuild_real_tr:-tr} '[:lower:]' '[:upper:]' )
        echo -n "${EBUILD_PROGRAM_NAME:-ebuild.bash}@$(${ebuild_real_date:-date} +%s ): " 1>&2
        echo "[${upper_level}.EBUILD] $* (from ${EBUILD:-?})" 1>&2
    fi
    true
}

ebuild_section()
{
    echo ">>> $*"
}