From 0ce0e2a279f6f39b6ce5f3b17699f285feca9ba1 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 16 Mar 2007 21:04:35 +0000 Subject: Bug 374215: Move all generally-useful Installation subroutines to Bugzilla::Install::Util Patch By Max Kanat-Alexander (module owner) a=mkanat --- Bugzilla/DB.pm | 1 + Bugzilla/Install/DB.pm | 32 +------ Bugzilla/Install/Requirements.pm | 74 +-------------- Bugzilla/Install/Util.pm | 198 +++++++++++++++++++++++++++++++++++++++ Bugzilla/Version.pm | 2 +- 5 files changed, 202 insertions(+), 105 deletions(-) create mode 100644 Bugzilla/Install/Util.pm (limited to 'Bugzilla') diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index 098a9414c..ffa3e96d1 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -37,6 +37,7 @@ use base qw(DBI::db); use Bugzilla::Constants; use Bugzilla::Install::Requirements; +use Bugzilla::Install::Util qw(vers_cmp); use Bugzilla::Install::Localconfig; use Bugzilla::Util; use Bugzilla::Error; diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 7d4939877..96bc161ac 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -25,6 +25,7 @@ use strict; use Bugzilla::Bug qw(is_open_state); use Bugzilla::Constants; use Bugzilla::Hook; +use Bugzilla::Install::Util qw(indicate_progress); use Bugzilla::Util; use Bugzilla::Series; @@ -32,23 +33,6 @@ use Date::Parse; use Date::Format; use IO::File; -use base qw(Exporter); -our @EXPORT_OK = qw( - indicate_progress -); - -sub indicate_progress { - my ($params) = @_; - my $current = $params->{current}; - my $total = $params->{total}; - my $every = $params->{every} || 1; - - print "." if !($current % $every); - if ($current % ($every * 60) == 0) { - print "$current/$total (" . int($current * 100 / $total) . "%)\n"; - } -} - # NOTE: This is NOT the function for general table updates. See # update_table_definitions for that. This is only for the fielddefs table. sub update_fielddefs_definition { @@ -2794,18 +2778,4 @@ Params: none Returns: nothing -=item C $total, current => $count, every => 1 })> - -Description: This prints out lines of dots as a long update is going on, - to let the user know where we are and that we're not frozen. - A new line of dots will start every 60 dots. - -Params: C - The total number of items we're processing. - C - The number of the current item we're processing. - C - How often the function should print out a dot. - For example, if this is 10, the function will print out - a dot every ten items. - -Returns: nothing - =back diff --git a/Bugzilla/Install/Requirements.pm b/Bugzilla/Install/Requirements.pm index 43cdaf7ec..c090fe1f4 100644 --- a/Bugzilla/Install/Requirements.pm +++ b/Bugzilla/Install/Requirements.pm @@ -25,8 +25,8 @@ package Bugzilla::Install::Requirements; use strict; +use Bugzilla::Install::Util qw(vers_cmp); use List::Util qw(max); -use POSIX (); use Safe; use base qw(Exporter); @@ -36,9 +36,7 @@ our @EXPORT = qw( check_requirements check_graphviz - display_version_and_os have_vers - vers_cmp install_command ); @@ -466,21 +464,6 @@ sub check_graphviz { return $return; } -sub display_version_and_os { - # Display version information - printf "\n* This is Bugzilla " . BUGZILLA_VERSION . " on perl %vd\n", - $^V; - my @os_details = POSIX::uname; - # 0 is the name of the OS, 2 is the major version, - my $os_name = $os_details[0] . ' ' . $os_details[2]; - if (ON_WINDOWS) { - require Win32; - $os_name = Win32::GetOSName(); - } - # 3 is the minor version. - print "* Running on $os_name $os_details[3]\n" -} - # This was originally clipped from the libnet Makefile.PL, adapted here to # use the below vers_cmp routine for accurate version checking. sub have_vers { @@ -533,49 +516,6 @@ sub have_vers { return $vok ? 1 : 0; } -# This is taken straight from Sort::Versions 1.5, which is not included -# with perl by default. -sub vers_cmp { - my ($a, $b) = @_; - - # Remove leading zeroes - Bug 344661 - $a =~ s/^0*(\d.+)/$1/; - $b =~ s/^0*(\d.+)/$1/; - - my @A = ($a =~ /([-.]|\d+|[^-.\d]+)/g); - my @B = ($b =~ /([-.]|\d+|[^-.\d]+)/g); - - my ($A, $B); - while (@A and @B) { - $A = shift @A; - $B = shift @B; - if ($A eq '-' and $B eq '-') { - next; - } elsif ( $A eq '-' ) { - return -1; - } elsif ( $B eq '-') { - return 1; - } elsif ($A eq '.' and $B eq '.') { - next; - } elsif ( $A eq '.' ) { - return -1; - } elsif ( $B eq '.' ) { - return 1; - } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) { - if ($A =~ /^0/ || $B =~ /^0/) { - return $A cmp $B if $A cmp $B; - } else { - return $A <=> $B if $A <=> $B; - } - } else { - $A = uc $A; - $B = uc $B; - return $A cmp $B if $A cmp $B; - } - } - @A <=> @B; -} - sub install_command { my $module = shift; my ($command, $package); @@ -656,18 +596,6 @@ Params: C<$output> - C<$true> if you want the function to Returns: C<1> if the check was successful, C<0> otherwise. -=item C - - Description: This is a comparison function, like you would use in - C, except that it compares two version numbers. - It's actually identical to versioncmp from - L. - - Params: c<$a> and C<$b> are versions you want to compare. - - Returns: -1 if $a is less than $b, 0 if they are equal, and - 1 if $a is greater than $b. - =item C Description: Tells you whether or not you have the appropriate diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm new file mode 100644 index 000000000..16f8f3e04 --- /dev/null +++ b/Bugzilla/Install/Util.pm @@ -0,0 +1,198 @@ +# -*- 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. +# +# The Initial Developer of the Original Code is Everything Solved. +# Portions created by Everything Solved are Copyright (C) 2006 +# Everything Solved. All Rights Reserved. +# +# Contributor(s): Max Kanat-Alexander + +package Bugzilla::Install::Util; + +# The difference between this module and Bugzilla::Util is that this +# module may require *only* Bugzilla::Constants and built-in +# perl modules. + +use strict; + +use Bugzilla::Constants; + +use POSIX (); + +use base qw(Exporter); +our @EXPORT_OK = qw( + display_version_and_os + indicate_progress + vers_cmp +); + +sub display_version_and_os { + # Display version information + printf "\n* This is Bugzilla " . BUGZILLA_VERSION . " on perl %vd\n", $^V; + my @os_details = POSIX::uname; + # 0 is the name of the OS, 2 is the major version, + my $os_name = $os_details[0] . ' ' . $os_details[2]; + if (ON_WINDOWS) { + require Win32; + $os_name = Win32::GetOSName(); + } + # 3 is the minor version. + print "* Running on $os_name $os_details[3]\n" +} + +sub indicate_progress { + my ($params) = @_; + my $current = $params->{current}; + my $total = $params->{total}; + my $every = $params->{every} || 1; + + print "." if !($current % $every); + if ($current % ($every * 60) == 0) { + print "$current/$total (" . int($current * 100 / $total) . "%)\n"; + } +} + +# This is taken straight from Sort::Versions 1.5, which is not included +# with perl by default. +sub vers_cmp { + my ($a, $b) = @_; + + # Remove leading zeroes - Bug 344661 + $a =~ s/^0*(\d.+)/$1/; + $b =~ s/^0*(\d.+)/$1/; + + my @A = ($a =~ /([-.]|\d+|[^-.\d]+)/g); + my @B = ($b =~ /([-.]|\d+|[^-.\d]+)/g); + + my ($A, $B); + while (@A and @B) { + $A = shift @A; + $B = shift @B; + if ($A eq '-' and $B eq '-') { + next; + } elsif ( $A eq '-' ) { + return -1; + } elsif ( $B eq '-') { + return 1; + } elsif ($A eq '.' and $B eq '.') { + next; + } elsif ( $A eq '.' ) { + return -1; + } elsif ( $B eq '.' ) { + return 1; + } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) { + if ($A =~ /^0/ || $B =~ /^0/) { + return $A cmp $B if $A cmp $B; + } else { + return $A <=> $B if $A <=> $B; + } + } else { + $A = uc $A; + $B = uc $B; + return $A cmp $B if $A cmp $B; + } + } + @A <=> @B; +} + +__END__ + +=head1 NAME + +Bugzilla::Install::Util - Utility functions that are useful both during +installation and afterwards. + +=head1 DESCRIPTION + +This module contains various subroutines that are used primarily +during installation. However, these subroutines can also be useful to +non-installation code, so they have been split out into this module. + +The difference between this module and L is that this +module is safe to C anywhere in Bugzilla, even during installation, +because it depends only on L and built-in perl modules. + +None of the subroutines are exported by default--you must explicitly +export them. + +=head1 SUBROUTINES + +=over + +=item C + +Prints out some text lines, saying what version of Bugzilla we're running, +what perl version we're using, and what OS we're running on. + +=item C + +=over + +=item B + +This prints out lines of dots as a long update is going on, to let the user +know where we are and that we're not frozen. A new line of dots will start +every 60 dots. + +Sample usage: C $total, current =E +$count, every =E 1 })> + +=item B + +Here's some sample output with C and C: + + ............................................................600/1000 (60%) + ........................................ + +=item B + +=over + +=item C - The total number of items we're processing. + +=item C - The number of the current item we're processing. + +=item C - How often the function should print out a dot. +For example, if this is 10, the function will print out a dot every +ten items. Defaults to 1 if not specified. + +=back + +=item B: nothing + +=back + +=item C + +=over + +=item B + +This is a comparison function, like you would use in C, except that +it compares two version numbers. So, for example, 2.10 would be greater +than 2.2. + +It's based on versioncmp from L, with some Bugzilla-specific +fixes. + +=item B: C<$a> and C<$b> - The versions you want to compare. + +=item B + +C<-1> if C<$a> is less than C<$b>, C<0> if they are equal, or C<1> if C<$a> +is greater than C<$b>. + +=back + +=back diff --git a/Bugzilla/Version.pm b/Bugzilla/Version.pm index ba7631a80..69eee3752 100644 --- a/Bugzilla/Version.pm +++ b/Bugzilla/Version.pm @@ -21,7 +21,7 @@ package Bugzilla::Version; use base qw(Bugzilla::Object); -use Bugzilla::Install::Requirements qw(vers_cmp); +use Bugzilla::Install::Util qw(vers_cmp); use Bugzilla::Util; use Bugzilla::Error; -- cgit v1.2.3-24-g4f1b