From 5bd2ef552465d127a535351e51bf9a1f889e23b0 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 29 Jul 2009 08:48:03 +0000 Subject: [PATCH] added .biopiecesrc git-svn-id: http://biopieces.googlecode.com/svn/trunk@612 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/list_mysql_databases | 4 ++-- bp_bin/read_mysql | 14 +++++++------- bp_bin/remove_mysql_tables | 15 +++++++++------ bp_bin/write_mysql | 4 ++-- code_perl/Maasha/Biopieces.pm | 30 ++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/bp_bin/list_mysql_databases b/bp_bin/list_mysql_databases index 040e7ab..45587d8 100755 --- a/bp_bin/list_mysql_databases +++ b/bp_bin/list_mysql_databases @@ -38,8 +38,8 @@ use Maasha::SQL; my ( $options, $user, $password, @databases, $database ); -$user = $ENV{ "USER" }; -$password = $ENV{ "USER" }; +$user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" ); +$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" ); $options = Maasha::Biopieces::parse_options( [ diff --git a/bp_bin/read_mysql b/bp_bin/read_mysql index ff96a81..2d8f7b1 100755 --- a/bp_bin/read_mysql +++ b/bp_bin/read_mysql @@ -36,17 +36,17 @@ use Maasha::UCSC; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $default_user, $default_password, $options, $in, $out, $record, $dbh, $results ); +my ( $user, $password, $options, $in, $out, $record, $dbh, $results ); -$default_user = Maasha::UCSC::ucsc_get_user(); -$default_password = Maasha::UCSC::ucsc_get_password(); +$user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" ); +$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" ); $options = Maasha::Biopieces::parse_options( [ - { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'query', short => 'q', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $default_user, allowed => undef, disallowed => undef }, - { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => $default_password, allowed => undef, disallowed => undef }, + { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'query', short => 'q', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $user, allowed => undef, disallowed => undef }, + { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => $password, allowed => undef, disallowed => undef }, ] ); diff --git a/bp_bin/remove_mysql_tables b/bp_bin/remove_mysql_tables index 1419cbc..794ab0f 100755 --- a/bp_bin/remove_mysql_tables +++ b/bp_bin/remove_mysql_tables @@ -37,15 +37,18 @@ use Maasha::UCSC; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, %table_hash, $dbh, $table ); +my ( $options, $user, $password, $in, $out, $record, %table_hash, $dbh, $table ); + +$user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" ); +$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" ); $options = Maasha::Biopieces::parse_options( [ - { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'tables', short => 't', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'tables', short => 't', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'keys', short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $user, allowed => undef, disallowed => undef }, + { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => $password, allowed => undef, disallowed => undef }, ] ); diff --git a/bp_bin/write_mysql b/bp_bin/write_mysql index 1a783bf..aa2c5a4 100755 --- a/bp_bin/write_mysql +++ b/bp_bin/write_mysql @@ -39,8 +39,8 @@ use Maasha::Calc; my ( $options, $user, $password, $dbh, $in, $out, $tmp_dir, $tmp_file, $fh_out, $record, $key, $type_hash, $i, @keys, $line ); -$user = $ENV{ "USER" }; -$password = $ENV{ "USER" }; +$user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" ); +$password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" ); $options = Maasha::Biopieces::parse_options( [ diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 20e1083..d9af0f1 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -846,6 +846,36 @@ sub get_tmpdir } +sub biopiecesrc +{ + # Martin A. Hansen, July 2009. + + # Read Biopiece configuration info from .biopiecesrc. + # and returns the value of a given key. + + my ( $key, # configuration key + ) = @_; + + # Returns a string. + + my ( $file, $fh, $record ); + + $file = "$ENV{ 'HOME' }/.biopiecesrc"; + + return undef if not -f $file; + + $fh = Maasha::Filesys::file_read_open( $file ); + $record = get_record( $fh ); + close $fh; + + if ( exists $record->{ $key } ) { + return $record->{ $key }; + } else { + return undef; + } +} + + END { clean_tmp(); -- 2.39.5