File: arch

package info (click to toggle)
mailman 1.1-10
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,572 kB
  • ctags: 1,485
  • sloc: python: 12,562; makefile: 625; ansic: 336; sh: 312
file content (114 lines) | stat: -rw-r--r-- 3,498 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /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.

"""Rebuild a list's archive.

Use this command to rebuild the archives for a mailing list.  You may want to
do this if you edit some messages in an archive, or remove some messages from
an archive.

Usage: %(program)s <listname> <mbox> [-h]

Where <mbox> is the path to a list's complete mbox archive.  Usually this will 
be some path in the archives/private directory.  For example:

%% bin/arch mylist archives/private/mylist.mbox/mylist.mbox
"""

import sys
import os
import getopt

import paths
from Mailman import mm_cfg
from Mailman.MailList import MailList
from Mailman.Archiver.HyperArch import HyperArchive, Article
from Mailman.LockFile import LockFile
from Mailman import Errors

program = sys.argv[0]



def usage(code, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(code)



def main():
    # get command line arguments
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'h', ['help'])
    except getopt.error, msg:
        usage(1, msg)

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage(0)

    # grok arguments
    if len(args) <> 2:
        usage(1, 'listname and/or mbox file is missing')

    # open the mailing list object
    mlist = None
    lock = None
    try:
        listname, mbox = sys.argv[1:]
        try:
            mlist = MailList(listname)
        except MMUnknownListError:
            usage(2, 'no such list: ' + listname)

        # lay claim to the archive's lock file.  this is so no other post can
        # mess up the archive while we're glomming it.  we pick a suitably
        # long period of time for the lock lifetime, however we really don't
        # know how long it will take.
        #
        # XXX: processUnixMailbox() should refresh the lock.
        #
        # XXX: this may not be necessary because I think we lay claim to the
        # list lock up above, although that may be too short to be of use (and 
        # maybe we don't really want to lock the list anyway).
        #
        lockfile = os.path.join(mm_cfg.LOCK_DIR, mlist._internal_name) + \
                   '.archiver.lock'
        # set the lock lifetime to 3 hours.  XXX is this reasonable???
        lock = LockFile(lockfile, lifetime=3*60*60)
        lock.lock()
        try:
            fp = open(mbox)
        except IOError, msg:
            usage(3, 'cannot open mbox file %s: %s' % (mbox, msg))

        archiver = HyperArchive(mlist)
        archiver.VERBOSE = 1
        archiver.processUnixMailbox(fp, Article)
        archiver.close()
        fp.close()
    finally:
        if mlist:
            mlist.Unlock()
        if lock:
            lock.unlock()


if __name__ == '__main__':
    main()