]> jfr.im git - irc/weechat/qweechat.git/blobdiff - qweechat/config.py
Rename default option "server" to "hostname"
[irc/weechat/qweechat.git] / qweechat / config.py
index 2aa5909615f480483f0f8bec84ba1248ffc0f2ad..835c1fbeea89df2bc4186651caa8c3f69899c60c 100644 (file)
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 #
-# config.py - configuration for QWeeChat (~/.qweechat/qweechat.conf)
+# config.py - configuration for QWeeChat
 #
-# Copyright (C) 2011-2014 Sébastien Helleu <flashcode@flashtux.org>
+# Copyright (C) 2011-2021 Sébastien Helleu <flashcode@flashtux.org>
 #
 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
 #
 # along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-import ConfigParser
+"""Configuration for QWeeChat."""
+
+import configparser
 import os
 
-CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
+from pathlib import Path
+
+CONFIG_DIR = '%s/.config/qweechat' % os.getenv('HOME')
 CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
 
 CONFIG_DEFAULT_RELAY_LINES = 50
 
 CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
-CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
+CONFIG_DEFAULT_OPTIONS = (('relay.hostname', ''),
                           ('relay.port', ''),
                           ('relay.ssl', 'off'),
                           ('relay.password', ''),
@@ -91,7 +95,7 @@ config_color_options = []
 def read():
     """Read config file."""
     global config_color_options
-    config = ConfigParser.RawConfigParser()
+    config = configparser.RawConfigParser()
     if os.path.isfile(CONFIG_FILENAME):
         config.read(CONFIG_FILENAME)
 
@@ -121,9 +125,8 @@ def read():
 
 def write(config):
     """Write config file."""
-    if not os.path.exists(CONFIG_DIR):
-        os.mkdir(CONFIG_DIR, 0o0755)
-    with open(CONFIG_FILENAME, 'wb') as cfg:
+    Path(CONFIG_DIR).mkdir(mode=0o0700, parents=True, exist_ok=True)
+    with open(CONFIG_FILENAME, 'w') as cfg:
         config.write(cfg)