Make config setup more friendly.
This commit is contained in:
parent
65e45a0e0d
commit
545e937dae
|
@ -1,8 +0,0 @@
|
||||||
[ed_companion]
|
|
||||||
username = ed_email@domain.com
|
|
||||||
password = ed_password_goes_here
|
|
||||||
|
|
||||||
[inara]
|
|
||||||
username = inara_username_goes_here
|
|
||||||
password = inara_password_goes_here
|
|
||||||
|
|
17
utils.py
17
utils.py
|
@ -5,7 +5,7 @@ import os
|
||||||
def get_settings():
|
def get_settings():
|
||||||
"""
|
"""
|
||||||
Try to read the settings from file into ConfigParser object.
|
Try to read the settings from file into ConfigParser object.
|
||||||
If the config file isn't found, initialize it and bail.
|
If the config file isn't found, initialize it.
|
||||||
"""
|
"""
|
||||||
filename = os.path.join(config.app_dir, 'settings.conf')
|
filename = os.path.join(config.app_dir, 'settings.conf')
|
||||||
settings = ConfigParser()
|
settings = ConfigParser()
|
||||||
|
@ -13,20 +13,19 @@ def get_settings():
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
settings.read(filename)
|
settings.read(filename)
|
||||||
else:
|
else:
|
||||||
init_settings(settings, filename)
|
_init_settings(settings, filename)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def init_settings(settings, filename):
|
def _init_settings(settings, filename):
|
||||||
settings.add_section('ed_companion')
|
settings.add_section('ed_companion')
|
||||||
settings.add_section('inara')
|
settings.add_section('inara')
|
||||||
settings.set('ed_companion', 'username', '')
|
settings.set('ed_companion', 'username', raw_input("Elite Username (email address): "))
|
||||||
settings.set('ed_companion', 'password', '')
|
settings.set('ed_companion', 'password', raw_input("Elite Password: "))
|
||||||
settings.set('inara', 'username', '')
|
settings.set('inara', 'username', raw_input("Inara Username: "))
|
||||||
settings.set('inara', 'password', '')
|
settings.set('inara', 'password', raw_input("Inara Password: "))
|
||||||
|
print "To change these settings later, edit " + filename
|
||||||
|
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
settings.write(f)
|
settings.write(f)
|
||||||
|
|
||||||
raise Exception("Missing configuration. Please edit %s and run the program again." % filename)
|
|
||||||
|
|
Reference in New Issue
Block a user