[siesta-commit] siesta/bin nacho,1.3,1.4

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

From: muttley
Subject: [siesta-commit] siesta/bin nacho,1.3,1.4
Date: 11:20 on 06 Sep 2002
Update of /cvsroot/siesta/siesta/bin
In directory usw-pr-cvs1:/tmp/cvs-serv28529/bin

Modified Files:
	nacho 
Log Message:
lots and lots more functionality


Index: nacho
===================================================================
RCS file: /cvsroot/siesta/siesta/bin/nacho,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- nacho	5 Sep 2002 16:21:23 -0000	1.3
+++ nacho	6 Sep 2002 10:20:42 -0000	1.4
@@ -6,11 +6,15 @@
 use Siesta::List;
 use Siesta::User;
 use Data::Dumper;
+use POSIX qw/strftime/;
 
 # All possible modes that we can do
-my @modes = qw(show-lists new-list delete-list 
-	       show-users new-user delete-user
+my @modes = qw(show-lists new-list delete-list modify-list
+	       show-users new-user delete-user modify-user
+	       create-alias
 	       show-users-list show-lists-user
+	       add-user-list
+	       list-all-plugins list-plugins	
 	    );
  
 # not enough arguments
@@ -91,11 +95,11 @@
 sub show_users_list
 {
 	my $list_id = shift || die "You must pass a list id to show_users_list\n";
-	my $list    = Siesta->storage->load_list($list_id) || die "Invalid list id\n";
+	my $list    = Siesta::List->new($list_id) || die "Invalid list id\n";
 
 	print "\nThe list $list_id has the following members : \n";
 	print "----\n";
-	foreach my $user (Siesta->storage->list_members($list_id))
+	foreach my $user ($list->members())
         {
                 printf  "%s %s <%s>\n", $user->forename(), 
 					$user->surname(), 
@@ -116,13 +120,13 @@
 sub show_lists_user
 {
         my $user_id = shift || die "You must pass a user id to show_lists_user\n";
-        my $user    = Siesta->storage->load_user($user_id) || die "Invalid user id\n";
+        my $user    = Siesta::User->new($user_id) || die "Invalid user id\n";
 
 	print "\nThe user $user_id is on the following lists : \n";
 	print "----\n";
-        foreach my $list (Siesta->list->users($user_id))
+        foreach my $list ($user->lists())
         {
-		print $list->id()."\n";
+		print $list->id(),"\n";
         }
 }
 
@@ -151,6 +155,12 @@
 	print "User $forename $surname <$user_id> added\n";
 }
 
+=head2 delete-user [email address/user id]
+
+Remove a user from the system.
+
+=cut 
+
 sub delete_user
 {
 	my $user_id = shift || die "You must pass a user id\n";
@@ -167,10 +177,207 @@
 
 }
 
-# todo :
-# - new list
-# - add user to list : (create new user automagically)
-# - list plugins for a list
+=head2 modify-user [user id] [key] [value]
+
+Change a property of the user. See B<Siesta::User>
+for what        my $user_id = shift || die "You must pass a user id\n";
+
+        my $user = Siesta::User->new($user_id) || die "Not a valid user id\n";
+
+=cut
+
+sub modify_user
+{
+	my $user_id = shift || die "You must pass a user id\n";
+	
+	my $user = Siesta::User->new($user_id) || die "Not a valid user id\n";
+
+	my %fields = map { $_ => 1} @Siesta::User::fields;
+
+	my ($key, $value) = @_;
+	
+	die "'$key' is not a valid property\n" unless $fields{$key};
+	
+	$user->$key($value);
+
+	print "Property '$key' set to '$value' for the user $user_id\n"; 
+}
+
+=head2 add-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 
+'return path' is  the address that bounces should come back to.
+
+=cut
+
+sub new_list
+{
+
+	my $list_id     = shift || die "You must supply a list id\n";
+	my $list_owner  = shift || die "You must supply a list owner\n";
+	my $post_addr   = shift || die "You must supply a post address\n";
+	my $return_path = shift || die "You must supply a bounce address\n";
+
+	my $list = Siesta::List->new_from_hash({
+						id=> $list_id,
+						owner => $list_owner,
+						post_address => $post_addr,
+						return_path => $return_path,
+						}) ||
+			die "Failed to create a new list\n";
+
+	$list->save() || die "Failed to save the new list";
+
+	print "Created the new list '$list_id' <$post_addr>\n";
+	print "Paste this into your alias file to activate the list\n\n";
+	print create_alias($list_id);
+			
+}
+
+=head2 create-alias [list id]
+
+Print out an alias file entry for the list specified.
+
+=cut
+
+sub create_alias
+{
+	my $list_id = shift;
+
+	my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+	(my $path = $0) =~ s!^(.*[\\/]).*$!$1!;
+
+	(my $post = $list->post_address()) =~ s!@.*$!!;
+	(my $ret  = $list->return_path()) =~  s!@.*$!!;
+ 
+	print "\n\n";
+	printf "## %s mailing list\n", $list_id;
+	printf "## created: %s nacho (the siesta config tool)\n", 
+			strftime("%d-%b-%Y", localtime(time)); 
+	printf "%s: \"%s%s %s\"\n",  $post, $path, 'tequila', $list->id();
+	printf "%s: %s\n\n\nq", $ret,  $list->owner();
+
+}
+
+=head2 delete-list [list id]
+
+Remove the list indicated from the system.
+
+=cut
+
+sub delete_list
+{
+ 	my $list_id = shift;
+
+        my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+	foreach my $user ($list->members())
+	{
+		$list->remove_member($user);
+	}
+
+	$list->delete();	
+}
+
+=head2 modify-list [list id] [key] [value]
+
+Change a property of the list specified. See B<Siesta::List> 
+for valid propertys.
+
+=cut
+
+sub modify_list
+{
+        my $list_id = shift || die "You must pass a user id\n";
+
+        my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+        my %fields = map { $_ => 1} @Siesta::List::fields;
+
+        my ($key, $value) = @_;
+
+        die "'$key' is not a valid property\n" unless $fields{$key};
+
+        $list->$key($value);
+
+        print "Property '$key' set to '$value' for the list $list_id\n";
+}
+
+=head2 add-user-list [list id] [user id(s)]
+
+Add the users specified to the list specified. This will create 
+new users if necessary.
+
+=cut 
+
+sub add_user_list
+{
+	
+	my $list_id = shift || die "You must pass a user id\n";
+
+	my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+
+        my $user_id = shift || die "You must pass a user id\n";
+
+	while ($user_id)
+	{
+		# TODO - create new user if not valid
+	        my $user = Siesta::User->new($user_id) || die "$user_id is not a valid user id\n";
+	
+		$list->add_member($user);
+
+		print "User '$user_id' added to list '$list_id'\n";
+
+		$user_id = shift;
+	}
+
+}
+
+=head2 list-all-plugins 
+
+List all plugins in the system.
+
+=cut
+
+sub list_all_plugins
+{
+
+	print "This system currently has these plugins installed : \n";
+	foreach my $plugin (Siesta->list_all_plugins())
+	{
+		print "$plugin\n";
+	}
+	
+}
+
+=head2 list-plugins [list id]
+
+List the plugins for the list specified in the order
+that they'll be executed.
+
+=cut
+
+sub list_plugins
+{
+        my $list_id = shift || die "You must pass a user id\n";
+
+        my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+        my $a=1;
+
+	print "The list $list_id has these plugins activated :\n";
+        foreach my $plugin ($list->plugins())
+        {
+                print "$a) $plugin\n";
+                $a++;
+        }
+}
+
+
+# todo 
 # - list plugin config options
 # - list plugin config for a list
 # - list plugin config for a user
@@ -182,7 +389,9 @@
 {
 	(my $name = $0) =~ s!^.*[\\/]!!;
 
-	return "Usage: $name ".join " ", map { "[$_]" } @modes; 
+	return join '', "Usage: $name ", join (" ", map { "[$_]" } @modes),
+			 "\n See the $name manpage for more details"; 
+
 
 
 }



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