head	1.2;
access;
symbols
	HELM_PEER_PORT_BRANCH:1.1.1.1 dlr:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2001.02.22.04.48.17;	author edk;	state dead;
branches;
next	1.1;

1.1
date	2001.02.21.00.36.25;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2001.02.21.00.36.25;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.2
log
@remove a generated file which was accidentally added
@
text
@#!/usr/bin/perl

use DBI;  
use Getopt::Long;
use strict;

main();

sub main {
    my $options_ref = getOptions();
    $main::dbh = getDatabaseConnection();
    my $lists_ref = getLists($main::dbh);
    handleLists($options_ref, $lists_ref);
}

#################################
### handle any required actions
#################################

sub handleLists {
    my ($options_ref, $lists_ref) = @@_;
    my @@command_base = getCommand($options_ref);
    foreach my $list (@@$lists_ref) {
        my ($list, $project, $domain) = @@$list;
        my @@command = getCommand($options_ref, $list, $project, $domain);
#        print "would do @@command\n";
        system (@@command);
    }
}

sub getCommand {
    my ($options_ref, $list, $project, $domain) = @@_;
    my @@command =
        ($options_ref->{sandbox}."/eyebrowse/src/scripts/index2mbox.pl",
         "--directory");
    if ($options_ref->{type} eq "oldtigris") {
        # treat www as a special case
        push @@command, $options_ref->{directory} . "/" .
            ($project eq 'www' ? '' : "$project-" ) . $list;
    } elsif ($options_ref->{type} eq "sourcecast") {
        push @@command, $options_ref->{directory} . "/domains/" . $domain .
            "/projects/" . $project . "/addresses/" . $list;
    }
    push @@command, "--output", $options_ref->{sandbox} . "/data/eyebrowse/".
        $domain . "/" . $project . "/" . $list . "/0mbox";
    return @@command;
}

#################################
### process information according to business logic
#################################

#################################
###  preparation (getting information, db connections, etc.)
#################################

sub getOptions {
    my %options;
    if (!GetOptions(\%options, "type=s", "directory=s", "sandbox=s")) {
        showUsage();
    }
    $options{sandbox} || ($options{sandbox} = '/home/dlr/sandbox');
    $options{type}    || ($options{type}    = "oldtigris");
    die "invalid type $options{type}\n" 
        if ($options{type} ne "oldtigris" and $options{type} ne "sourcecast");

    if (not $options{directory}) {
        if ($options{type} eq "oldtigris") {
            $options{directory} = "$options{sandbox}/data/helm/qmail";
        } elsif ($options{type} eq "sourcecast") {
            $options{directory} = "$options{sandbox}/data/anzu";
        }
    }
    return \%options;
}
    
sub getLists {
    my ($dbh) = @@_;
    my @@lists = ();
    my $select  = $dbh->prepare(
            "SELECT ml.LIST_NAME as list, ".
                "proj.NAME as project, ".
                "dom.NAME as domain " .
            "FROM HELM_MAILINGLIST ml, HELM_PROJECT proj, HELM_DOMAIN dom ".
            "WHERE ml.PROJECT_ID = proj.PROJECT_ID AND ".
                "proj.DOMAIN_ID = dom.DOMAIN_ID");
    my $ret  = $select->execute();
    warn "error selecting lists" if not $ret;
    while (my $listRecord = $select->fetchrow_hashref) {
        my $list = $listRecord->{list};
        my $project = $listRecord->{project};
        my $domain = $listRecord->{domain};
        push @@lists, [$list, $project, $domain];
    }
    return \@@lists;
}

END { $main::dbh->disconnect if $main::dbh }

sub getDatabaseConnection {
    my $db_base = 'mysql';
    my $db_name = 'tigris_1025';
    my $db_host = 'localhost';
    my $db_port = '3306';
    my $db_user = 'tigris';
    my $db_pass = 'euphrates';
    my $connectstring = "dbi:$db_base:$db_name:host=$db_host:port=$db_port";
    my $dbh = DBI->connect($connectstring, $db_user, $db_pass)
        or die "Can't connect to the table '$connectstring'.\n";
    return $dbh;
}

sub showUsage {
    print "usage: archive_convert [--sandbox {sandbox}] [--directory {dir}]\n",
        "\t[--type {type}]\n";
    exit;
}

@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@@
