summaryrefslogtreecommitdiff
path: root/Mailman/Cgi/archives.py
blob: 414795c7a724a9b2e8b7b7831656e34896a032f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /usr/bin/env python
#
# Copyright (C) 1998 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# This script is being deprecated, in favor hookups for an external archiver.

# We don't need to lock in this script, because we're never going to change
# data.

import sys
import os
import string
from Mailman import Utils, MailList, htmlformat


def ArchiveFilter(str):
    try:
        if str[:7] <> 'volume_':
            return 0
        try:
            x = int(str[7:])
        except ValueError:
            return 0
        if x < 1:
            return 0
        return 1
    except IndexError:
        return 0


def GetArchiveList(mlist):
    archive_list = htmlformat.UnorderedList()
    try:
	dir_listing = filter(ArchiveFilter, os.listdir(mlist.archive_dir()))
    except os.error:
	return "<h3><em>No archives are currently available.</em></h3>"
    if not len(dir_listing):
	return "<h3><em>No archives are currently available.</em></h3>"
    for dir in dir_listing:
	link = htmlformat.Link("%s/%s" % (mlist._base_archive_url, dir),
			       "Volume %s" % dir[7:])
	archive_list.AddItem(link)
    return archive_list.Format()
	
    
def main():
    print "Content-type: text/html"
    print

    list_info = []
    try:
        path = os.environ['PATH_INFO']
        list_info = Utils.GetPathPieces(path)
    except KeyError:
        pass

    if len(list_info) < 1:
        print "<h2>Invalid options to CGI script.</h2>"
        sys.exit(0)

    list_name = string.lower(list_info[0])
    try:
        mlist = MailList.MailList(list_name)
    except:
        print "<h2>%s: No such list.</h2>" % list_name
        sys.exit(0)

    if not mlist._ready:
        print "<h2>%s: No such list.</h2>" % list_name
        sys.exit(0)

    replacements = mlist.GetStandardReplacements()
    replacements['<mm-archive-list>'] = GetArchiveList(mlist)

    # Just doing print mlist.ParseTags(...) calls ParseTags twice???
    text = mlist.ParseTags('archives.html', replacements)
    print text