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

66 lines
2.0 KiB
Python
Raw Normal View History

2015-10-26 00:51:48 +00:00
from ConfigParser import ConfigParser
import os
import easygui
import platform
2015-10-26 00:51:48 +00:00
2016-01-21 18:01:54 +00:00
def get_config_dir():
2016-01-21 18:23:09 +00:00
return os.path.join(os.path.expanduser('~'), '.ed_tools/')
2016-01-21 18:01:54 +00:00
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
def windows_detected():
return platform.system() == 'Windows'
2015-10-26 00:51:48 +00:00
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')
if windows_detected():
_settings_prompt_gui(settings)
easygui.msgbox("To change your settings later, edit " + filename)
else:
_settings_prompt_cli(settings)
print "To change these settings later, edit " + filename
with open(filename, 'wb') as f:
settings.write(f)
def _settings_prompt_gui(settings):
data = []
data = easygui.multenterbox(
"Enter your E:D and Inara credentials. You only need to do this once.",
"Authentication Data",
["Elite Username (email address)", "Elite Password",
"Inara Username", "Inara Password"]
)
for i in range(4):
if data[i].strip() == '':
easygui.msgbox("You must provide data for all fields.")
_settings_prompt_gui(settings)
return
settings.set('ed_companion', 'username', data[0].strip())
settings.set('ed_companion', 'password', data[1].strip())
settings.set('inara', 'username', data[2].strip())
settings.set('inara', 'password', data[3].strip())
def _settings_prompt_cli(settings):
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: "))