summaryrefslogtreecommitdiff
path: root/misc/paths.py.in
blob: 50eaebf3e0a5c249b2dce4c9d9c0586f27bfc241 (plain)
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
# -*- python -*-

# Copyright (C) 1998-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

# configure turns this file into paths.py which is installed in the bin
# directory.  By importing this module, sys.path gets `hacked' so that the
# $prefix/Mailman and $prefix/pythonlib directories are inserted at the start
# of that list.  This file exports two attributes that other modules may use
# to get the absolute path to the installed Mailman distribution.
#
# Note that we can't use site.addsitedir() because that ends up appending
# directories to sys.path and we really need to add them to the front so that
# they override anything in the system Python.

import os
import sys

# Some scripts expect this attribute to be in this module
prefix = '@prefix@'
exec_prefix = '@exec_prefix@'

# Work around a bogus autoconf 2.12 bug
if exec_prefix == '${prefix}':
    exec_prefix = prefix

pythonlib = os.path.join(prefix, 'pythonlib')

# Hack the path to include the parent directory of $prefix/Mailman
sys.path.insert(0, prefix)

# Much of this is ripped off from site.py
paths = set()
for dirname in sys.path:
    try:
        if os.path.isdir(dirname):
            paths.add(os.path.normcase(os.path.abspath(dirname)))
    except TypeError:
        pass

extra_paths = [pythonlib]
for name in sorted(os.listdir(pythonlib)):
    if os.path.splitext(name)[1] == '.pth':
        filename = os.path.join(pythonlib, name)
        try:
            fp = open(filename, 'rU')
        except IOError:
            continue
        try:
            for line in fp:
                if line.startswith('#'):
                    continue
                if line.startswith('import'):
                    exec line
                    continue
                line = line.rstrip()
                path = os.path.abspath(os.path.join(pythonlib, line))
                path = os.path.normcase(path)
                if not path in paths and os.path.exists(path):
                    # Here's what's different than site.py!
                    extra_paths.append(path)
                    paths.add(path)
        finally:
            fp.close()
# Add the new paths to the front of sys.path
sys.path[0:0] = extra_paths


# Arabic and Hebrew (RFC-1556) encoding aliases. (temporary solution)
import encodings.aliases
encodings.aliases.aliases.update({
    'iso_8859_6_e': 'iso8859_6',
    'iso_8859_6_i': 'iso8859_6',
    'iso_8859_8_e': 'iso8859_8',
    'iso_8859_8_i': 'iso8859_8',
    })