📄 requirements.pm
字号:
# -*- Mode: perl; indent-tabs-mode: nil -*-## The contents of this file are subject to the Mozilla Public# License Version 1.1 (the "License"); you may not use this file# except in compliance with the License. You may obtain a copy of# the License at http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or# implied. See the License for the specific language governing# rights and limitations under the License.## The Original Code is the Bugzilla Bug Tracking System.## Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org># Marc Schumann <wurblzap@gmail.com>package Bugzilla::Install::Requirements;# NOTE: This package MUST NOT "use" any Bugzilla modules other than# Bugzilla::Constants, anywhere. We may "use" standard perl modules.## Subroutines may "require" and "import" from modules, but they# MUST NOT "use."use strict;use List::Util qw(max);use POSIX ();use Safe;use base qw(Exporter);our @EXPORT = qw( REQUIRED_MODULES OPTIONAL_MODULES check_requirements check_graphviz display_version_and_os have_vers vers_cmp install_command);use Bugzilla::Constants;# The below two constants are subroutines so that they can implement# a hook. Other than that they are actually constants.# "package" is the perl package we're checking for. "module" is the name# of the actual module we load with "require" to see if the package is# installed or not. "version" is the version we need, or 0 if we'll accept# any version.## "blacklist" is an arrayref of regular expressions that describe versions that# are 'blacklisted'--that is, even if the version is high enough, Bugzilla# will refuse to say that it's OK to run with that version.sub REQUIRED_MODULES { my $perl_ver = sprintf('%vd', $^V); my @modules = ( { package => 'CGI.pm', module => 'CGI', # Perl 5.10 requires CGI 3.33 due to a taint issue when # uploading attachments, see bug 416382. version => (vers_cmp($perl_ver, '5.10') > -1) ? '3.33' : '2.93' }, { package => 'TimeDate', module => 'Date::Format', version => '2.21' }, { package => 'DBI', module => 'DBI', version => '1.41' }, { package => 'PathTools', module => 'File::Spec', version => '0.84' }, { package => 'Template-Toolkit', module => 'Template', version => '2.12' }, { package => 'Email-Send', module => 'Email::Send', version => ON_WINDOWS ? '2.16' : '2.00' }, { package => 'Email-MIME', module => 'Email::MIME', version => '1.861' }, { package => 'Email-MIME-Modifier', module => 'Email::MIME::Modifier', version => '1.442' }, ); my $all_modules = _get_extension_requirements( 'REQUIRED_MODULES', \@modules); return $all_modules;};sub OPTIONAL_MODULES { my @modules = ( { package => 'GD', module => 'GD', version => '1.20', feature => 'Graphical Reports, New Charts, Old Charts' }, { package => 'Template-GD', # This module tells us whether or not Template-GD is installed # on Template-Toolkits after 2.14, and still works with 2.14 and lower. module => 'Template::Plugin::GD::Image', version => 0, feature => 'Graphical Reports' }, { package => 'Chart', module => 'Chart::Base', version => '1.0', feature => 'New Charts, Old Charts' }, { package => 'GDGraph', module => 'GD::Graph', version => 0, feature => 'Graphical Reports' }, { package => 'GDTextUtil', module => 'GD::Text', version => 0, feature => 'Graphical Reports' }, { package => 'XML-Twig', module => 'XML::Twig', version => 0, feature => 'Move Bugs Between Installations' }, { package => 'MIME-tools', # MIME::Parser is packaged as MIME::Tools on ActiveState Perl module => ON_WINDOWS ? 'MIME::Tools' : 'MIME::Parser', version => '5.406', feature => 'Move Bugs Between Installations' }, { package => 'libwww-perl', module => 'LWP::UserAgent', version => 0, feature => 'Automatic Update Notifications' }, { package => 'PatchReader', module => 'PatchReader', version => '0.9.4', feature => 'Patch Viewer' }, { package => 'PerlMagick', module => 'Image::Magick', version => 0, feature => 'Optionally Convert BMP Attachments to PNGs' }, { package => 'perl-ldap', module => 'Net::LDAP', version => 0, feature => 'LDAP Authentication' }, { package => 'SOAP-Lite', module => 'SOAP::Lite', version => 0, feature => 'XML-RPC Interface' }, { # We need the 'utf8_mode' method of HTML::Parser, for HTML::Scrubber. package => 'HTML-Parser', module => 'HTML::Parser', version => '3.40', feature => 'More HTML in Product/Group Descriptions' }, { package => 'HTML-Scrubber', module => 'HTML::Scrubber', version => 0, feature => 'More HTML in Product/Group Descriptions' }, # Inbound Email { package => 'Email-MIME-Attachment-Stripper', module => 'Email::MIME::Attachment::Stripper', version => 0, feature => 'Inbound Email' }, { package => 'Email-Reply', module => 'Email::Reply', version => 0, feature => 'Inbound Email' }, # mod_perl { package => 'mod_perl', module => 'mod_perl2', version => '1.999022', feature => 'mod_perl' }, ); # Even very new releases of perl (5.8.5) don't come with this version, # so I didn't want to make it a general requirement just for # running under mod_cgi. # If Perl 5.10 is installed, then CGI 3.33 is already required. So this # check is only relevant with Perl 5.8.x. my $perl_ver = sprintf('%vd', $^V); if (vers_cmp($perl_ver, '5.10') < 0) { push(@modules, { package => 'CGI.pm', module => 'CGI', version => '3.11', feature => 'mod_perl' }); } my $all_modules = _get_extension_requirements( 'OPTIONAL_MODULES', \@modules); return $all_modules;};# This implements the install-requirements hook described in Bugzilla::Hook.sub _get_extension_requirements { my ($function, $base_modules) = @_; my @all_modules; # get a list of all extensions my @extensions = glob(bz_locations()->{'extensionsdir'} . "/*"); foreach my $extension (@extensions) { my $file = "$extension/code/install-requirements.pl"; if (-e $file) { my $safe = new Safe; # This is a very liberal Safe. $safe->permit(qw(:browse require entereval caller)); $safe->rdo($file); if ($@) { warn $@; next; } my $modules = eval { &{$safe->varglob($function)}($base_modules) }; next unless $modules; push(@all_modules, @$modules); } } unshift(@all_modules, @$base_modules); return \@all_modules;};sub check_requirements { my ($output) = @_; print "\nChecking perl modules...\n" if $output; my $root = ROOT_USER; my %missing = _check_missing(REQUIRED_MODULES, $output); print "\nChecking available perl DBD modules...\n" if $output; my $have_one_dbd = 0; my $db_modules = DB_MODULE; foreach my $db (keys %$db_modules) { my $dbd = $db_modules->{$db}->{dbd}; $have_one_dbd = 1 if have_vers($dbd, $output); } print "\nThe following Perl modules are optional:\n" if $output; my %missing_optional = _check_missing(OPTIONAL_MODULES, $output); # If we're running on Windows, reset the input line terminator so that # console input works properly - loading CGI tends to mess it up $/ = "\015\012" if ON_WINDOWS; my $pass = !scalar(keys %missing) && $have_one_dbd; return { pass => $pass, one_dbd => $have_one_dbd, missing => \%missing, optional => \%missing_optional, any_missing => !$pass || scalar(keys %missing_optional), };}# A helper for check_requirementssub _check_missing { my ($modules, $output) = @_; my %missing; foreach my $module (@$modules) { unless (have_vers($module, $output)) { $missing{$module->{package}} = $module; } } return %missing;}# Returns the build ID of ActivePerl. If several versions of# ActivePerl are installed, it won't be able to know which one# you are currently running. But that's our best guess.sub _get_activestate_build_id { eval 'use Win32::TieRegistry'; return 0 if $@; my $key = Win32::TieRegistry->new('LMachine\Software\ActiveState\ActivePerl') or return 0; return $key->GetValue("CurrentVersion");}sub print_module_instructions { my ($check_results, $output) = @_; # We only print these notes if we have to. if ((!$output && %{$check_results->{missing}}) || ($output && $check_results->{any_missing})) { print "\n* NOTE: You must run any commands listed below as " . ROOT_USER . ".\n\n"; if (ON_WINDOWS) { my $perl_ver = sprintf('%vd', $^V); # URL when running Perl 5.8.x. my $url_to_theory58S = 'http://theoryx5.uwinnipeg.ca/ppms'; my $repo_up_cmd ='* *'; # Packages for Perl 5.10 are not compatible with Perl 5.8. if (vers_cmp($perl_ver, '5.10') > -1) { $url_to_theory58S = 'http://cpan.uwinnipeg.ca/PPMPackages/10xx/'; } # ActivePerl older than revision 819 require an additional command. if (_get_activestate_build_id() < 819) { $repo_up_cmd = <<EOT;* ** Then you have to do (also as an Administrator): ** ** ppm repo up theory58S ** ** Do that last command over and over until you see "theory58S" at the ** top of the displayed list. *EOT } print <<EOT;************************************************************************ Note For Windows Users ************************************************************************* In order to install the modules listed below, you first have to run * * the following command as an Administrator: ** ** ppm repo add theory58S $url_to_theory58S
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -