[prev] [thread] [next] [lurker] [Date index for 2004/04/07]
Author: simon Date: 2004-04-07 16:54:18 +0100 (Wed, 07 Apr 2004) New Revision: 1512 Added: trunk/siesta/messages/bandito trunk/siesta/messages/generate_setup Modified: trunk/siesta/bin/bandito trunk/siesta/messages/backup Log: Make bandito generate shell scripts and take Digests into account Modified: trunk/siesta/bin/bandito =================================================================== --- trunk/siesta/bin/bandito 2004-04-06 17:01:19 UTC (rev 1511) +++ trunk/siesta/bin/bandito 2004-04-07 15:54:18 UTC (rev 1512) @@ -1,36 +1,35 @@ #!/usr/local/bin/perl -w -use strict; -use Siesta; -use Siesta::List; -use Siesta::Member; +use strict; +use Siesta::Config; +my $old_archive_dir; +BEGIN { + while (@ARGV) { + if (@ARGV && $ARGV[0] eq '-a') { + shift; + $old_archive_dir = shift; + } elsif (@ARGV && $ARGV[0] eq '-f') { + shift; + $config->load_from( shift ); + } else { + last; + } + } + } + +use Siesta; +use Siesta::List; +use Siesta::Member; use Python::Serialise::Marshal; use Email::Folder; use Email::LocalDelivery; use POSIX qw/strftime/; +use UNIVERSAL::require; +use String::ShellQuote qw( shell_quote ); -my $old_archive_dir; -BEGIN { - while (@ARGV) { - - if (@ARGV && $ARGV[0] eq '-a') { - shift; - $old_archive_dir = shift; - } elsif (@ARGV && $ARGV[0] eq '-f') { - shift; - $Siesta::Config::CONFIG_FILE = shift; - } else { - last; - } - } -} -use Siesta::Config; - - - =pod =head1 NAME @@ -120,154 +119,181 @@ my $file = shift || die "You must pass a mailman config.db\n"; my $pr = Python::Serialise::Marshal->new($file) || die "Couldn't open $file\n"; - my $data = $pr->load(); +use YAML; +print Dump $data; +exit; (my $list_name = $data->{private_archive_file_dir}) =~ s!.+/([^/]+).mbox$!$1!; -my $owner = Siesta::Member->find_or_create({ email => $data->{owner}->[0] }); +my $owner = $data->{owner}->[0]; my $post_address = $list_name.'@'.$data->{host_name}; my $return_path = $list_name.'-bounce@'.$data->{host_name}; -print "Creating a new list '$list_name' ...\n"; -print "\towner is '$owner'\n"; -print "\tpost address is '$post_address'\n"; -print "\treturn path is '$return_path'\n"; -print "\n\n"; +print STDERR "Creating a new list '$list_name' ...\n"; +print STDERR "\towner is '$owner'\n"; +print STDERR "\tpost address is '$post_address'\n"; +print STDERR "\treturn path is '$return_path'\n"; +print STDERR "\n\n"; -# create the new list -my $list = Siesta::List->new ( - name => $list_name, - owner => $owner, + +my $list = { + name => $list_name, + owner => $owner, post_address => $post_address, return_path => $return_path, + queues => [ 'sub' , 'unsub', 'post' ], + members => [], +}; -) or die "Failed to create a new list\n"; +print STDERR "Adding plugins : "; +# TODO there;s a problem with Archive and Digest +my @plugins = qw(Debounce MembersOnly Moderated ListHeaders ReplyTo SubjectTag MessageFooter Send +NoMail); +print STDERR join ", ", @plugins; +print STDERR "\n\n"; +my %plugins; +foreach my $name (@plugins) { + my $plugin = {}; -# make the new members -print "Adding new members : \n"; -foreach my $email (keys %{$data->{passwords}}) { - print "$email "; - my $member = Siesta::Member->find_or_create({ email => $email }); - my $nomail = ($data->{user_options}->{$email} & $flags{'DisableDelivery'} == $flags{'DisableDelivery'}); - #$member->nomail($nomail); - #$member->password($data->{passwords}->{$email}); - $member->update; - $list->add_member( $member ); + $plugin->{name} = $name; + $plugin->{personal} = $plugin->{name} =~ s/^\+//; - - + $plugins{$name} = bless $plugin, 'Siesta::FakePlugin'; } -print "\n\n"; +print STDERR "Setting options :\n"; +# reply to +my $reply_to = $data->{'reply_goes_to_list'} || 0; +print STDERR "ReplyTo => $reply_to\n"; +$plugins{'ReplyTo'}->{pref}->{munge} = $reply_to; -print "Adding plugins : "; -# first qet the sub and unsub queues out of the way -$list->set_plugins( sub => qw(Subscribe) ); -$list->set_plugins( unsub => qw(UnSubscribe) ); - -my @plugins = qw(Debounce MembersOnly Moderated ListHeaders ReplyTo SubjectTag MessageFooter Send Archive); -print join ", ", @plugins; -print "\n\n"; -$list->set_plugins( post => @plugins ); - -# now get them out again -my %plugins = map { $_->name => $_ } $list->plugins; - -print "Setting options :\n"; -# reply to -my $reply_to = $data->{'reply_goes_to_list'}; - $reply_to = 0 unless defined $reply_to; -print "ReplyTo => $reply_to\n"; -$plugins{'ReplyTo'}->pref('munge',$reply_to); - - # members only -my $members_only = $data->{'member_posting_only'}; - $members_only = 0 unless defined $members_only; +my $members_only = $data->{'member_posting_only'} || 0; +print STDERR "MembersOnly => $members_only\n"; +$plugins{'MembersOnly'}->{pref}->{approve} = $members_only; +$plugins{'MembersOnly'}->{pref}->{tell_user} = 1; +$plugins{'MembersOnly'}->{pref}->{allowed_posters} = join " ", @{$data->{posters}}; -print "MembersOnly => $members_only\n"; -$plugins{'MembersOnly'}->pref('approve', $members_only); -$plugins{'MembersOnly'}->pref('tell_user', 1); -$plugins{'MembersOnly'}->pref('allowed_posters', join " ", @{$data->{posters}}); - # set the subject line -my $subject_munge = $data->{'subject_prefix'}; - $subject_munge = "" unless defined $subject_munge; -print "SubjectTag => $subject_munge\n"; +my $subject = $data->{'subject_prefix'}; $subject = "" unless defined $subject; +print STDERR "SubjectTag => $subject\n"; +$plugins{'SubjectTag'}->{pref}->{subjecttag} = $subject; + # whether or not it's moderated -my $moderated = $data->{'moderated'}; - $moderated = 0 unless defined $moderated; -print "Moderated => $moderated\n"; -$plugins{'Moderated'}->pref('moderated', $moderated); -$plugins{'Moderated'}->pref('tell_user', 1); +my $moderated = $data->{'moderated'} || 0; +print STDERR "Moderated => $moderated\n"; +$plugins{'Moderated'}->{pref}->{moderated} = $moderated; +$plugins{'Moderated'}->{pref}->{tell_user} = 1; + # the message footer +print STDERR "MessageFooter => ", $data->{'description'},"\n"; my $footer = $data->{'msg_footer'}; if ($footer && $footer !~ /^\s+$/m) { $footer =~ s!%\(([^\)]+)\)!\[% $1 %\]!gm; - $plugins{'MessageFooter'}->pref('footer',$footer); + $plugins{'MessageFooter'}->{pref}->{footer} = $footer; } foreach my $key (qw(info description web_page_url host_name cgiext)) { my $val = $data->{$key}; - $plugins{'MessageFooter'}->pref($key, $val) + $plugins{'MessageFooter'}->{pref}->{$key} = $val if ($val && $val !~ /^\s+$/m); } -$plugins{'MessageFooter'}->pref('description',$data->{'description'}); -print "MessageFooter => ",$data->{'description'},"\n"; -# now copy across the archives -# where are we going to get the mails from -my $in = $old_archive_dir || $data->{'public_archive_file_dir'}; +$list->{plugins}->{post} = [ values %plugins ]; +# now add the sub and unsub ones +$list->{plugins}->{sub} = [ bless { name => 'Subscribe' }, 'Siesta::FakePlugin' ]; +$list->{plugins}->{unsub} = [ bless { name => 'UnSubscribe' }, 'Siesta::FakePlugin' ]; -unless (-e $in) { - warn "No such file or dir '$in'\n"; - goto FAIL; + + + +# make the new members +my @members; +print STDERR "Adding new members : \n"; +foreach my $email (keys %{$data->{passwords}}) { + print STDERR "$email "; + + my $member = { email => $email, columns => ['email'], lists => [ $list_name ] }; + my $nomail = (($data->{user_options}->{$email} & $flags{'DisableDelivery'}) == $flags{'DisableDelivery'}); + + + $plugins{'+NoMail'}->{$email}->{pref}->{nomail} = $nomail; + + # we have no per list passwords + # $member->password($data->{passwords}->{$email}); + + push @members, $member; } -my $folder; +foreach my $email (keys %{$data->{digest_member}}) { + $plugins{'+Digest'}->{$email}->{pref}->{digest} = 1; +} -unless($folder = Email::Folder->new($in)) { - warn "Couldn't open '$in' to read archives from\n"; - goto FAIL; + +$list->{members} = \@members; + +print Siesta->bake('bandito', + 'members' => \@members, + 'lists' => [ bless $list, 'Siesta::FakeList' ], + 'shellq' => sub { my $val = shift || return; return shell_quote($val) }, + ); + + + + +print STDERR "\n\n"; + + + +package Siesta::FakePlugin; + +sub member { + my ($self, $member) = @_; + + $self->{_current_member} = $member->{email}; } -# work out where to stick them -my $name = $list->name; -my $path = "$Siesta::Config::ARCHIVE/$name/"; +sub pref { + my ($self, $key) = @_; -unless (-e $path) { - warn "No such file or dir '$in'\n"; - goto FAIL; + + my $member = $self->{_current_member}; + + if ($member) { + return $self->{$member}->{pref}->{$key}; + } else { + return $self->{pref}->{$key}; + } } +sub options { + my $self = shift; -# and then deliver each one -foreach my $mail ($folder->messages()) { - unless (Email::LocalDelivery->deliver( $mail->as_string, $path )) { - warn "local delivery into '$path' failed - couldn't copy archives from '$in'\n"; - goto FAIL; - } + my $class = "Siesta::Plugin::".$self->{name}; + + $class->require; + + + return $class->options; } -# yay! -print "Successfully copied archives from '$in' to '$path'\n"; +package Siesta::FakeList; -# erk -FAIL: +sub plugins { + my ($self, $queue) = @_; + return $self->{plugins}->{$queue}; +} -print "\n\nNow paste this into your aliases file :\n\n\n"; -print $list->alias("bandito (the Siesta config stealing tool)"); +1; - Modified: trunk/siesta/messages/backup =================================================================== --- trunk/siesta/messages/backup 2004-04-06 17:01:19 UTC (rev 1511) +++ trunk/siesta/messages/backup 2004-04-07 15:54:18 UTC (rev 1512) @@ -4,51 +4,6 @@ # report bugs to the siesta-dev team # http://siesta.unixbeard.net -### -# First create the database -### -nacho create-database +[% INCLUDE generate_setup %] -### -# Then, let's create users ... -### -[% FOREACH member = members %] -# [% member.email %] -nacho create-member [% member.email %] - [%- FOREACH col = member.columns -%] - [%- IF col != 'email' && col != 'id' %] -nacho modify-member [% member.email %] [% col %] [% shellq( member.$col ) %] - [%- END -%] - [%- END -%] -[% END %] -### -# Finally we create the lists, add the plugins -# and set the plugin prefs for the list and each user -### -[% FOREACH list = lists %] - -# [% list.name %] -nacho create-list [% list.name %] [% list.owner.email %] [% list.post_address %] [% list.return_path %] - [%- FOREACH queue = list.queues %] - -nacho set-plugins [% list.name %] [% queue %] [%- FOREACH plugin = list.plugins( queue ) -%] [% plugin.personal ? '+' : '' %][% plugin.name %][% END -%] - [%- FOREACH plugin = list.plugins( queue ) -%] - [%- FOREACH key = plugin.options.keys %] -nacho modify-plugin [% plugin.name %] [% list.name %] [% shellq( key ) %] [% shellq( plugin.pref( key ) ) %] - [%- END -%] - - [%- IF plugin.personal -%] - [%- FOREACH member = list.members -%][% x = plugin.member( member ) %] - [%- FOREACH key = plugin.options.keys %] - [%- val = plugin.pref( key ) %] - [%- IF val != plugin.options.$key.default %] -nacho modify-plugin [% plugin.name %] [% list.name %] [% shellq( key ) %] [% shellq( plugin.pref( key ) )%] [% member.email %] - [%- END -%] - [%- END -%] - [%- END -%] - [% END %] - [%- END -%] - - [%- END -%] -[%- END -%] Added: trunk/siesta/messages/bandito =================================================================== --- trunk/siesta/messages/bandito 2004-04-06 17:01:19 UTC (rev 1511) +++ trunk/siesta/messages/bandito 2004-04-07 15:54:18 UTC (rev 1512) @@ -0,0 +1,10 @@ +#!/bin/sh +[% USE Date %] +# +# Import script for [% lists.0.name %] +# +# This script was generated by 'bandito' on [% Date.format %] +# +# report bugs to the Siesta dev team (http://siesta.unixbeard.net) + +[% INCLUDE generate_setup %] Added: trunk/siesta/messages/generate_setup =================================================================== --- trunk/siesta/messages/generate_setup 2004-04-06 17:01:19 UTC (rev 1511) +++ trunk/siesta/messages/generate_setup 2004-04-07 15:54:18 UTC (rev 1512) @@ -0,0 +1,57 @@ +### +# First create the database +### +nacho create-database + +### +# Then, let's create users ... +### +[% FOREACH member = members %] +# [% member.email %] +nacho create-member [% member.email %] + [%- FOREACH col = member.columns -%] + [%- IF col != 'email' && col != 'id' %] +nacho modify-member [% member.email %] [% col %] [% shellq( member.$col ) %] + [%- END -%] + [%- END %] + [%- FOREACH list = member.lists %] +nacho add-member [% list %] [% member.email %] + [%- END %] +[% END %] + +### +# Finally we create the lists, add the plugins +# and set the plugin prefs for the list and each user +### +[% FOREACH list = lists %] + +# [% list.name %] +nacho create-list [% list.name %] [% list.owner.email %] [% list.post_address %] [% list.return_path %] + + [%- FOREACH queue = list.queues %] +nacho set-plugins [% list.name %] [% queue %] [%- FOREACH plugin = list.plugins( queue ) -%] [% plugin.personal ? '+' : '' %][% plugin.name %][% END %] + + [%- FOREACH plugin = list.plugins( queue ) -%] + + [%- IF !plugin.personal -%] + [%- FOREACH key = plugin.options.keys %] + [%- val = plugin.pref( key ) -%] + [%- IF val %] +nacho modify-plugin [% plugin.name %] [% list.name %] [% shellq( key ) %] [% shellq( val ) %] + [%- END -%] + [%- END -%] + + [%- ELSE # plugin.personal -%] + [%- FOREACH member = list.members -%][% x = plugin.member( member ) %] + [%- FOREACH key = plugin.options.keys %] + [%- val = plugin.pref( key ) %] + [%- IF val && val != plugin.options.$key.default %] +nacho modify-plugin [% plugin.name %] [% list.name %] [% shellq( key ) %] [% shellq( plugin.pref( key ) )%] [% member.email %] + [%- END -%] + [%- END -%] + [%- END -%] + [% END %] + [%- END -%] + + [%- END -%] +[%- END -%]
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52