This repository has been archived on 2019-12-04. You can view files and clone it, but cannot push or open issues or pull requests.
inara_updater/utils.py

34 lines
1020 B
Python
Raw Normal View History

2015-10-26 00:51:48 +00:00
from ConfigParser import ConfigParser
import os
2016-01-21 18:01:54 +00:00
def get_config_dir():
return os.path.join(path.expanduser('~'), '.ed_tools/')
2015-10-26 00:51:48 +00:00
def get_settings():
"""
Try to read the settings from file into ConfigParser object.
2016-01-21 17:57:35 +00:00
If the config file isn't found, initialize it.
2015-10-26 00:51:48 +00:00
"""
2016-01-21 18:01:54 +00:00
filename = os.path.join(get_config_dir(), 'settings.conf')
2015-10-26 00:51:48 +00:00
settings = ConfigParser()
if os.path.isfile(filename):
settings.read(filename)
else:
2016-01-21 17:57:35 +00:00
_init_settings(settings, filename)
2015-10-26 00:51:48 +00:00
return settings
2016-01-21 17:57:35 +00:00
def _init_settings(settings, filename):
2015-10-26 00:51:48 +00:00
settings.add_section('ed_companion')
settings.add_section('inara')
2016-01-21 17:57:35 +00:00
settings.set('ed_companion', 'username', raw_input("Elite Username (email address): "))
settings.set('ed_companion', 'password', raw_input("Elite Password: "))
settings.set('inara', 'username', raw_input("Inara Username: "))
settings.set('inara', 'password', raw_input("Inara Password: "))
print "To change these settings later, edit " + filename
2015-10-26 00:51:48 +00:00
with open(filename, 'wb') as f:
settings.write(f)