mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-19 18:34:59 +00:00
Add lib/Percona/Toolkit.pm for $Percona::Toolkit::VERSION. Put that in pt-diskstats. Add util/tool-header to update %INC magic when bin/update-modules is ran.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
# This program is part of Percona Toolkit: http://www.percona.com/software/
|
# This program is part of Percona Toolkit: http://www.percona.com/software/
|
||||||
# See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal
|
# See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal
|
||||||
@@ -6,13 +6,22 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
|
||||||
|
|
||||||
# %INC magic to allow us to require/use these even within the big file.
|
# This tool is "fat-packed": most of its dependent modules are embedded
|
||||||
|
# in this file. Setting %INC to this file for each module makes Perl aware
|
||||||
|
# of this so it will not try to load the module from @INC. See the tool's
|
||||||
|
# documentation for a full list of dependencies.
|
||||||
BEGIN {
|
BEGIN {
|
||||||
$INC{$_} = __FILE__ for map {
|
$INC{$_} = __FILE__ for map { (my $pkg = "$_.pm") =~ s!::!/!g; $pkg } (qw(
|
||||||
(my $t = $_ . ".pm") =~ s!::!/!g; $t
|
OptionParser
|
||||||
} qw( OptionParser Transformers ReadKeyMini Diskstats DiskstatsGroupByAll DiskstatsGroupByDisk DiskstatsGroupBySample DiskstatsMenu pt_diskstats );
|
Transformers
|
||||||
|
ReadKeyMini
|
||||||
|
Diskstats
|
||||||
|
DiskstatsGroupByAll
|
||||||
|
DiskstatsGroupByDisk
|
||||||
|
DiskstatsGroupBySample
|
||||||
|
DiskstatsMenu
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
47
lib/Percona/Toolkit.pm
Normal file
47
lib/Percona/Toolkit.pm
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# This program is copyright 2012 Percona Inc.
|
||||||
|
# Feedback and improvements are welcome.
|
||||||
|
#
|
||||||
|
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
#
|
||||||
|
# This program 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
|
||||||
|
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
|
||||||
|
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
|
||||||
|
# licenses.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
# Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||||
|
# ###########################################################################
|
||||||
|
# Percona::Toolkit package
|
||||||
|
# ###########################################################################
|
||||||
|
{
|
||||||
|
package Percona::Toolkit;
|
||||||
|
|
||||||
|
our $VERSION = '2.1.3';
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings FATAL => 'all';
|
||||||
|
use English qw(-no_match_vars);
|
||||||
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
|
require Exporter;
|
||||||
|
our @ISA = qw(Exporter);
|
||||||
|
our %EXPORT_TAGS = ();
|
||||||
|
our @EXPORT = (qw(_d));
|
||||||
|
|
||||||
|
sub _d {
|
||||||
|
my ($package, undef, $line) = caller 0;
|
||||||
|
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||||
|
map { defined $_ ? $_ : 'undef' }
|
||||||
|
@_;
|
||||||
|
print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
# ###########################################################################
|
||||||
|
# End Percona::Toolkit package
|
||||||
|
# ###########################################################################
|
89
util/tool-header
Executable file
89
util/tool-header
Executable file
@@ -0,0 +1,89 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script prints the standard header that should be at the start
|
||||||
|
# of every Perl tool.
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Standard startup, find the branch's root directory
|
||||||
|
# ############################################################################
|
||||||
|
|
||||||
|
exit_status=0
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo $1 >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
echo $1 >&2
|
||||||
|
exit_status=$((exit_status | 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
cwd="$PWD"
|
||||||
|
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
|
||||||
|
BRANCH=$PERCONA_TOOLKIT_BRANCH
|
||||||
|
else
|
||||||
|
while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
if [ ! -f Makefile.PL ]; then
|
||||||
|
die "Cannot find the root directory of the Percona Toolkit branch"
|
||||||
|
fi
|
||||||
|
BRANCH=`pwd`
|
||||||
|
fi
|
||||||
|
cd "$cwd"
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Global variables
|
||||||
|
# ############################################################################
|
||||||
|
|
||||||
|
EXIT_STATUS=0
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Subroutines
|
||||||
|
# ############################################################################
|
||||||
|
|
||||||
|
# None
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Script starts here
|
||||||
|
# ############################################################################
|
||||||
|
|
||||||
|
tool_file=$1
|
||||||
|
|
||||||
|
if [ -z "$tool_file" ]; then
|
||||||
|
die "Usage: $0 TOOL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f $tool_file ]; then
|
||||||
|
die "$tool_file does not exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -m 1 -q '^use ' $tool_file; then
|
||||||
|
die "This only works for Perl tools"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "#!/usr/bin/env perl
|
||||||
|
|
||||||
|
# This program is part of Percona Toolkit: http://www.percona.com/software/
|
||||||
|
# See \"COPYRIGHT, LICENSE, AND WARRANTY\" at the end of this file for legal
|
||||||
|
# notices and disclaimers.
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings FATAL => 'all';
|
||||||
|
|
||||||
|
# This tool is \"fat-packed\": most of its dependent modules are embedded
|
||||||
|
# in this file. Setting %INC to this file for each module makes Perl aware
|
||||||
|
# of this so it will not try to load the module from @INC. See the tool's
|
||||||
|
# documentation for a full list of dependencies.
|
||||||
|
BEGIN {
|
||||||
|
\$INC{\$_} = __FILE__ for map { (my \$pkg = \"\$_.pm\") =~ s!::!/!g; \$pkg } (qw("
|
||||||
|
|
||||||
|
for pkg in $(grep '^package [A-Za-z:]*;' $tool_file | cut -d' ' -f2 | cut -d';' -f1); do
|
||||||
|
echo " $pkg"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " ));
|
||||||
|
}";
|
||||||
|
|
||||||
|
exit $EXIT_STATUS
|
@@ -4,7 +4,7 @@
|
|||||||
# Standard startup, find the branch's root directory
|
# Standard startup, find the branch's root directory
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
exit_status=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
echo $1 >&2
|
echo $1 >&2
|
||||||
@@ -13,7 +13,7 @@ die() {
|
|||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
echo $1 >&2
|
echo $1 >&2
|
||||||
exit_status=$((exit_status | 1))
|
EXIT_STATUS=$((EXIT_STATUS | 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd="$PWD"
|
cwd="$PWD"
|
||||||
@@ -34,25 +34,16 @@ cd "$cwd"
|
|||||||
# Global variables
|
# Global variables
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
CHECK=${CHECK:-1}
|
# None
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Subroutines
|
# Subroutines
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
file_is_modified() {
|
|
||||||
local file=$1
|
|
||||||
if [ $CHECK -eq 1 ]; then
|
|
||||||
bzr status $file | grep -q modified
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgs_in_tool() {
|
pkgs_in_tool() {
|
||||||
local tool=$1
|
local tool=$1
|
||||||
if [ "$tool_lang" = "perl" ]; then
|
if [ "$tool_lang" = "perl" ]; then
|
||||||
pkgs=$(grep '^package [A-Za-z]*;' $tool | cut -d' ' -f2 | cut -d';' -f1)
|
pkgs=$(grep '^package [A-Za-z:]*;' $tool | cut -d' ' -f2 | cut -d';' -f1)
|
||||||
else
|
else
|
||||||
pkgs=$(grep '^# [a-z_]* package' $tool | awk '{print $2}')
|
pkgs=$(grep '^# [a-z_]* package' $tool | awk '{print $2}')
|
||||||
fi
|
fi
|
||||||
@@ -82,8 +73,8 @@ replace_pkg_in_tool() {
|
|||||||
echo "# $pkg package
|
echo "# $pkg package
|
||||||
# This package is a copy without comments from the original. The original
|
# This package is a copy without comments from the original. The original
|
||||||
# with comments and its test file can be found in the Bazaar repository at,
|
# with comments and its test file can be found in the Bazaar repository at,
|
||||||
# lib/$pkg.pm
|
# lib/$pkg_file_base.pm
|
||||||
# t/lib/$pkg.t
|
# t/lib/$pkg_file_base.t
|
||||||
# See https://launchpad.net/percona-toolkit for more information.
|
# See https://launchpad.net/percona-toolkit for more information.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
{" >> $tmp_file
|
{" >> $tmp_file
|
||||||
@@ -112,6 +103,25 @@ echo "# ########################################################################
|
|||||||
mv $tmp_file $tool_file
|
mv $tmp_file $tool_file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_tool_header() {
|
||||||
|
local tool_file=$1
|
||||||
|
|
||||||
|
local start_line=$(grep -m 1 -n "^# ###" $tool_file | cut -d':' -f1)
|
||||||
|
if [ -z "$start_line" ]; then
|
||||||
|
warn "$tool_file does not have a package header line"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
start_line=$((start_line - 1))
|
||||||
|
|
||||||
|
tail -n +$start_line $tool_file > $tool_file-code
|
||||||
|
$BRANCH/util/tool-header $tool_file > $tool_file-header
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
warn "Failed to update tool header for $tool_file"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
cat $tool_file-header $tool_file-code > $tool_file
|
||||||
|
}
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Script starts here
|
# Script starts here
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
@@ -119,7 +129,7 @@ echo "# ########################################################################
|
|||||||
tool_file=$1
|
tool_file=$1
|
||||||
|
|
||||||
if [ -z "$tool_file" ]; then
|
if [ -z "$tool_file" ]; then
|
||||||
die "Usage: $0 TOOL [MODULE...]"
|
die "Usage: $0 TOOL [MODULES]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f $tool_file ]; then
|
if [ ! -f $tool_file ]; then
|
||||||
@@ -150,7 +160,10 @@ for pkg in $pkgs; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$tool_lang" = "perl" ]; then
|
if [ "$tool_lang" = "perl" ]; then
|
||||||
|
# Perl :: package separators translate to directory slashes.
|
||||||
pkg_file="$BRANCH/lib/$pkg.pm"
|
pkg_file="$BRANCH/lib/$pkg.pm"
|
||||||
|
pkg_file=${pkg_file//"::"/"/"}
|
||||||
|
pkg_file_base=${pkg//"::"/"/"}
|
||||||
else
|
else
|
||||||
pkg_file="$BRANCH/lib/bash/$pkg.sh"
|
pkg_file="$BRANCH/lib/bash/$pkg.sh"
|
||||||
fi
|
fi
|
||||||
@@ -160,11 +173,6 @@ for pkg in $pkgs; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if file_is_modified $pkg_file; then
|
|
||||||
# warn "$pkg_file has uncommitted changes"
|
|
||||||
# continue
|
|
||||||
# fi
|
|
||||||
|
|
||||||
replace_pkg_in_tool $tmp_tool_file
|
replace_pkg_in_tool $tmp_tool_file
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Updated $pkg"
|
echo "Updated $pkg"
|
||||||
@@ -172,14 +180,19 @@ for pkg in $pkgs; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $pkgs_updated -ne 0 ]; then
|
if [ $pkgs_updated -gt 0 ]; then
|
||||||
cp $tmp_tool_file $tool_file
|
update_tool_header $tmp_tool_file
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
warn "Failed to copy $tmp_tool_file to $tool_file"
|
warn "Failed to update tool header"
|
||||||
else
|
else
|
||||||
rm $tmp_tool_file > /dev/null
|
cp $tmp_tool_file $tool_file
|
||||||
exit_status=$((exit_status | $?))
|
if [ $? -ne 0 ]; then
|
||||||
|
warn "Failed to copy $tmp_tool_file to $tool_file"
|
||||||
|
else
|
||||||
|
rm $tmp_tool_file > /dev/null
|
||||||
|
EXIT_STATUS=$((EXIT_STATUS | $?))
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit $exit_status
|
exit $EXIT_STATUS
|
||||||
|
Reference in New Issue
Block a user