author | Pascal Volk <neverseen@users.sourceforge.net> |
Fri, 24 Jul 2009 01:21:12 +0000 | |
changeset 97 | 2de22fbab129 |
parent 95 | fc008eb12186 |
child 98 | e992f03aace7 |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
4
diff
changeset
|
2 |
# Copyright 2007-2008 VEB IT |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
# $Id$ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
6 |
"""Configurtion class for read, modify and write the |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
configuration from Virtual Mail Manager. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
9 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
|
4 | 11 |
from constants.VERSION import VERSION |
12 |
||
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
__author__ = 'Pascal Volk <p.volk@veb-it.de>' |
4 | 14 |
__version__ = VERSION |
15 |
__revision__ = 'rev '+'$Rev$'.split()[1] |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
__date__ = '$Date$'.split()[1] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
|
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
18 |
import locale |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
19 |
import sys |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
from shutil import copy2 |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
21 |
from ConfigParser import ConfigParser, MissingSectionHeaderError, ParsingError |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
22 |
from cStringIO import StringIO |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
24 |
from Exceptions import VMMConfigException |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
25 |
import constants.ERROR as ERR |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
27 |
locale.setlocale(locale.LC_ALL, '') |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
28 |
ENCODING = locale.nl_langinfo(locale.CODESET) |
32
ceb700bc4a80
* 'install.sh'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
29 |
|
49
9bd033177377
* 'VirtualMailManager/Config.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
30 |
class Config(ConfigParser): |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
31 |
"""This class is for configure the Virtual Mail Manager. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
You can specify settings for the database connection |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
and maildirectories. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
35 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
def __init__(self, filename): |
49
9bd033177377
* 'VirtualMailManager/Config.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
38 |
"""Creates a new Config instance |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
39 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
filename -- name of the configuration file |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
ConfigParser.__init__(self) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
self.__cfgFileName = filename |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
self.__cfgFile = None |
21 | 46 |
self.__VMMsections = ['database', 'maildir', 'services', 'domdir', |
47 |
'bin', 'misc', 'config'] |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
self.__changes = False |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
49 |
self.__missing = {} |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
self.__dbopts = [ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
['host', 'localhot'], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
['user', 'vmm'], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
['pass', 'your secret password'], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
['name', 'mailsys'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
self.__mdopts = [ |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
57 |
['name', 'Maildir'], |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
58 |
['folders', 'Drafts:Sent:Templates:Trash'], |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
['mode', 448], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
['diskusage', 'false'], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
['delete', 'false'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
] |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
63 |
self.__serviceopts = [ |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
64 |
['smtp', 'true'], |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
65 |
['pop3', 'true'], |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
66 |
['imap', 'true'], |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
67 |
['managesieve', 'true'] |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
68 |
] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
self.__domdopts = [ |
34
6d74e20c5b3b
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
32
diff
changeset
|
70 |
['base', '/srv/mail'], |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
['mode', 504], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
72 |
['delete', 'false'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
self.__binopts = [ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
['dovecotpw', '/usr/sbin/dovecotpw'], |
86
e43e4e7e9ec0
* 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
76 |
['du', '/usr/bin/du'], |
e43e4e7e9ec0
* 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
77 |
['postconf', '/usr/sbin/postconf'] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
78 |
] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
79 |
self.__miscopts = [ |
24 | 80 |
['passwdscheme', 'PLAIN'], |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
['gid_mail', 8], |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
82 |
['forcedel', 'false'], |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
83 |
['transport', 'dovecot:'] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
84 |
] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
85 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
86 |
def load(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
87 |
"""Loads the configuration, r/o""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
88 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
89 |
self.__cfgFile = file(self.__cfgFileName, 'r') |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
90 |
self.readfp(self.__cfgFile) |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
91 |
except (MissingSectionHeaderError, ParsingError), e: |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
92 |
self.__cfgFile.close() |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
93 |
raise VMMConfigException(str(e), ERR.CONF_ERROR) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
94 |
self.__cfgFile.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
|
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
96 |
def check(self): |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
97 |
if not self.__chkSections(): |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
98 |
errmsg = StringIO() |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
86
diff
changeset
|
99 |
errmsg.write(_("Using configuration file: %s\n") %\ |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
86
diff
changeset
|
100 |
self.__cfgFileName) |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
101 |
for k,v in self.__missing.items(): |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
102 |
if v[0] is True: |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
103 |
errmsg.write(_(u"missing section: %s\n") % k) |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
104 |
else: |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
105 |
errmsg.write(_(u"missing options in section %s:\n") % k) |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
106 |
for o in v: |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
107 |
errmsg.write(" * %s\n" % o) |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
108 |
raise VMMConfigException(errmsg.getvalue(), ERR.CONF_ERROR) |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
109 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
110 |
def getsections(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
111 |
"""Return a list with all configurable sections.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
112 |
return self.__VMMsections[:-1] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
113 |
|
69
0c124160a991
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
68
diff
changeset
|
114 |
def get(self, section, option, raw=False, vars=None): |
0c124160a991
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
68
diff
changeset
|
115 |
return unicode(ConfigParser.get(self, section, option, raw, vars), |
0c124160a991
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
68
diff
changeset
|
116 |
ENCODING, 'replace') |
0c124160a991
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
68
diff
changeset
|
117 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
118 |
def configure(self, sections): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
"""Interactive method for configuring all options in the given section |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
122 |
sections -- list of strings |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
124 |
if not isinstance(sections, list): |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
51
diff
changeset
|
125 |
raise TypeError("Argument 'sections' is not a list.") |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
126 |
# if [config] done = false (default at 1st run), |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
# then set changes true |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
128 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
129 |
if not self.getboolean('config', 'done'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
130 |
self.__changes = True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
131 |
except ValueError: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
132 |
self.set('config', 'done', 'False') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
133 |
self.__changes = True |
95
fc008eb12186
* 'VirtualMailManager/Config.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
94
diff
changeset
|
134 |
print _(u"Using configuration file: %s\n") % self.__cfgFileName |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
135 |
for s in sections: |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
136 |
if s != 'config': |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
137 |
print _(u'* Config section: »%s«') % s |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
138 |
for opt, val in self.items(s): |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
139 |
newval = raw_input( |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
49
diff
changeset
|
140 |
_('Enter new value for option %(opt)s [%(val)s]: ').encode( |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
49
diff
changeset
|
141 |
ENCODING, 'replace') % {'opt': opt, 'val': val}) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
142 |
if newval and newval != val: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
self.set(s, opt, newval) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
self.__changes = True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
145 |
print |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
if self.__changes: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
self.__saveChanges() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
148 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
149 |
def __saveChanges(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
150 |
"""Writes changes to the configuration file.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
151 |
self.set('config', 'done', 'true') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
copy2(self.__cfgFileName, self.__cfgFileName+'.bak') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
153 |
self.__cfgFile = file(self.__cfgFileName, 'w') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
154 |
self.write(self.__cfgFile) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
155 |
self.__cfgFile.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
156 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
157 |
def __chkSections(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
158 |
"""Checks if all configuration sections are existing.""" |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
159 |
errors = False |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
160 |
for s in self.__VMMsections: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
161 |
if not self.has_section(s): |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
162 |
self.__missing[s] = [True] |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
163 |
elif not self.__chkOptions(s): |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
164 |
errors = True |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
165 |
return not errors |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
167 |
def __chkOptions(self, section): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
168 |
"""Checks if all configuration options in section are existing. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
169 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
170 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
171 |
section -- the section to be checked |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
172 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
173 |
retval = True |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
174 |
missing = [] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
175 |
if section == 'database': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
176 |
opts = self.__dbopts |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
177 |
elif section == 'maildir': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
178 |
opts = self.__mdopts |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
179 |
elif section == 'services': |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
180 |
opts = self.__serviceopts |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
181 |
elif section == 'domdir': |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
182 |
opts = self.__domdopts |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
183 |
elif section == 'bin': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
184 |
opts = self.__binopts |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
185 |
elif section == 'misc': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
186 |
opts = self.__miscopts |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
187 |
elif section == 'config': |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
188 |
opts = [['done', 'false']] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
189 |
for o, v in opts: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
190 |
if not self.has_option(section, o): |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
191 |
missing.append(o) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
192 |
retval = False |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
193 |
if len(missing): |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
194 |
self.__missing[section] = missing |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
195 |
return retval |