Bug 7242 : Fixing typo in a div
[koha.git] / koha_perl_deps.pl
blobc5b614ec3d0d01bda9b70f33e804b961169d96ff
1 #!/usr/bin/perl
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
8 use lib $FindBin::Bin;
10 use C4::Installer::PerlModules;
12 use strict;
13 use warnings;
15 my $help = 0;
16 my $missing = 0;
17 my $installed = 0;
18 my $upgrade = 0;
19 my $all = 0;
20 my $color = 0;
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,
31 pod2usage(1) if $help || (!$missing && !$installed && !$upgrade && !$all);
33 my $koha_pm = C4::Installer::PerlModules->new;
34 $koha_pm->version_info(all => 1);
36 my @pm = ();
38 push @pm, 'missing_pm' if $missing || $all;
39 push @pm, 'upgrade_pm' if $upgrade || $all;
40 push @pm, 'current_pm' if $installed || $all;
42 print color 'bold white' if $color;
43 print"
44 Installed Required Module is
45 Module Name Version Version Required
46 --------------------------------------------------------------------------------------------
49 my $count = 0;
50 foreach my $type (@pm) {
51 my $mod_type = $type;
52 $mod_type =~ s/_pm$//;
53 my $pm = $koha_pm->get_attr($type);
54 foreach (@$pm) {
55 foreach my $pm (keys(%$_)) {
56 print color 'yellow' if $type eq 'upgrade_pm' && $color;
57 print color 'red' if $type eq 'missing_pm' && $color;
58 print color 'green' if $type eq 'current_pm' && $color;
59 $count++;
60 my $required = ($_->{$pm}->{'required'}?'Yes':'No');
61 my $current_version = ($color ? $_->{$pm}->{'cur_ver'} :
62 $type eq 'missing_pm' || $type eq 'upgrade_pm' ? $_->{$pm}->{'cur_ver'}." *" : $_->{$pm}->{'cur_ver'});
63 format =
64 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<
65 $pm, $current_version, $_->{$pm}->{'min_ver'}, $required
67 write;
71 print color 'bold white' if $color;
72 my $footer = "
73 --------------------------------------------------------------------------------------------
74 Total modules reported: $count ";
76 if ($color) {
77 $footer .= "\n\n";
79 else {
80 $footer .= "* Module is missing or requires an upgrade.\n\n";
83 print $footer;
87 __END__
89 =head1 NAME
91 koha_perl_deps.pl
93 =head1 SYNOPSIS
95 ./koha_perl_deps.pl -m
97 =head1 OPTIONS
99 =over 8
101 =item B<-m|--missing>
103 lists all missing perl modules
105 =item B<-i|--installed>
107 lists all installed perl modules
109 =item B<-u|--upgrade>
111 lists all perl modules needing to be upgraded relative to Koha
113 =item B<-a|--all>
115 lists all koha perl dependencies
117 =item B<-c|--color>
119 formats the output in color; red = module is missing, yellow = module requires upgrading, green = module is installed and current
121 =item B<-h|--help|?>
123 prints this help text
125 =back
127 =head1 AUTHOR
129 Chris Nighswonger <cnighswonger AT foundations DOT edu>
131 =head1 COPYRIGHT
133 Copyright 2010 Foundations Bible College.
135 =head1 LICENSE
137 This file is part of Koha.
139 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
140 Foundation; either version 2 of the License, or (at your option) any later version.
142 You should have received a copy of the GNU General Public License along
143 with Koha; if not, write to the Free Software Foundation, Inc.,
144 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
146 =head1 DISCLAIMER OF WARRANTY
148 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
149 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
151 =cut