]>
jfr.im git - irc/weechat/qweechat.git/blob - src/qweechat/config.py
2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
6 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
8 # QWeeChat is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # QWeeChat is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
23 # Configuration for QWeeChat (~/.qweechat/qweechat.conf)
26 import os
, ConfigParser
28 CONFIG_DIR
= '%s/.qweechat' % os
.getenv('HOME')
29 CONFIG_FILENAME
= '%s/qweechat.conf' % CONFIG_DIR
31 CONFIG_DEFAULT_SECTIONS
= ('relay', 'look')
32 CONFIG_DEFAULT_OPTIONS
= (('relay.server', ''),
34 ('relay.password', ''),
35 ('relay.autoconnect', 'off'),
36 ('look.debug', 'off'),
37 ('look.statusbar', 'off'))
41 """Read config file."""
42 config
= ConfigParser
.RawConfigParser()
43 if os
.path
.isfile(CONFIG_FILENAME
):
44 config
.read(CONFIG_FILENAME
)
46 # add missing sections/options
47 for section
in CONFIG_DEFAULT_SECTIONS
:
48 if not config
.has_section(section
):
49 config
.add_section(section
)
50 for option
in reversed(CONFIG_DEFAULT_OPTIONS
):
51 section
, name
= option
[0].split('.', 1)
52 if not config
.has_option(section
, name
):
53 config
.set(section
, name
, option
[1])
57 """Write config file."""
58 if not os
.path
.exists(CONFIG_DIR
):
59 os
.mkdir(CONFIG_DIR
, 0755)
60 with open(CONFIG_FILENAME
, 'wb') as cfg
: