Mercurial > libervia-backend
comparison src/tools/config.py @ 1056:a5cfa9bb4541
tools (config): fixConfigOption creates the section if it doesn't exist
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 08 Jun 2014 17:27:03 +0200 |
parents | a874a79ad0f5 |
children | 7ee9d9db67b9 |
comparison
equal
deleted
inserted
replaced
1055:abcac1ac27a7 | 1056:a5cfa9bb4541 |
---|---|
24 log = getLogger(__name__) | 24 log = getLogger(__name__) |
25 | 25 |
26 from sat.core.constants import Const as C | 26 from sat.core.constants import Const as C |
27 from sat.core.i18n import _ | 27 from sat.core.i18n import _ |
28 | 28 |
29 from ConfigParser import SafeConfigParser | 29 from ConfigParser import SafeConfigParser, DEFAULTSECT |
30 from xdg import BaseDirectory | 30 from xdg import BaseDirectory |
31 import os | 31 import os |
32 | 32 |
33 | 33 |
34 def fixConfigOption(section, option, value, silent=True): | 34 def fixConfigOption(section, option, value, silent=True): |
52 target_file = file_ | 52 target_file = file_ |
53 break | 53 break |
54 if not target_file: | 54 if not target_file: |
55 # ... otherwise we create a new config file for that user | 55 # ... otherwise we create a new config file for that user |
56 target_file = BaseDirectory.save_config_path('sat') + '/sat.conf' | 56 target_file = BaseDirectory.save_config_path('sat') + '/sat.conf' |
57 if section and section.upper() != DEFAULTSECT and not config.has_section(section): | |
58 config.add_section(section) | |
57 config.set(section, option, value) | 59 config.set(section, option, value) |
58 with open(target_file, 'wb') as configfile: | 60 with open(target_file, 'wb') as configfile: |
59 config.write(configfile) # for the next time that user launches sat | 61 config.write(configfile) # for the next time that user launches sat |
60 if not silent: | 62 if not silent: |
61 if option in ('passphrase'): # list here the options storing a password | 63 if option in ('passphrase'): # list here the options storing a password |