[928] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r915 - in branches/barnowl_sqlite/owl: . perl/lib/BarnOwl/MessageList

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:11:13 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@MIT.EDU
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Fri,  1 Feb 2008 02:24:20 -0500 (EST)

Author: nelhage
Date: 2008-02-01 02:24:19 -0500 (Fri, 01 Feb 2008)
New Revision: 915

Modified:
   branches/barnowl_sqlite/owl/createdb.pl
   branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm
Log:
Err, last commit was accidental.
Accept database configuration in ~/.owl/sql. Still default to sqlite
in ~/.owl/messagedb if no configuration present.


Modified: branches/barnowl_sqlite/owl/createdb.pl
===================================================================
--- branches/barnowl_sqlite/owl/createdb.pl	2008-02-01 07:18:14 UTC (rev 914)
+++ branches/barnowl_sqlite/owl/createdb.pl	2008-02-01 07:24:19 UTC (rev 915)
@@ -83,19 +83,24 @@
 
 my $schema = DBIx::DBSchema->new($messages, $attrs);
 
+# Hack to allow load_dbconfig to be shared with BarnOwl::MessageList::SQL
+sub BarnOwl::get_config_dir() {$ENV{HOME} . "/.owl/";}
+
 sub load_dbconfig {
     my %conf = ();
-    open(my $fh, "<", "$ENV{HOME}/.owl/sql") or die("Unable to read $ENV{HOME}/.owl/sql: $!");
-    while(my $line = <$fh>) {
-        chomp($line);
-        my ($k, $v) = split(/\s*:\s*/, $line, 2);
-        $conf{$k} = $v;
+    my $confpath = BarnOwl::get_config_dir() . "/sql";
+    if (open( my $fh, "<", $confpath )) {
+        while ( my $line = <$fh> ) {
+            chomp($line);
+            my ( $k, $v ) = split( /\s*:\s*/, $line, 2 );
+            $conf{$k} = $v;
+        }
+        close($fh);
     }
-    close($fh);
     my $driver = delete $conf{driver} || 'SQLite';
     my $user = delete $conf{user};
     my $pass = delete $conf{password};
-    $conf{dbname} ||= ($conf{database} || "$ENV{HOME}/.owl/messagedb");
+    $conf{dbname} ||= ($conf{database} || (BarnOwl::get_config_dir() . "/messagedb"));
     my $dsn = "dbi:$driver:" .
        join(';', map { $_ ."=".$conf{$_} } grep { defined $conf{$_} } keys %conf);
     return ($dsn, $user, $pass);

Modified: branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm	2008-02-01 07:18:14 UTC (rev 914)
+++ branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm	2008-02-01 07:24:19 UTC (rev 915)
@@ -34,13 +34,14 @@
 sub load_dbconfig {
     my %conf = ();
     my $confpath = BarnOwl::get_config_dir() . "/sql";
-    open(my $fh, "<", $confpath) or die("Unable to read $confpath: $!");
-    while(my $line = <$fh>) {
-        chomp($line);
-        my ($k, $v) = split(/\s*:\s*/, $line, 2);
-        $conf{$k} = $v;
+    if (open( my $fh, "<", $confpath )) {
+        while ( my $line = <$fh> ) {
+            chomp($line);
+            my ( $k, $v ) = split( /\s*:\s*/, $line, 2 );
+            $conf{$k} = $v;
+        }
+        close($fh);
     }
-    close($fh);
     my $driver = delete $conf{driver} || 'SQLite';
     my $user = delete $conf{user};
     my $pass = delete $conf{password};


home help back first fref pref prev next nref lref last post