]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 374215: Move all generally-useful Installation subroutines to Bugzilla::Install...
authormkanat%bugzilla.org <>
Fri, 16 Mar 2007 21:04:35 +0000 (21:04 +0000)
committermkanat%bugzilla.org <>
Fri, 16 Mar 2007 21:04:35 +0000 (21:04 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat

Bugzilla/DB.pm
Bugzilla/Install/DB.pm
Bugzilla/Install/Requirements.pm
Bugzilla/Install/Util.pm [new file with mode: 0644]
Bugzilla/Version.pm
checksetup.pl
query.cgi

index 098a9414c98e7950a694adeed25632f9f5e67062..ffa3e96d19bc6858ca430e109c8c1ebe18cb4367 100644 (file)
@@ -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;
index 7d49398771a81bd07ae2ecf199fe661460c02a8b..96bc161ac2521dc0b0d6fc098b5bdf2b7123e09e 100644 (file)
@@ -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<indicate_progress({ total => $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<total> - The total number of items we're processing.
-             C<current> - The number of the current item we're processing.
-             C<every> - 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
index 43cdaf7ec18ce5c58d476077feff077518601015..c090fe1f4c2fe49917c5ff543030b186e07a5d95 100644 (file)
@@ -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<vers_cmp($a, $b)>
-
- Description: This is a comparison function, like you would use in
-              C<sort>, except that it compares two version numbers.
-              It's actually identical to versioncmp from 
-              L<Sort::Versions>.
-
- 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<have_vers($module, $output)>
 
  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 (file)
index 0000000..16f8f3e
--- /dev/null
@@ -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 <mkanat@bugzilla.org>
+
+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<Bugzilla::Util> is that this
+module is safe to C<use> anywhere in Bugzilla, even during installation,
+because it depends only on L<Bugzilla::Constants> and built-in perl modules.
+
+None of the subroutines are exported by default--you must explicitly
+export them.
+
+=head1 SUBROUTINES
+
+=over
+
+=item C<display_version_and_os>
+
+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<indicate_progress>
+
+=over
+
+=item B<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.
+
+Sample usage: C<indicate_progress({ total =E<gt> $total, current =E<gt>
+$count, every =E<gt> 1 })>
+
+=item B<Sample Output>
+
+Here's some sample output with C<total = 1000> and C<every = 10>:
+
+ ............................................................600/1000 (60%)
+ ........................................
+
+=item B<Params>
+
+=over
+
+=item C<total> - The total number of items we're processing.
+
+=item C<current> - The number of the current item we're processing.
+
+=item C<every> - 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<Returns>: nothing
+
+=back
+
+=item C<vers_cmp>
+
+=over
+
+=item B<Description>
+
+This is a comparison function, like you would use in C<sort>, 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<Sort::Versions>, with some Bugzilla-specific
+fixes.
+
+=item B<Params>: C<$a> and C<$b> - The versions you want to compare.
+
+=item B<Returns>
+
+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
index ba7631a805827879a98fb6d78fde81b41b31ed0e..69eee3752925f0557d90a9f468748c42dae82a69 100644 (file)
@@ -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;
 
index eefff49181965cfd01fda4d522ba4e39c2bf3798..5e684db0a78af7bd1b2e065c04e82b576ade40e0 100755 (executable)
@@ -54,6 +54,7 @@ BEGIN { chdir dirname($0); }
 use lib ".";
 use Bugzilla::Constants;
 use Bugzilla::Install::Requirements;
+use Bugzilla::Install::Util qw(display_version_and_os);
 
 require 5.008001 if ON_WINDOWS; # for CGI 2.93 or higher
 
index ce6aefc617b2412cd5e4a33397e38431902e1524..3d18606ba1b9512a5bd5700c3c778472416fc353 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -38,7 +38,7 @@ use Bugzilla::Error;
 use Bugzilla::Product;
 use Bugzilla::Keyword;
 use Bugzilla::Field;
-use Bugzilla::Install::Requirements;
+use Bugzilla::Install::Util qw(vers_cmp);
 
 my $cgi = Bugzilla->cgi;
 my $dbh = Bugzilla->dbh;