summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-09 00:05:44 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-09 00:05:44 +0000
commit835527e2d130cd427972cadfc82d10ee36391e52 (patch)
tree1a0002e851af6f5b621b6d72044620b72756ac3b
parent4bde31a5862e84891bc782a53ca3b3ab30a55fc6 (diff)
downloadpoezio-835527e2d130cd427972cadfc82d10ee36391e52.tar.gz
poezio-835527e2d130cd427972cadfc82d10ee36391e52.tar.bz2
poezio-835527e2d130cd427972cadfc82d10ee36391e52.tar.xz
poezio-835527e2d130cd427972cadfc82d10ee36391e52.zip
Writing to file doesn't remove comments. fixed #1713
-rw-r--r--src/config.py42
-rw-r--r--src/connection.py8
-rw-r--r--src/gui.py4
3 files changed, 40 insertions, 14 deletions
diff --git a/src/config.py b/src/config.py
index 5d91dd2d..73674711 100644
--- a/src/config.py
+++ b/src/config.py
@@ -94,13 +94,30 @@ class Config(RawConfigParser):
"""
return RawConfigParser.getboolean(self, self.defsection, option)
- def save(self):
- """
- save the configuration in the file
- """
- fdes = open(self.file_name, "w")
- RawConfigParser.write(self, fdes)
- fdes.close()
+ def write_in_file(self, section, option, value):
+ """
+ Our own way to save write the value in the file
+ Just find the right section, and then find the
+ right option, and edit it.
+ """
+ df = open(self.file_name, 'r')
+ lines_before = [line.strip() for line in df.readlines()]
+ df.close()
+ result_lines = []
+ we_are_in_the_right_section = False
+ for line in lines_before:
+ if line.startswith('['): # check the section
+ if line == '[%s]' % section:
+ we_are_in_the_right_section = True
+ else:
+ we_are_in_the_right_section = False
+ if line.startswith(option) and we_are_in_the_right_section:
+ line = '%s = %s' % (option, value)
+ result_lines.append(line)
+ df = open(self.file_name, 'w')
+ for line in result_lines:
+ df.write('%s\n' % line)
+ df.close()
def set_and_save(self, option, value):
"""
@@ -108,9 +125,7 @@ class Config(RawConfigParser):
to the file
"""
RawConfigParser.set(self, self.defsection, option, value)
- self.save()
-
- import argparse
+ self.write_in_file(self.defsection, option, value)
# creates the configuration directory if it doesn't exist
# and copy the default config in it
@@ -135,3 +150,10 @@ else:
filename = CONFIG_PATH+'poezio.cfg'
config = Config(filename)
+
+if __name__ == '__main__':
+ # tests
+ import sys
+ (dummy, filename, section, option, value) = sys.argv
+ conf = Config(sys.argv[1])
+ conf.write_in_file(section, option, value)
diff --git a/src/connection.py b/src/connection.py
index 224b7632..642614dd 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -105,11 +105,11 @@ class Connection(threading.Thread):
"""
registers handlers from xmpppy signals
"""
- # self.client.RegisterHandler('iq', self.on_get_time, typ='get',
- # ns="urn:xmpp:time")
+ self.client.RegisterHandler('iq', self.on_get_time, typ='get',
+ ns="urn:xmpp:time")
self.client.RegisterHandler('iq', self.on_get_vcard)
- # self.client.RegisterHandler('iq', self.on_get_version, typ='get',
- # ns=xmpp.NS_VERSION)
+ self.client.RegisterHandler('iq', self.on_get_version, typ='get',
+ ns=xmpp.NS_VERSION)
self.client.RegisterHandler('presence', self.handler_presence)
self.client.RegisterHandler('message', self.handler_message)
diff --git a/src/gui.py b/src/gui.py
index 19773c92..a2ff670d 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -181,6 +181,8 @@ class Gui(object):
returns the room that has this name
"""
for room in self.rooms:
+ from common import debug
+ debug('-- %s ? %s\n' % (room.name, name,))
if room.name.decode('utf-8') == name:
return room
return None
@@ -436,6 +438,8 @@ class Gui(object):
if (self.ignores.has_key(room_from)) and (nick_from in self.ignores[room_from]):
return
room = self.get_room_by_name(room_from)
+ from common import debug
+ debug('%s\n' % room_from)
if not room:
self.information(_("message received for a non-existing room: %s") % (room_from))
return