Hi,

Looking a bit more closely at the package, I found that the bug was due
to a patch that was applied in the Debian package (attached):
----
/src/mytop-1.6$ head -n12 debian/patches/520421.my.cnf.diff
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.
--- 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;
----

I would remove this "feature" as it is obviously not finished yet. The
other solution would be to test/include your patch to this already
existing patch.

Philipp, if you need any help packaging it, I would be glad to give you
a hand. ;)

Cheers,
 Ignace M
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.
--- 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