[siesta-commit] siesta/bin nacho,1.8,1.9

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

From: muttley
Subject: [siesta-commit] siesta/bin nacho,1.8,1.9
Date: 14:55 on 10 Sep 2002
Update of /cvsroot/siesta/siesta/bin
In directory usw-pr-cvs1:/tmp/cvs-serv4567/bin

Modified Files:
	nacho 
Log Message:
Plugin configuartion commands


Index: nacho
===================================================================
RCS file: /cvsroot/siesta/siesta/bin/nacho,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- nacho	9 Sep 2002 11:16:08 -0000	1.8
+++ nacho	10 Sep 2002 13:55:36 -0000	1.9
@@ -14,12 +14,17 @@
 	       show-list show-user create-alias
 	       show-users-list show-lists-user
 	       add-user-list remove-user-list
-	       list-all-plugins list-plugins
-	       list-plugin-options	
-	       list-plugin-config-default
-	       list-plugin-config-user
-	       list-plugin-config-list
-	       list-plugin-config-userlist
+	       show-all-plugins show-plugins 
+	       set-plugins-list add-plugin-list
+	       show-plugin-options	
+	       show-plugin-config-default
+	       show-plugin-config-user
+	       show-plugin-config-list
+	       show-plugin-config-userlist
+	       set-plugin-config-default
+	       set-plugin-config-user
+	       set-plugin-config-list
+	       set-plugin-config-userlist
 		
 	    );
  
@@ -430,13 +435,13 @@
         }
 }
 
-=head2 list-all-plugins 
+=head2 show-all-plugins 
 
 List all plugins in the system.
 
 =cut
 
-sub list_all_plugins
+sub show_all_plugins
 {
 
 	print "This system currently has these plugins installed : \n";
@@ -447,16 +452,16 @@
 	
 }
 
-=head2 list-plugins [list id]
+=head2 show-plugins [list id]
 
 List the plugins for the list specified in the order
 that they'll be executed.
 
 =cut
 
-sub list_plugins
+sub show_plugins
 {
-        my $list_id = shift || die "You must pass a user id\n";
+        my $list_id = shift || die "You must pass a list id\n";
 
         my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
 
@@ -471,7 +476,30 @@
 }
 
 
-=head2 list-plugin-options [plugin name]
+
+=head2 set-plugins [ list id ] [ plugin id(s) ]
+
+Set the list plugins to be the ones specified in the order specified.
+
+=cut
+
+sub set_plugins 
+{
+	my $list_id = shift || die "You must pass a list id\n";
+
+        my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+
+}
+
+=head2 add-plugin [ list id ] [ plugin id ] < position >
+
+Add a plugin onto the end of a list or, if a position is supplied, 
+then insert it somewhere in that list.
+
+=cut
+
+
+=head2 show-plugin-options [plugin name]
 
 List all the options for a particular plugin.
 
@@ -503,13 +531,13 @@
 
 }
 
-=head2 list-plugin-config-default [ plugin id ]
+=head2 show-plugin-config-default [ plugin id ]
 
 List the current default config options 	
 
 =cut
 
-sub list_plugin_config_default 
+sub show_plugin_config_default 
 {
 	my $plugin_id = shift || die "You must pass a plugin name\n";
 
@@ -521,13 +549,38 @@
 }
 
 
-=head2 list-plugin-config-user [ plugin id ] [ user id ]
+=head2 set-plugin-config-default [ plugin id ] [ key ] [ value ]
+
+Set the value of a config option for this plugin
+
+=cut 
+
+sub set_plugin_config_default
+{
+
+	my $plugin_id = shift || die "You must pass a plugin id\n";
+
+	my %plugins   = map { $_ => 1 } Siesta->list_all_plugins;
+
+        die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
+	my $key       = shift || die "You must pass a config option\n";
+	
+	my $value     = shift;
+
+	defined $value  || die "You must pass a new value\n";
+
+	_set_plugin_config ($plugin_id, undef, undef, $key, $value);
+}
+
+
+=head2 show-plugin-config-user [ plugin id ] [ user id ]
 
 List the current per-user options for this user and this plugin	
 
 =cut
 
-sub list_plugin_config_user
+sub show_plugin_config_user
 {
 	my $plugin_id = shift || die "You must pass a plugin name\n";
 
@@ -541,13 +594,42 @@
 	_list_plugin_config($plugin_id, $user_id, undef);
 }
 
-=head2 list-plugin-config-list [ plugin id ] [ list id ]
+
+
+=head2 set-plugin-config-user [ plugin id ] [ user id ] [ key ] [ value ]
+
+Set the value of a config option for this user and this plugin 
+
+=cut
+
+sub set_plugin_config_user
+{
+
+        my $plugin_id = shift || die "You must pass a plugin id\n";
+
+        my %plugins   = map { $_ => 1 } Siesta->list_all_plugins;
+
+        die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
+	my $user_id   = shift || die "You must pass a user id\n";
+
+        my $key       = shift || die "You must pass a config option\n";
+
+        my $value     = shift;
+	defined $value  || die "You must pass a new value\n";
+
+        _set_plugin_config ($plugin_id, $user_id, undef, $key, $value);
+}
+
+
+
+=head2 show-plugin-config-list [ plugin id ] [ list id ]
 
 List the current per-list options for this list and this plugin	
 
 =cut
 
