Package: mytop
Version: 1.6-5
Severity: wishlist
Tags: patch

Hi,

I have attached a patch that adds support for reading the mytop config from the
standard MySQL ~/.my.cnf file. In 2007, I sent the patch to Jeremy, who replied
that he would include it in the next mytop release. When upgrading to Lenny, I 
noticed that this next release never happened.

I would be nice if the patch could be included with Debian's mytop package.

Cheers, Til
=== debian/changelog
==================================================================
--- debian/changelog    (revision 4)
+++ debian/changelog    (local)
@@ -1,3 +1,10 @@
+mytop (1.6-5.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * add handling of ~/.my.cnf
+
+ -- Tilman Koschnick <[email protected]>  Thu, 19 Mar 2009 16:54:36 +0100
+
 mytop (1.6-5) unstable; urgency=low
 
   * A newline should be replaced by a space, not just deleted (Closes: #502179)
=== debian/control
==================================================================
--- debian/control      (revision 4)
+++ debian/control      (local)
@@ -4,12 +4,12 @@
 Maintainer: Philipp Matthias Hahn <[email protected]>
 Standards-Version: 3.8.0
 Build-Depends: quilt
-Build-Depends-Indep: perl (>= 5.6.0-16), libdbi-perl (>= 1.13), 
libdbd-mysql-perl (>= 1.0), libterm-readkey-perl (>=2.10)
+Build-Depends-Indep: perl (>= 5.6.0-16), libdbi-perl (>= 1.13), 
libdbd-mysql-perl (>= 1.0), libterm-readkey-perl (>=2.10), 
libconfig-inifiles-perl
 Homepage: http://jeremy.zawodny.com/mysql/mytop/
 
 Package: mytop
 Architecture: all
-Depends: perl (>= 5.6.0-16), libdbi-perl (>= 1.13), libdbd-mysql-perl (>= 
1.0), libterm-readkey-perl (>=2.10)
+Depends: perl (>= 5.6.0-16), libdbi-perl (>= 1.13), libdbd-mysql-perl (>= 
1.0), libterm-readkey-perl (>=2.10), libconfig-inifiles-perl
 Suggests: libtime-hires-perl
 Description: top like query monitor for MySQL
  Mytop is a console-based tool for monitoring queries and the performance
=== debian/patches/series
==================================================================
--- debian/patches/series       (revision 4)
+++ debian/patches/series       (local)
@@ -6,3 +6,4 @@
 475140.flicker.diff
 477822.escape.diff
 q_is_quit.diff
+my.cnf.diff
=== debian/patches/my.cnf.diff
==================================================================
--- debian/patches/my.cnf.diff  (revision 4)
+++ debian/patches/my.cnf.diff  (local)
@@ -0,0 +1,106 @@
+--- mytop-1.6.orig/mytop
++++ mytop-1.6/mytop
+@@ -17,6 +17,7 @@
+ use 5.005;
+ use strict;
+ use DBI;
++use Config::IniFiles;
+ use Getopt::Long;
+ use Socket;
+ 
+@@ -77,6 +78,7 @@
+     batchmode     => 0,
+     color         => 1,
+     db            => '',
++    database      => '',
+     delay         => 5,
+     filter_user   => qr/.?/,
+     filter_db     => qr/.?/,
+@@ -89,6 +91,7 @@
+     mode          => 'top',
+     prompt        => 0,
+     pass          => '',
++    password      => '',
+     port          => 3306,
+     resolve       => 1,
+     socket        => '',
+@@ -117,6 +120,26 @@
+ my $RM_RESET   = 0;
+ my $RM_NOBLKRD = 3; ## using 4 traps Ctrl-C :-(
+ 
++## Try ~/.my.cnf first
++
++my $mycnf = "$ENV{HOME}/.my.cnf";
++
++if (-e $mycnf)
++{
++      my $cfgini = new Config::IniFiles( -file => $mycnf );
++      my @sections = ('client', 'mytop');
++
++      foreach my $section (@sections) {
++              foreach my $param ($cfgini->Parameters ($section))
++              {
++                      $config{$param} = $cfgini->val($section, $param) if 
exists $config{$param};
++              }
++      }
++      ## map database/password onto db/pass (long version gets precedence in 
.my.cnf)
++      $config{'db'} = $config{'database'} if $config{'database'};
++      $config{'pass'} = $config{'password'} if $config{'password'};
++}
++
+ ## Read the user's config file, if it exists.
+ 
+ my $config = "$ENV{HOME}/.mytop";
+@@ -139,6 +162,9 @@
+         }
+         close CFG;
+     }
++      ## map database/password onto db/pass (short version gets precedence 
for historical reasons)
++      $config{'db'} = $config{'database'} unless $config{'db'};
++      $config{'pass'} = $config{'password'} unless $config{'pass'};
+ }
+ 
+ ## Command-line args.
+@@ -257,8 +283,8 @@
+   * port you specified "$config{port}" (default is 3306)
+   * socket you specified "$config{socket}" (default is "")
+ 
+-The options my be specified on the command-line or in a ~/.mytop
+-config file. See the manual (perldoc mytop) for details.
++The options my be specified on the command-line or in a ~/.mytop or
++~/.my.cnf config file. See the manual (perldoc mytop) for details.
+ 
+ Here's the exact error from DBI. It might help you debug:
+ 
+@@ -1564,6 +1590,7 @@
+ following:
+ 
+   * Perl 5.005 or newer
++  * Config::IniFiles;
+   * Getopt::Long
+   * DBI and DBD::mysql
+   * Term::ReadKey from CPAN
+@@ -1844,6 +1871,13 @@
+ You may have white space on either side of the C<=> in lines of the
+ config file.
+ 
++If present, mytop will also read mysql's default config file C<~/.my.cnf>.
++Values from both the [client] and [mytop] section are read, in this order.
++The long options I<database> and I<password> are preferred over the short
++versions I<db> and I<pass> to match mysql's syntax.
++These settings take lowest precedence and will be overwritten by either
++values in C<~/.mytop> or command-line options.
++
+ =head2 Shortcut Keys
+ 
+ The following keys perform various actions while B<mytop> is
+@@ -1970,9 +2004,6 @@
+ may appear odd. I have no good idea as to how best to deal with that
+ yet. Suggestions are welcome.
+ 
+-It'd be nice if you could just add B<mytop> configuration directives
+-in your C<my.cnf> file instead of having a separate config file.
+-
+ You should be able to specify the columns you'd like to see in the
+ display and the order in which they appear. If you only have one
+ username that connects to your database, it's probably not worth

Reply via email to