[prev] [thread] [next] [lurker] [Date index for 2002/08/28]
Update of /cvsroot/siesta/siesta/bin In directory usw-pr-cvs1:/tmp/cvs-serv13720 Added Files: nacho Log Message: Beginnings ofcommand line tool. Hey, I was bored. --- NEW FILE: nacho --- #!/usr/bin/perl -w use strict; 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); # not enough arguments die usage()."\n" unless @ARGV; # what are we doing? my $mode = shift @ARGV; # 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; # h-h-h-ack # due to syntax rules minues signs aren't # allowed in sub routine names. $mode =~ tr/-/_/; my $store = new Siesta::Storage::DBI ("",""); no strict qw(refs); # call the appropriate subroutine #eval { &$mode(@ARGV); #die usage()."\n" if $@; exit 0; # show all lists sub show_lists { foreach my $list (Siesta::Storage::Table::Lists->new()->retrieve_all()) { print $list->id()."\n"; } } # show all users sub show_users { foreach my $user (Siesta::Storage::Table::Users->new()->retrieve_all()) { printf "%s %s <%s>\n", $user->forename(), $user->surname(), $user->id(); } } # 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"; print "\nThe list $list_id has the following members : \n"; print "----\n"; foreach my $list_user ($store->list_members($list_id)) { my $user = new Siesta::User($list_user->user_id()); printf "%s %s <%s>\n", $user->forename(), $user->surname(), $user->id(); } } # 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"; print "\nThe user $user_id is on the following lists : \n"; print "----\n"; foreach my $list (Siesta::Storage::Table::Lists->new()->retrieve_all()) { print $list->id()."\n" if ($store->member_of_list($list->id(), $user_id)); } } sub usage { (my $name = $0) =~ s!^.*[\\/]!!; return "Usage: $name ".join " ", map { "[$_]" } @modes; }
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52