1872
by Canonical.com Patch Queue Manager
First cut of the email interface! Refactorings to SQLObjectFooEvents. First cut of banzai deeath scene. Fix bug 931. Add bug url declarations. And some more... r=stevea |
1 |
#!/usr/bin/env python
|
2 |
# Copyright 2004 Canonical Ltd. All rights reserved.
|
|
3 |
"""Fetches mail from the mail box and feeds them to the handlers."""
|
|
4 |
||
5 |
import logging, sys |
|
6 |
||
7 |
from optparse import OptionParser |
|
8 |
||
9 |
from zope.component.exceptions import ComponentLookupError |
|
10 |
||
11 |
from canonical.lp import initZopeless |
|
12 |
from canonical.launchpad.scripts import execute_zcml_for_scripts |
|
13 |
from canonical.launchpad.scripts.lockfile import LockFile |
|
14 |
from canonical.launchpad.mail.incoming import handleMail |
|
15 |
from canonical.launchpad.interfaces import IMailBox |
|
16 |
||
17 |
usage = """%prog [options] |
|
18 |
||
19 |
""" + __doc__ |
|
20 |
||
21 |
options_parser = OptionParser(usage=usage) |
|
22 |
||
23 |
def create_logger(): |
|
24 |
logger = logging.getLogger('process-mail') |
|
25 |
handler = logging.StreamHandler(strm=sys.stderr) |
|
26 |
logger.addHandler(handler) |
|
27 |
return logger |
|
28 |
||
29 |
||
30 |
def main(args): |
|
31 |
options, args = options_parser.parse_args(args) |
|
32 |
||
33 |
lockfile = LockFile('/var/lock/launchpad-poimport.lock') |
|
34 |
lockfile.acquire() |
|
35 |
||
36 |
logger = create_logger() |
|
37 |
||
38 |
try: |
|
39 |
trans = initZopeless() |
|
40 |
execute_zcml_for_scripts(use_web_security=True) |
|
41 |
||
42 |
try: |
|
43 |
handleMail(trans) |
|
44 |
except ComponentLookupError, lookup_error: |
|
45 |
if lookup_error.args[0] == IMailBox: |
|
46 |
logger.error( |
|
47 |
"No mail box is configured.\n\n" |
|
48 |
"Please see mailbox.txt for info on how to configure one.") |
|
49 |
else: |
|
50 |
logger.warn( |
|
51 |
"An exception occured in handleMail.", exc_info=True) |
|
52 |
finally: |
|
53 |
lockfile.release() |
|
54 |
||
55 |
||
56 |
if __name__ == '__main__': |
|
57 |
sys.exit(main(sys.argv[1:])) |