3
# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
3
# Copyright (C) 1998-2005 by the Free Software Foundation, Inc.
5
5
# This program is free software; you can redistribute it and/or
6
6
# modify it under the terms of the GNU General Public License
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
20
"""Configure a list from a text file description.
72
73
from Mailman import MailList
73
74
from Mailman import Utils
74
75
from Mailman import Errors
75
from Mailman.i18n import _
76
from Mailman import i18n
81
nonasciipat = re.compile(r'[\x80-\xff]')
103
107
mlist = MailList.MailList(listname, lock=0)
104
108
except Errors.MMListError:
105
109
usage(1, _('No such list: %(listname)s'))
106
# get all the list config info. all this stuff is accessible via the
110
# Preamble for the config info. PEP263 charset and capture time.
111
language = mlist.preferred_language
112
charset = Utils.GetCharSet(language)
113
i18n.set_language(language)
108
116
when = time.ctime(time.time())
109
117
print >> outfp, _('''\
110
## "%(listname)s" mailing list configuration settings -*- python -*-
119
# -*- coding: %(charset)s -*-
120
## "%(listname)s" mailing list configuration settings
111
121
## captured on %(when)s
123
# get all the list config info. all this stuff is accessible via the
114
125
for k in mm_cfg.ADMIN_CATEGORIES:
115
126
subcats = mlist.GetConfigSubCategories(k)
116
127
if subcats is None:
128
139
label, gui = mlist.GetConfigCategories()[k]
142
charset = Utils.GetCharSet(mlist.preferred_language)
131
143
print >> outfp, '##', k.capitalize(), _('options')
132
144
print >> outfp, '#'
133
145
# First, massage the descripton text, which could have obnoxious
166
178
value = gui.getValue(mlist, vtype, varname, data[2])
167
179
if value is None and not varname.startswith('_'):
168
180
value = getattr(mlist, varname)
169
if vtype in (mm_cfg.Text, mm_cfg.FileUpload):
181
if vtype in (mm_cfg.String, mm_cfg.Text, mm_cfg.FileUpload):
170
182
print >> outfp, varname, '=',
171
183
lines = value.splitlines()
173
185
print >> outfp, "''"
174
186
elif len(lines) == 1:
175
print >> outfp, repr(lines[0])
187
if charset <> 'us-ascii' and nonasciipat.search(lines[0]):
188
# This is more readable for non-english list.
189
print >> outfp, '"' + lines[0].replace('"', '\\"') + '"'
191
print >> outfp, repr(lines[0])
184
outfp.write(line.replace('"', '\\"'))
185
print >> outfp, '"""'
193
if charset == 'us-ascii' and nonasciipat.search(value):
194
# Normally, an english list should not have non-ascii char.
195
print >> outfp, repr(NL.join(lines))
198
outfp.write(NL.join(lines).replace('"', '\\"'))
186
200
elif vtype in (mm_cfg.Radio, mm_cfg.Toggle):
187
201
print >> outfp, '#'
188
202
print >> outfp, '#', _('legal values are:')