]> jfr.im git - irc/weechat/qweechat.git/blame - src/qweechat/config.py
Add local variables in buffers, update prompt of buffers using local variable "nick"
[irc/weechat/qweechat.git] / src / qweechat / config.py
CommitLineData
7dcf23b1
SH
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
5#
6# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
7#
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.
12#
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.
17#
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/>.
20#
21
22#
23# Configuration for QWeeChat (~/.qweechat/qweechat.conf)
24#
25
26import os, ConfigParser
27
28CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
29CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
30
31CONFIG_DEFAULT_SECTIONS = ('relay', 'look')
32CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
33 ('relay.port', ''),
34 ('relay.password', ''),
35 ('relay.autoconnect', 'off'),
36 ('look.debug', 'off'),
37 ('look.statusbar', 'off'))
38
39
40def read():
41 """Read config file."""
42 config = ConfigParser.RawConfigParser()
43 if os.path.isfile(CONFIG_FILENAME):
44 config.read(CONFIG_FILENAME)
45
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])
54 return config
55
56def write(config):
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:
61 config.write(cfg)