fixing various links to point to *.koha-community.org
[koha.git] / koha_perl_deps.pl
1 #!/usr/bin/perl
2
3 use Getopt::Long;
4 use Pod::Usage;
5 use Term::ANSIColor;
6 use FindBin; # we need to enforce which C4::Installer is used in case more than one is installed
7
8 use lib $FindBin::Bin;
9
10 use C4::Installer::PerlModules;
11
12 use strict;
13 use warnings;
14
15 my $help = 0;
16 my $missing = 0;
17 my $installed = 0;
18 my $upgrade = 0;
19 my $all = 0;
20 my $color = 0;
21
22 GetOptions(
23             'h|help|?'    => \$help,
24             'm|missing'   => \$missing,
25             'i|installed' => \$installed,
26             'u|upgrade'   => \$upgrade,
27             'a|all'       => \$all,
28             'c|color'     => \$color,
29           );
30
31 pod2usage(1) if $help || (!$missing && !$installed && !$upgrade && !$all);
32
33 my $koha_pm = C4::Installer::PerlModules->new;
34 $koha_pm->version_info(all => 1);
35
36 my @pm = ();
37
38 push @pm, 'missing_pm' if $missing || $all;
39 push @pm, 'upgrade_pm' if $upgrade || $all;
40 push @pm, 'current_pm' if $installed || $all;
41
42 print color 'bold white' if $color;
43 print"
44 Module Name                                 Current Version                       Required Version         Module Required
45 --------------------------------------------------------------------------------------------------------------------------
46 ";
47
48 my $count = 0;
49 foreach my $type (@pm) {
50     my $mod_type = $type;
51     $mod_type =~ s/_pm$//;
52     my $pm = $koha_pm->get_attr($type);
53     foreach (@$pm) {
54         foreach my $pm (keys(%$_)) {
55             print color 'yellow' if $type eq 'upgrade_pm' && $color;
56             print color 'red' if $type eq 'missing_pm' && $color;
57             print color 'green' if $type eq 'current_pm' && $color;
58             $count++;
59             my $required = ($_->{$pm}->{'required'}?'Yes':'No');
60             my $current_version = ($color ? $_->{$pm}->{'cur_ver'} :
61                                    $type eq 'missing_pm' || $type eq 'upgrade_pm' ? $_->{$pm}->{'cur_ver'}." *" : $_->{$pm}->{'cur_ver'});
62 format =
63 @<<<<<<<<<<<<<<<<<<<<<<<<<                  @<<<<<<<<<<                           @<<<<<<<<<<              @<<<<<
64 $pm,                                        $current_version,                     $_->{$pm}->{'min_ver'},  $required
65 .
66 write;
67         }
68     }
69 }
70 print color 'bold white' if $color;
71 my $footer = "
72 --------------------------------------------------------------------------------------------------------------------------
73 Total modules reported: $count                                                     ";
74
75 if ($color) {
76     $footer .= "\n\n";
77 }
78 else {
79     $footer .= "* Module is missing or requires an upgrade.\n\n";
80 }
81
82 print $footer;
83
84 1;
85
86 __END__
87
88 =head1 NAME
89
90 koha_perl_deps.pl
91
92 =head1 SYNOPSIS
93
94 ./koha_perl_deps.pl -m
95
96 =head1 OPTIONS
97
98 =over 8
99
100 =item B<-m|--missing>
101
102 lists all missing perl modules
103
104 =item B<-i|--installed>
105
106 lists all installed perl modules
107
108 =item B<-u|--upgrade>
109
110 lists all perl modules needing to be upgraded relative to Koha
111
112 =item B<-a|--all>
113
114 lists all koha perl dependencies
115
116 =item B<-c|--color>
117
118 formats the output in color; red = module is missing, yellow = module requires upgrading, green = module is installed and current
119
120 =item B<-h|--help|?>
121
122 prints this help text
123
124 =back
125
126 =head1 AUTHOR
127
128 Chris Nighswonger <cnighswonger AT foundations DOT edu>
129
130 =head1 COPYRIGHT
131
132 Copyright 2010 Foundations Bible College.
133
134 =head1 LICENSE
135
136 This file is part of Koha.
137
138 Koha 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
139 Foundation; either version 2 of the License, or (at your option) any later version.
140
141 You should have received a copy of the GNU General Public License along
142 with Koha; if not, write to the Free Software Foundation, Inc.,
143 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
144
145 =head1 DISCLAIMER OF WARRANTY
146
147 Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
148 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
149
150 =cut