config: make sure we create the config file properly

I guess this code was tested with an existing config file only, because
I have the following:

DEBUG: tuhi.config: E0:61:C6:BF:14:4E: adding new config, uuid 8bbc6be4347a
Traceback (most recent call last):
  File "./tuhi.py", line 153, in _on_uuid_updated
    self.config.new_device(bluez_device.address, wacom_device.uuid)
  File "tuhi/tuhi/config.py", line 89, in new_device
    config['Device']['Address'] = address
  File "/usr/lib64/python3.6/configparser.py", line 959, in __getitem__
    raise KeyError(key)
KeyError: 'Device'
pull/14/head
Benjamin Tissoires 2018-01-19 10:05:32 +01:00 committed by Peter Hutterer
parent fda5d7f132
commit 1b73de68b2
1 changed files with 5 additions and 2 deletions

View File

@ -86,8 +86,11 @@ class TuhiConfig(GObject.Object):
config.optionxform = str
config.read(path)
config['Device']['Address'] = address
config['Device']['UUID'] = uuid
config['Device'] = {
'Address': address,
'UUID': uuid,
}
with open(path, 'w') as configfile:
config.write(configfile)