[prev] [thread] [next] [lurker] [Date index for 2002/09/12]
Update of /cvsroot/siesta/siesta/bin In directory usw-pr-cvs1:/tmp/cvs-serv12345/bin Modified Files: nacho Log Message: lose $DBFILE instead use @STORAGE Index: nacho =================================================================== RCS file: /cvsroot/siesta/siesta/bin/nacho,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- nacho 12 Sep 2002 12:55:31 -0000 1.16 +++ nacho 12 Sep 2002 14:10:10 -0000 1.17 @@ -34,16 +34,16 @@ # what are we doing? my $mode = shift @ARGV; -my $db = $Siesta::Config::DBFILE; +my @storage = @Siesta::Config::STORAGE; if ($mode eq '-d') { - $db = shift; - $mode = shift; + @storage = split /\s/, shift; + $mode = shift; } # I know that grep is bad for this thing but ... -# die if this isn't a valid mode -die usage() . "\n" unless grep { /^$mode$/ } @modes; +# die if this isn't a valid mode +die usage() . "\n" unless grep { $_ eq $mode } @modes; # h-h-h-ack # due to syntax rules minues signs aren't @@ -51,8 +51,7 @@ $mode =~ tr/-/_/; # Connect -_connect_database($db); -#Siesta->connect( DBI => "dbi:SQLite:" . $Siesta::Config::DBFILE ); +_connect_database(@storage); no strict qw(refs); @@ -71,37 +70,30 @@ You can optionally pass a database to act on (the default is the one defined in Siesta::Config). By doing - -d [ database ] + -d [ database ] The following commands are then valid =cut -=head2 create-database [ database ] +=head2 create-database -Initialise a new database at the supplied location. +Initialise a new database at the supplied location. Not passing a database will reinitialise the current one. =cut -sub create_database -{ - my $db = shift || $Siesta::Config::DBFILE; - if (-f $db) { - unlink($db) || die "Failed to remove existing file\n"; - print "Removed existing file\n"; - } - _connect_database ($db); - Siesta->storage->init_db() || die "Couldn't initialise the database\n"; - +sub create_database { + _connect_database(@storage); + Siesta->storage->init_db + or die "Couldn't initialise the database\n"; } -sub _connect_database -{ - my $db = shift || die "You must supply a new database\n"; - Siesta->connect(DBI => "dbi:SQLite:".$db) || die "Couldn't connect to the database\n"; +sub _connect_database { + Siesta->connect(@_) + or die "Couldn't connect to the database\n"; } @@ -407,12 +399,12 @@ # TODO - create new user if not valid my $user = Siesta::User->new($user_id); - unless (defined $user) { - $user = Siesta::User->new_from_hash(id=>$user_id) || die "Couldn't create a new user\n"; - $user->save(); - print "Created a new user '$user_id' - don't forget to set more details for them\n"; + unless (defined $user) { + $user = Siesta::User->new_from_hash(id=>$user_id) || die "Couldn't create a new user\n"; + $user->save(); + print "Created a new user '$user_id' - don't forget to set more details for them\n"; - } + } $list->add_member($user);
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52