[AudioLink-cvs]audiolink/code audiolink,1.3,1.4
Status: Alpha
Brought to you by:
amitshah
|
From: <ami...@us...> - 2003-12-05 12:20:52
|
Update of /cvsroot/audiolink/audiolink/code
In directory sc8-pr-cvs1:/tmp/cvs-serv3914
Modified Files:
audiolink
Log Message:
1. clean up the printed statements.
2. added a verbose mode
3. config file isn't perl code now; simple "a = b" stuff
4. default to localhost for the host field
5. command-line args override config file options
Index: audiolink
===================================================================
RCS file: /cvsroot/audiolink/audiolink/code/audiolink,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** audiolink 4 Dec 2003 16:20:17 -0000 1.3
--- audiolink 5 Dec 2003 12:20:49 -0000 1.4
***************
*** 26,43 ****
-
- # Currently, we'll do the database setting up and the config file
- # setting up here. Eventually, move this to alconf and aldbconf.
-
- # First, detect if there's a config file in the home dir.
-
-
use DBI;
use Getopt::Long;
# Options for the database
$user = undef;
$password = undef;
! $host = "localhost"; # use local mysql server by default
--- 26,37 ----
use DBI;
use Getopt::Long;
+ use Pod::Usage;
# Options for the database
$user = undef;
$password = undef;
! $host = undef;
***************
*** 54,78 ****
sub ask_for_configfile_and_input {
! print STDERR "
You haven't specified the " . $_[0] . " field for the database. The
easiest way of doing this is by storing it in the AudioLink
configuration file. Would you like to do that now? [Yes/no] ";
! chomp($input = <STDIN>);
! unless ($input) {
! $input = "yes";
! }
! unless ($input =~ /yes/i) {
! print "\n\tQuitting now. See the audiolink(1) man page for
more information on the mandatory input information needed,
the config file and alternate ways of specifying the
information.\n";
! # This is bad... don't quit from a subroutine!
! close CONFFILE;
! exit -1;
}
--- 48,74 ----
sub ask_for_configfile_and_input {
! if ( $_[0] =~ /user/ or $_[0] =~ /password/) {
! print STDERR "
You haven't specified the " . $_[0] . " field for the database. The
easiest way of doing this is by storing it in the AudioLink
configuration file. Would you like to do that now? [Yes/no] ";
! chomp($input = <STDIN>);
! unless ($input) {
! $input = "yes";
! }
! unless ($input =~ /yes/i) {
! print "\n\tQuitting now. See the audiolink(1) man page for
more information on the mandatory input information needed,
the config file and alternate ways of specifying the
information.\n";
! # This is bad... don't quit from a subroutine!
! close CONFFILE;
! exit -1;
! }
}
***************
*** 82,86 ****
--- 78,87 ----
print STDERR "Please enter the " . $_[0] . " field for the database: ";
+ $_[0] =~ /host/ ? print "[localhost]" : 1 ;
+
chomp($input = <STDIN>);
+ if (not $input and $_[0] =~ /host/) {
+ $input = "localhost";
+ }
}
return $input;
***************
*** 92,95 ****
--- 93,97 ----
'pass=s' => \$password,
'host=s' => \$host,
+ 'verbose' => \$verbose
) or pod2usage();
***************
*** 98,121 ****
}
$config_file = "$ENV{HOME}/.audiolink/config";
! unless (do $config_file) {
! warn "WARNING: Couldn't parse the config file, $config_file: $@" if $@;
! warn "WARNING: Couldn't read the config file, $config_file: $!";
}
! open(CONFFILE, ">>", $config_file);
unless ($user) {
$user = ask_for_configfile_and_input("username");
! print CONFFILE '$user = ' . $user . ";\n";
}
unless ($password) {
$password = ask_for_configfile_and_input("password");
! print CONFFILE '$password = ' . $password . ";\n";
}
unless ($host) {
$host = ask_for_configfile_and_input("host");
! print CONFFILE '$host = ' . $host . ";\n";
}
--- 100,140 ----
}
+ # Currently, we'll do the database setting up and the config file
+ # setting up here.
+
$config_file = "$ENV{HOME}/.audiolink/config";
! # First, detect if there's a config file in the home dir.
! if (-e $config_file) {
! # If the config file already exists, open it in read-write mode;
! # don't clobber contents (+< as opposed to +>)
! open(CONFFILE, '+<', $config_file);
! } else {
! # If it doesn't exist, open it in write mode.
! open (CONFFILE, '>', $config_file);
}
! # go through the config file
! while (<CONFFILE>) {
! if (/^\s*user\s*\=+\s*(\w+)/) {
! chomp($user = $1) unless $user;
! } elsif ( /^\s*pass(word)?\s*=\s*(\w+)/) {
! chomp($password = $2) unless $password;
! } elsif ( /^\s*host\s*=\s*(\w+)/) {
! chomp($host = $1) unless $host;
! }
! }
unless ($user) {
$user = ask_for_configfile_and_input("username");
! print CONFFILE 'user = ' . $user . "\n";
}
unless ($password) {
$password = ask_for_configfile_and_input("password");
! print CONFFILE 'pass = ' . $password . "\n";
}
unless ($host) {
$host = ask_for_configfile_and_input("host");
! print CONFFILE 'host = ' . $host . "\n";
}
***************
*** 127,136 ****
AutoCommit => 1} )
or warn "\n$0: WARNING: Could not connect to the database!\
! !! This probably means that the AudioLink database is not initialized or
! !! the MySQL server you are trying to connect to is not available.
# If
! # !! you have already created the database tables, answer \"no\" below and
# !! start the MySQL server. If you're running it on your local machine,
! # !! executing \'/etc/init.d/mysql restart\' as root would suffice.\n";
$input = "";
--- 146,158 ----
AutoCommit => 1} )
or warn "\n$0: WARNING: Could not connect to the database!\
! !! This probably means that the AudioLink database is not initialized,
! !! the MySQL server you are trying to connect to is not available,
! !! or the username/password for authentication are not valid.
!
! !! If you don't see a success message below, something is wrong.\n";
# If
! # !! you have already created the database tables, answer "no" below and
# !! start the MySQL server. If you're running it on your local machine,
! # !! executing `/etc/init.d/mysql restart` as root would suffice.\n";
$input = "";
***************
*** 151,155 ****
$db_name = "aldb";
! print "\nCreating the AudioLink database...";
$ret = system("mysqladmin -u$user -p$password -h$host create $db_name 2>/tmp/audiolink.db.tmp");
--- 173,177 ----
$db_name = "aldb";
! print "\nCreating the AudioLink database..." if $verbose;
$ret = system("mysqladmin -u$user -p$password -h$host create $db_name 2>/tmp/audiolink.db.tmp");
***************
*** 163,170 ****
while (<DBOP>) {
if ( /database exists/i) {
! print "The database already exists. Moving on to creating the tables...\n";
} else {
! print "Some error occured while creating the database:\n$_\n";
! print "Ask for help on the audiolink-users\@lists.sourceforge.net mailing list.\n";
}
}
--- 185,192 ----
while (<DBOP>) {
if ( /database exists/i) {
! print "The database already exists.\n" if $verbose;
} else {
! die "\nSome error occured while creating the database:\n$_\n"
! . "Ask for help on the audiolink-users\@lists.sourceforge.net mailing list.\n";
}
}
***************
*** 172,176 ****
close DBOP;
! print "\nCreating the AudioLink tables...";
$ret = system ("mysql -u$user -p$password -h$host $db_name < /usr/share/doc/audiolink/mysql.schema 2>/tmp/audiolink.tb.tmp");
--- 194,198 ----
close DBOP;
! print "\nCreating the AudioLink tables..." if $verbose;
$ret = system ("mysql -u$user -p$password -h$host $db_name < /usr/share/doc/audiolink/mysql.schema 2>/tmp/audiolink.tb.tmp");
***************
*** 183,190 ****
while (<DBOP>) {
if ( /already exists/i) {
! print "The table already exists.\n";
} else {
! print "Some error occured while creating the table:\n$_";
! print "Ask for help on the audiolink-users\@lists.sourceforge.net mailing list.\n";
}
}
--- 205,212 ----
while (<DBOP>) {
if ( /already exists/i) {
! print "The table already exists.\n" if $verbose;
} else {
! die "\nSome error occured while creating the table:\n$_"
! . "Ask for help on the audiolink-users\@lists.sourceforge.net mailing list.\n";
}
}
***************
*** 192,196 ****
$dbh->disconnect;
! print "\n\nAudioLink is now setup. You're now ready to run the program. Take a look at the AudioLink documentation\n";
print "available via the three man pages: audiolink(1), alfilldb(1), alsearch(1)\n";
print "\nReport positive or negative feedback on the audiolink-users\@lists.sourceforge.net mailing list.\n";
--- 214,218 ----
$dbh->disconnect;
! print "\nAudioLink is setup and ready to run. Take a look at the AudioLink documentation\n";
print "available via the three man pages: audiolink(1), alfilldb(1), alsearch(1)\n";
print "\nReport positive or negative feedback on the audiolink-users\@lists.sourceforge.net mailing list.\n";
***************
*** 229,232 ****
--- 251,257 ----
L<alsearch(1)> use.
+ The options specified on the command prompt override the options
+ specified in the config file.
+
=head1 OPTIONS
***************
*** 249,252 ****
--- 274,281 ----
Username for the database
+ =item B<--verbose>
+
+ Display extra information about what's going on
+
=back
***************
*** 296,300 ****
Specifying them in the config file (the most convenient). The config
file is stored in each user's home directory in the
! F<~/.audiolink/config> location.
=back
--- 325,329 ----
Specifying them in the config file (the most convenient). The config
file is stored in each user's home directory in the
! S<F<~/.audiolink/config>> location.
=back
***************
*** 302,318 ****
=head1 CONFIGURATION FILE
! The AudioLink configuration file resides in the .audiolink/ directory
! in the user's home directory (F<~/.audiolink/config>). This config
! file is perl code; it is included in the AudioLink scripts at
! run-time. This behavior will be changed in a later version, and a
! simple-to-understand format will be used.
! The format of the current config file is such: The option which you
! want to associate with a value is prepended with a '$' sign, and the
! value with which it is to be associated follows after an '=' sign. End
! the statement with a ';'. For example, if you want to associate the
! value of 'root' to the option 'user', you will use:
! C<$user = root;>
=head1 SEE ALSO
--- 331,346 ----
=head1 CONFIGURATION FILE
! The AudioLink configuration file F<config> resides in the
! F<.audiolink/> directory in the user's home directory
! (F<$HOME/.audiolink/config>).
! The format of the current config file is pretty easy to understand:
! Just put in C<a = b> on separate lines for all the options you want the
! AudioLink scripts to use by default. Here, a is the option name, like
! user, password, host, etc., and b is the value you wish to associate
! the option with. For example, to set the username for accessing the
! database to 'root', you would put this in the config file:
! C<user = root>
=head1 SEE ALSO
|