[927] in BarnOwl Developers

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

[D-O-H] r914 - 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:18:14 -0500 (EST)

Author: nelhage
Date: 2008-02-01 02:18:14 -0500 (Fri, 01 Feb 2008)
New Revision: 914

Modified:
   branches/barnowl_sqlite/owl/createdb.pl
   branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm
Log:
Accept database


Modified: branches/barnowl_sqlite/owl/createdb.pl
===================================================================
--- branches/barnowl_sqlite/owl/createdb.pl	2008-02-01 07:17:40 UTC (rev 913)
+++ branches/barnowl_sqlite/owl/createdb.pl	2008-02-01 07:18:14 UTC (rev 914)
@@ -49,6 +49,7 @@
            })
         ],
     'index'       => DBIx::DBSchema::ColGroup::Index->new([
+        [qw(expunged)]
         ]),
    });
 
@@ -82,10 +83,26 @@
 
 my $schema = DBIx::DBSchema->new($messages, $attrs);
 
-my $dsn = shift || "DBI:SQLite:dbname=$ENV{HOME}/.owl/messagedb";
-my $user = shift || undef;
-my $pass = shift || undef;
+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;
+    }
+    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");
+    my $dsn = "dbi:$driver:" .
+       join(';', map { $_ ."=".$conf{$_} } grep { defined $conf{$_} } keys %conf);
+    return ($dsn, $user, $pass);
+}
 
+my ($dsn, $user, $pass) = load_dbconfig();
+
 my $dbh = DBI->connect($dsn, $user, $pass, {RaiseError => 1, AutoCommit => 0});
 my @sql = $schema->sql($dbh);
 

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:17:40 UTC (rev 913)
+++ branches/barnowl_sqlite/owl/perl/lib/BarnOwl/MessageList/SQL.pm	2008-02-01 07:18:14 UTC (rev 914)
@@ -31,10 +31,29 @@
 __PACKAGE__->mk_ro_accessors(qw(db cache));
 __PACKAGE__->mk_accessors(qw(msg_iter attr_iter attr_lookahead _next_id deleted));
 
+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;
+    }
+    close($fh);
+    my $driver = delete $conf{driver} || 'SQLite';
+    my $user = delete $conf{user};
+    my $pass = delete $conf{password};
+    $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);
+}
+
 sub new {
     my $class = shift;
-    my $db = DBIx::Simple->new("DBI:SQLite:dbname=$ENV{HOME}/.owl/messagedb",
-                               "", "",
+    my ($dsn, $user, $pass) = load_dbconfig();
+    my $db = DBIx::Simple->new($dsn, $user, $pass,
                              {RaiseError => 1, AutoCommit => 1});
     my $cache = Cache::Memory->new(default_expires => '30 sec');
     my $self = {db => $db, cache => $cache, deleted => {}};


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