1
# Copyright (C) 2010 Modestas Vainius <modax@debian.org>
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>
16
package Debian::PkgKde;
18
use base qw(Exporter);
19
our @EXPORT = qw(get_program_name
20
printmsg info warning errormsg error syserr usageerr);
21
our @EXPORT_OK = qw(find_datalibdir setup_datalibdir DATALIBDIR);
23
# Determine datalib for current script. It depends on the context the script
25
use constant DATALIBDIR => '/usr/share/pkg-kde-tools/lib';
30
if ($0 =~ m@^(.+)/[^/]+$@) {
31
push @dirs, "$1/datalib";
33
push @dirs, DATALIBDIR;
35
# Verify if the dir and hint files exist
37
foreach my $dir (@dirs) {
39
if ($dir && -d $dir) {
41
foreach my $hint (@hintfiles) {
42
unless (-e "$dir/$hint") {
57
# Add DATALIBDIR to @INC if the script is NOT being run from the source tree.
58
sub setup_datalibdir {
59
my $dir = find_datalibdir(@_);
61
unshift @INC, DATALIBDIR if $dir eq DATALIBDIR;
63
error("unable to locate pkg-kde-tools library directory");
70
sub get_program_name {
71
unless (defined $progname) {
72
$progname = ($0 =~ m,/([^/]+)$,) ? $1 : $0;
82
my $msg = sprintf($format, @_);
83
return ((defined $type) ?
84
get_program_name() . ": $type: " : "") . "$msg\n";
88
print STDERR format_message(undef, @_);
92
print STDERR format_message("info", @_);
96
warn format_message("warning", @_);
101
die format_message("error", "$msg: $!", @_);
105
print STDERR format_message("error", @_);
109
die format_message("error", @_);
113
die format_message("usage", @_);