-sub list_plugin_config_list
+sub show_plugin_config_list
 {
 	my $plugin_id = shift || die "You must pass a plugin name\n";
 
@@ -561,13 +643,40 @@
 	_list_plugin_config($plugin_id, undef, $list_id);
 }
 
-=head2 list-plugin-config-userlist [ plugin id ] [ user id ] [ list id ]
+
+=head2 set-plugin-config-list [ plugin id ] [ list id ] [ key ] [ value ]
+
+Set the value of a config option for this list and this plugin
+
+=cut
+
+sub set_plugin_config_list
+{
+
+        my $plugin_id = shift || die "You must pass a plugin id\n";
+
+        my %plugins   = map { $_ => 1 } Siesta->list_all_plugins;
+
+        die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
+        my $list_id   = shift || die "You must pass a list id\n";
+
+        my $key       = shift || die "You must pass a config option\n";
+
+        my $value     = shift;
+ 
+	defined $value || die "You must pass a new value\n";
+
+        _set_plugin_config ($plugin_id, undef, $list_id, $key, $value);
+}
+
+=head2 show-plugin-config-userlist [ plugin id ] [ user id ] [ list id ]
 
 List the current per-user options for this user on this list and this plugin	
 
 =cut
 
-sub list_plugin_config_userlist
+sub show_plugin_config_userlist
 {
 	my $plugin_id = shift || die "You must pass a plugin name\n";
 
@@ -582,15 +691,43 @@
 	_list_plugin_config($plugin_id, $user_id, $list_id);
 }
 
+=head2 set-plugin-config-userlist [ plugin id ] [ user id ] [ list id ] [ key ] [ value ]
+
+Set the value of a config option for this user and list and this plugin
 
+=cut
 
+sub set_plugin_config_userlist
+{
 
+        my $plugin_id = shift || die "You must pass a plugin id\n";
+
+        my %plugins   = map { $_ => 1 } Siesta->list_all_plugins;
+
+        die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
+        my $user_id   = shift || die "You must pass a user id\n";
+
+        my $list_id   = shift || die "You must pass a list id\n";
+
+        my $key       = shift || die "You must pass a config option\n";
+
+        my $value     = shift;
+	defined $value || die "You must pass a new value\n";
+
+
+        _set_plugin_config ($plugin_id, $user_id, $list_id, $key, $value);
+}
+
+
+# generic plugin config printer
 sub _list_plugin_config
 {
 	my ($plugin_id, $user_id, $list_id) = @_;
 
         my $class = "Siesta::Plugin::$plugin_id";
 
+	# check to see if it's a valid plugin
         eval "require $class";
         die $@ if $@;
         my $plugin =  $class->new();
@@ -598,51 +735,84 @@
 	$user_id ||= -1;
 	$list_id ||= -1;
 
+	# try and load the user and list
 	my $user = Siesta::User->new($user_id) || undef;
 	my $list = Siesta::List->new($list_id) || undef;
 
+	# set up a message
 	my $message = Siesta::Message->new();
 	$message->user($user);
 	$message->list($list);
 
 
+	# just set up the string, mere cosmetics
 	my $type = 'default';
-
 	if (defined $user && defined $list) {
-
 		$type = 'per-user-per-list';
-
 	} elsif (defined $user) {
-
 		$type = 'per-user';
-
 	} elsif (defined $list) {
-		
 		$type = 'per-list';	
-	
 	}
 	
 
 	print "\n\nThe '$type' options for the plugin $plugin_id :\n";
 
+	# loop through all the config options and print them out
 	foreach my $option (keys %{$plugin->options()})
 	{
-		my $value = $plugin->config($message, $option) || '[ no option set ]';
+		my $value = $plugin->config($message, $option);
+		$value = (defined $value)? $value :  '[ no option set ]';
 
 		print " - $option = $value\n";
 	}
 	print "\n";
 }
 
+# generic plugin config setter
+sub _set_plugin_config
+{
+        my ($plugin_id, $user_id, $list_id, $key, $value) = @_;
 
+        my $class = "Siesta::Plugin::$plugin_id";
+
+        # check to see if it's a valid plugin
+        eval "require $class";
+        die $@ if $@;
+        my $plugin =  $class->new();
 
 
-# todo 
-# - list plugin config options
-# - list plugin config for a list
-# - list plugin config for a user
+	die "That's not a valid option\n" unless $plugin->options()->{$key};
+
+        $user_id ||= -1;
+        $list_id ||= -1;
+
+        # try and load the user and list
+        my $user = Siesta::User->new($user_id) || undef;
+        my $list = Siesta::List->new($list_id) || undef;
+
+
+
+        # set up a message
+        my $message = Siesta::Message->new();
+        $message->user($user);
+        $message->list($list);
 
 
+        # just set up the string, mere cosmetics
+        my $type = 'default';
+        if (defined $user && defined $list) {
+                $type = 'per-user-per-list';
+        } elsif (defined $user) {
+                $type = 'per-user';
+        } elsif (defined $list) {
+                $type = 'per-list';
+        }
+
+	$plugin->config($message, $key, $value);
+	print "Set the $type config option '$key' to '$value' for the plugin '$plugin_id'\n";
+	
+}
 
 
 sub usage



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