]> Frank Brehm's Git Trees - books.git/commitdiff
Darstellung der Sitzungen von der Konfiguration abhängig gemacht
authorFrank Brehm <frank@brehm-online.com>
Fri, 19 Dec 2008 11:45:19 +0000 (11:45 +0000)
committerFrank Brehm <frank@brehm-online.com>
Fri, 19 Dec 2008 11:45:19 +0000 (11:45 +0000)
bin/show_sessions.pl
frbr_books.yml

index 8ce84103e2f6363075a0b1cea7080f4813f50c5a..5e1e3411ba748ba3ab6921d2e0aeb07e6f5cd13e 100755 (executable)
@@ -14,6 +14,9 @@ use FrBr::Books::Db;
 use MIME::Base64 ();
 use Storable;
 use Data::Dumper;
+use Hash::Merge;
+use YAML;
+use Cwd qw( abs_path );
 
 $Data::Dumper::Indent   = 1;
 $Data::Dumper::Sortkeys = 1;
@@ -21,16 +24,24 @@ $Data::Dumper::Sortkeys = 1;
 my $db  = 'books';
 my $title = "Sitzungsdaten:";
 
-my $dsn = 'DBI:mysql:database=' . $db . ';host=localhost';
-my $user = 'books';
-my $password = 'uhu';
 my $attrs    = {
     'AutoCommit' => 1,
     'PrintError' => 0,
     'RaiseError' => 0,
 };
 
-my $schema = FrBr::Books::Db->connect( $dsn, $user, $password, $attrs );
+my $dbconf = {
+    'host'  => 'localhost',
+    'port'  => 3306,
+    'db'    => 'books',
+    'user'  => 'books',
+    'pwd'   => 'uhu',
+};
+config();
+
+my $dsn = sprintf( 'DBI:mysql:database=%s;host=%s%s', $dbconf->{'db'}, $dbconf->{'host'}, $dbconf->{'port'} == 3306 ? '' : ( ';port=' . $dbconf->{'port'} ) );
+
+my $schema = FrBr::Books::Db->connect( $dsn, $dbconf->{'user'}, $dbconf->{'pwd'}, $attrs );
 
 my @all_items = $schema->resultset('Session')->search( undef, {
                 'columns' => [ qw/
@@ -58,6 +69,58 @@ for ( @all_items ) {
 
 exit 0;
 
+#--------------------------------------------------------------------------------
+
+sub config {
+
+    my $conf_file_normal = abs_path( $FindBin::Bin . "/../frbr_books.yml" );
+    my $conf_file_local  = abs_path( $FindBin::Bin . "/../frbr_books_local.yml" );
+
+    my $cnf_normal = read_yml($conf_file_normal);
+    my $cnf_local  = read_yml($conf_file_local);
+
+    unless ( $cnf_normal ) {
+        common_notice( "Konfiguraionsdatei '" . $conf_file_normal . "' konnte nicht gelesen werden." );
+        exit 66;
+    }
+
+    my $conf;
+    if ( $cnf_local ) {
+        Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
+        $conf = Hash::Merge::merge( $cnf_normal, $cnf_local );
+    }
+    else {
+        $conf = $cnf_normal;
+    }
+
+    $dbconf->{'host'} = $conf->{'database'}{'host'} if $conf->{'database'}{'host'};
+    $dbconf->{'port'} = to_int( $conf->{'database'}{'port'} ) if $conf->{'database'}{'port'} and to_int( $conf->{'database'}{'port'} );
+    $dbconf->{'db'}   = $conf->{'database'}{'schema'} if $conf->{'database'}{'schema'};
+    $dbconf->{'user'} = $conf->{'database'}{'user'} if $conf->{'database'}{'user'};
+    $dbconf->{'pwd'}  = $conf->{'database'}{'passwd'} if $conf->{'database'}{'passwd'};
+
+}
+
+#--------------------------------------------------------------------------------
+
+sub read_yml {
+
+    my $file = shift;
+
+    return undef unless -f $file;
+
+    my $cnf = undef;
+    eval {
+        $cnf = YAML::LoadFile($file);
+    };
+    if ( $@ ) {
+        common_notice( "Fehler beim Lesen der YAML-Datei '" . $file . "': ", $@ );
+    }
+
+    return $cnf;
+
+}
+
 __END__
 
 # vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
index f1c2a71100db5dbbbb162c903e0f290749234b4c..bbac7a1a113f138f3568c2085f27d41ae94dd069 100644 (file)
@@ -12,7 +12,7 @@ log_level:      info
 colored_log:    0
 #
 # Standard-Listenlaenge
-default_list_length:    10
+default_list_length:    20
 #
 # Sitzungsparameter
 session: