[siesta-commit] siesta/bin nacho,1.1,1.2

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

From: muttley
Subject: [siesta-commit] siesta/bin nacho,1.1,1.2
Date: 17:14 on 05 Sep 2002
Update of /cvsroot/siesta/siesta/bin
In directory usw-pr-cvs1:/tmp/cvs-serv2325/bin

Modified Files:
	nacho 
Log Message:
Fix it to make it work with the new config stuff.


Index: nacho
===================================================================
RCS file: /cvsroot/siesta/siesta/bin/nacho,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- nacho	28 Aug 2002 16:03:20 -0000	1.1
+++ nacho	5 Sep 2002 16:13:58 -0000	1.2
@@ -1,16 +1,17 @@
 #!/usr/bin/perl -w
 
 use strict;
+use Siesta;
+use Siesta::Config;
+use Siesta::List;
 use Siesta::User;
-use Siesta::Storage::Table::Lists;
-use Siesta::Storage::Table::Users;
-use Siesta::Storage::DBI;
 use Data::Dumper;
 
 # All possible modes that we can do
 my @modes = qw(show-lists new-list delete-list 
 	       show-users new-user delete-user
-	       show-users-list show-lists-user);
+	       show-users-list show-lists-user
+	    );
  
 # not enough arguments
 die usage()."\n" unless @ARGV;
@@ -28,7 +29,8 @@
 $mode =~ tr/-/_/; 
 
 
-my $store = new Siesta::Storage::DBI ("","");
+# Connect
+Siesta->connect(DBI => "dbi:SQLite:".$Siesta::Config::DBFILE);
 
 no strict qw(refs);
 # call the appropriate subroutine
@@ -39,19 +41,37 @@
 
 exit 0;
 
+=head1 COMMANDS
+
+The following commands are valid
+
+=cut
+
+=head2 show-lists
+
+Show all the lists that are in the system,
+
+=cut
+
 # show all lists
 sub show_lists
 {
-	foreach my $list (Siesta::Storage::Table::Lists->new()->retrieve_all())
+	foreach my $list (Siesta->storage->get_lists())
 	{
         	print  $list->id()."\n";
 	}	
 }
 
+=head2 show-users
+
+Show all the users that are in the system.
+
+=cut 
+
 # show all users
 sub show_users
 {
-	foreach my $user (Siesta::Storage::Table::Users->new()->retrieve_all())
+	foreach my $user (Siesta->storage->get_users())
 	{
         	printf  "%s %s <%s>\n", $user->forename(), 
 					$user->surname(), 
@@ -60,18 +80,23 @@
 
 }
 
+
+=head2 show-users-list [list-id]
+
+show all the users of the list 'list-id'
+
+=cut
+
 # show all the users in a list
 sub show_users_list
 {
 	my $list_id = shift || die "You must pass a list id to show_users_list\n";
-	my $list    = $store->load_list($list_id) || die "Invalid list id\n";
+	my $list    = Siesta->storage->load_list($list_id) || die "Invalid list id\n";
 
 	print "\nThe list $list_id has the following members : \n";
 	print "----\n";
-	foreach my $list_user ($store->list_members($list_id))
+	foreach my $user (Siesta->storage->list_members($list_id))
         {
-		my $user = new Siesta::User($list_user->user_id());
-
                 printf  "%s %s <%s>\n", $user->forename(), 
 					$user->surname(), 
 					$user->id();
@@ -81,20 +106,62 @@
 }
 
 
+=head2 show-lists-user [user-id]
+
+Show all the lists that the user 'user-id' is on.
+
+=cut
+
 # show all lists that a user is on
 sub show_lists_user
 {
         my $user_id = shift || die "You must pass a user id to show_lists_user\n";
-        my $user    = $store->load_user($user_id) || die "Invalid user id\n";
+        my $user    = Siesta->storage->load_user($user_id) || die "Invalid user id\n";
 
 	print "\nThe user $user_id is on the following lists : \n";
 	print "----\n";
-        foreach my $list (Siesta::Storage::Table::Lists->new()->retrieve_all())
+        foreach my $list (Siesta->list->users($user_id))
         {
-		print $list->id()."\n" if ($store->member_of_list($list->id(), $user_id));
+		print $list->id()."\n";
         }
+}
 
+
+=head2 new-user [email address/user id] [forename] [surname]
+
+Add a new user to the system. 
+
+=cut
+
+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 $hash = { id => $user_id, 
+		     forename => $forename,
+		     surname  => $surname,
+		   };
+
+
+	my $user = Siesta::User->new_from_hash($hash);
+	$user->save() || die "Errk : that failed to save";
+	
+	print "User $forename $surname <$user_id> added\n";
 }
+
+
+# todo :
+
+# - new list
+# - add user to list
+# - list plugins for a list
+# - list plugin config options
+# - list plugin config for a list
+# - list plugin config for a user
+
+
 
 
 sub usage



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