[siesta-commit] siesta/bin make-devlist,NONE,1.1 nacho,1.14,1.15 create_db.pl,1.4,NONE create_db.sql,1.13,NONE list_example,1.3,NONE lists_example,1.2,NONE populate_db.sql,1.14,NONE

[prev] [thread] [next] [lurker] [Date index for 2002/09/12]

From: muttley
Subject: [siesta-commit] siesta/bin make-devlist,NONE,1.1 nacho,1.14,1.15 create_db.pl,1.4,NONE create_db.sql,1.13,NONE list_example,1.3,NONE lists_example,1.2,NONE populate_db.sql,1.14,NONE
Date: 12:34 on 12 Sep 2002
Update of /cvsroot/siesta/siesta/bin
In directory usw-pr-cvs1:/tmp/cvs-serv25192/bin

Modified Files:
	nacho 
Added Files:
	make-devlist 
Removed Files:
	create_db.pl create_db.sql list_example lists_example 
	populate_db.sql 
Log Message:
Get rid of redundant sql files and examples.
Added a script for initialising the dev list
Fixed some stuff in nacho.


--- NEW FILE: make-devlist ---
#!/bin/sh

NACHO='nacho'

# create the database
$NACHO create-database

# create the users
$NACHO new-user greg@xxxxxxxxx.xxxxx.xx.xx Greg McCarroll
$NACHO new-user richardc@xxxxxxxxx.xxx Richard Clamp
$NACHO new-user simon@xxxxxxxxxx.xxx Simon Wistow

# create the lists
$NACHO new-list siesta-dev    greg@xxxxxxxxx.xxxxx.xx.xx siesta-dev@xxxxxxxxx.xxx siesta-dev-bounce@xxxxxxxxx.xxx
$NACHO new-list siesta-commit richardc@xxxxxxxxx.xxx     siesta-commit@xxxxxxxxx.xxx siesta-commit-bounce@xxxxxxxxx.xxx

# add the users to the lists
$NACHO add-user-list siesta-dev    greg@xxxxxxxxx.xxxxx.xx.xx richardc@xxxxxxxxx.xxx simon@xxxxxxxxxx.xxx
$NACHO add-user-list siesta-commit richardc@xxxxxxxxx.xxx

# set the list plugins
$NACHO set-plugins siesta-dev     SubjectTag ListHeaders ReplyTo Archive Send
$NACHO set-plugins siesta-commit  SubjectTag ListHeaders Archive Send

# set the config for siesta-dev
$NACHO set-plugin-config-list ReplyTo siesta-dev munge 1



Index: nacho
===================================================================
RCS file: /cvsroot/siesta/siesta/bin/nacho,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- nacho	11 Sep 2002 15:03:46 -0000	1.14
+++ nacho	12 Sep 2002 11:34:18 -0000	1.15
@@ -9,7 +9,8 @@
 use POSIX qw/strftime/;
 
 # All possible modes that we can do
-my @modes = qw(show-lists new-list delete-list modify-list
+my @modes = qw(create-database
+  show-lists new-list delete-list modify-list
   show-users new-user delete-user modify-user
   show-list show-user create-alias
   show-users-list show-lists-user
@@ -25,7 +26,6 @@
   set-plugin-config-user
   set-plugin-config-list
   set-plugin-config-userlist
-
   );
 
 # not enough arguments
@@ -34,6 +34,13 @@
 # what are we doing?
 my $mode = shift @ARGV;
 
+my $db  = $Siesta::Config::DBFILE;
+
+if ($mode eq '-d') {
+	$db   = 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;
@@ -44,7 +51,8 @@
 $mode =~ tr/-/_/;
 
 # Connect
-Siesta->connect( DBI => "dbi:SQLite:" . $Siesta::Config::DBFILE );
+_connect_database($db);
+#Siesta->connect( DBI => "dbi:SQLite:" . $Siesta::Config::DBFILE );
 
 no strict qw(refs);
 
@@ -56,12 +64,47 @@
 
 exit 0;
 
+
+
 =head1 COMMANDS
 
-The following commands are valid
+You can optionally pass a database to act on (the default is the 
+one defined in Siesta::Config). By doing 
+
+	-d [ database ] 
+
+The following commands are then valid
+
+=cut
+
+=head2 create-database [ database ]
+
+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 _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";
+}
+
+
 =head2 show-lists
 
 Show all the lists that are in the system,
@@ -135,14 +178,14 @@
 sub new_user {
     my $user_id = shift
       || die "You need to pass an email address as a user id\n";
-    my $forename = shift || die "You need to pass a forename\n";
-    my $surname  = shift || die "You need to pass a surname\n";
+    my $forename = shift || '';
+    my $surname  = shift || '';
 
-    my %hash = {
+    my %hash = (
                  id       => $user_id,
                  forename => $forename,
                  surname  => $surname,
-                 };
+                 );
 
     my $user = Siesta::User->new_from_hash(%hash);
     $user->save() || die "Errk : that failed to save";
@@ -217,7 +260,7 @@
     print "Property '$key' set to '$value' for the user $user_id\n";
 }
 
-=head2 add-list [list id] [list owner] [post address] [return path]
+=head2 new-list [list id] [list owner] [post address] [return path]
 
 'list id' is the name of the list, 'list owner' is the administrator of the list,
 'post address' is the email address that users send mail to post to the list and 
@@ -789,7 +832,7 @@
 sub usage {
     ( my $name = $0 ) =~ s!^.*[\\/]!!;
 
-    return join '', "Usage: $name ", join ( " ", map { "[$_]" } @modes ),
+    return join '', "Usage: $name <-d database>", join ( " ", map { "[$_]" } @modes ),
       "\nSee the $name manpage for more details";
 
 }

--- create_db.pl DELETED ---

--- create_db.sql DELETED ---

--- list_example DELETED ---

--- lists_example DELETED ---

--- populate_db.sql DELETED ---



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52