📄 localconfig.pm
字号:
elsif (defined @$glob) { $localconfig{$var} = \@$glob; } elsif (defined %$glob) { $localconfig{$var} = \%$glob; } } } return \%localconfig;}## This is quite tricky. But fun!## First we read the file 'localconfig'. Then we check if the variables we# need are defined. If not, we will append the new settings to# localconfig, instruct the user to check them, and stop.## Why do it this way?## Assume we will enhance Bugzilla and eventually more local configuration# stuff arises on the horizon.## But the file 'localconfig' is not in the Bugzilla CVS or tarfile. You# know, we never want to overwrite your own version of 'localconfig', so# we can't put it into the CVS/tarfile, can we?## Now, when we need a new variable, we simply add the necessary stuff to# LOCALCONFIG_VARS. When the user gets the new version of Bugzilla from CVS and# runs checksetup, it finds out "Oh, there is something new". Then it adds# some default value to the user's local setup and informs the user to# check that to see if it is what the user wants.## Cute, ey?#sub update_localconfig { my ($params) = @_; my $output = $params->{output} || 0; my $answer = Bugzilla->installation_answers; my $localconfig = read_localconfig('include deprecated'); my @new_vars; foreach my $var (LOCALCONFIG_VARS) { my $name = $var->{name}; if (!defined $localconfig->{$name}) { push(@new_vars, $name); $var->{default} = &{$var->{default}} if ref($var->{default}) eq 'CODE'; $localconfig->{$name} = $answer->{$name} || $var->{default}; } } my @old_vars; foreach my $name (OLD_LOCALCONFIG_VARS) { push(@old_vars, $name) if defined $localconfig->{$name}; } if (!$localconfig->{'interdiffbin'} && $output) { print <<EOTOPTIONAL NOTE: If you want to be able to use the 'difference between twopatches' feature of Bugzilla (which requires the PatchReader Perl moduleas well), you should install patchutils from: http://cyberelk.net/tim/patchutils/EOT } my $filename = bz_locations->{'localconfig'}; if (scalar @old_vars) { my $oldstuff = join(', ', @old_vars); print <<EOTThe following variables are no longer used in $filename, andshould be removed: $oldstuffEOT } if (scalar @new_vars) { my $filename = bz_locations->{'localconfig'}; my $fh = new IO::File($filename, '>>') || die "$filename: $!"; $fh->seek(0, SEEK_END); foreach my $var (LOCALCONFIG_VARS) { if (grep($_ eq $var->{name}, @new_vars)) { print $fh "\n", $var->{desc}, Data::Dumper->Dump([$localconfig->{$var->{name}}], ["*$var->{name}"]); } } my $newstuff = join(', ', @new_vars); print <<EOT;This version of Bugzilla contains some variables that you may want to change and adapt to your local settings. Please edit the file $filename and rerun checksetup.pl.The following variables are new to $filename since you last ranchecksetup.pl: $newstuffEOT exit; } # Reset the cache for Bugzilla->localconfig so that it will be re-read delete Bugzilla->request_cache->{localconfig}; return { old_vars => \@old_vars, new_vars => \@new_vars };}sub _get_default_cvsbin { return '' if ON_WINDOWS; my $cvs_executable = `which cvs`; if ($cvs_executable =~ /no cvs/ || $cvs_executable eq '') { # If which didn't find it, just set to blank $cvs_executable = ""; } else { chomp $cvs_executable; } return $cvs_executable;}sub _get_default_interdiffbin { return '' if ON_WINDOWS; my $interdiff = `which interdiff`; if ($interdiff =~ /no interdiff/ || $interdiff eq '') { # If which didn't find it, just set to blank $interdiff = ''; } else { chomp $interdiff; } return $interdiff;}sub _get_default_diffpath { return '' if ON_WINDOWS; my $diff_binaries; $diff_binaries = `which diff`; if ($diff_binaries =~ /no diff/ || $diff_binaries eq '') { # If which didn't find it, set to blank $diff_binaries = ""; } else { $diff_binaries =~ s:/diff\n$::; } return $diff_binaries;}1;__END__=head1 NAMEBugzilla::Install::Localconfig - Functions and variables dealing with the manipulation and creation of the F<localconfig> file.=head1 SYNOPSIS use Bugzilla::Install::Requirements qw(update_localconfig); update_localconfig({ output => 1 });=head1 DESCRIPTIONThis module is used primarily by L<checksetup.pl> to create andmodify the localconfig file. Most scripts should use L<Bugzilla/localconfig>to access localconfig variables.=head1 CONSTANTS=over=item C<LOCALCONFIG_VARS>An array of hashrefs. These hashrefs contain three keys: name - The name of the variable. default - The default value for the variable. Should always be something that can fit in a scalar. desc - Additional text to put in localconfig before the variable definition. Must end in a newline. Each line should start with "#" unless you have some REALLY good reason not to do that.=item C<OLD_LOCALCONFIG_VARS>An array of names of variables. If C<update_localconfig> finds thesevariables defined in localconfig, it will print out a warning.=back=head1 SUBROUTINES=over=item C<read_localconfig($include_deprecated)>Description: Reads the localconfig file and returns all valid values in a hashref.Params: C<$include_deprecated> - C<true> if you want the returned hashref to also include variables listed in C<OLD_LOCALCONFIG_VARS>, if they exist. Generally this is only for use by C<update_localconfig>.Returns: A hashref of the localconfig variables. If an array is defined, it will be an arrayref in the returned hash. If a hash is defined, it will be a hashref in the returned hash. Only includes variables specified in C<LOCALCONFIG_VARS> (and C<OLD_LOCALCONFIG_VARS> if C<$include_deprecated> is specified).=item C<update_localconfig({ output =E<gt> 1 })>Description: Adds any new variables to localconfig that aren't currently defined there. Also optionally prints out a message about vars that *should* be there and aren't. Exits the program if it adds any new vars.Params: C<output> - C<true> if the function should display informational output and warnings. It will always display errors or any message which would cause program execution to halt.Returns: A hashref, with C<old_vals> being an array of names of variables that were removed, and C<new_vals> being an array of names of variables that were added to localconfig.=back
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -