Default auto_login and README update
This commit is contained in:
12
README.rst
12
README.rst
@@ -152,14 +152,18 @@ RTV will read a configuration placed at ``~/.config/rtv/rtv.cfg`` (or ``$XDG_CON
|
|||||||
Each line in the file will replace the corresponding default argument in the launch script.
|
Each line in the file will replace the corresponding default argument in the launch script.
|
||||||
This can be used to avoid having to re-enter login credentials every time the program is launched.
|
This can be used to avoid having to re-enter login credentials every time the program is launched.
|
||||||
|
|
||||||
Example config:
|
The OAuth section contains a boolean to trigger auto-login (defaults to False).
|
||||||
|
When authenticated, two additional fields are written : **access_token** and **refresh_token**.
|
||||||
|
Those are basically like username and password : they are used to authenticate you on Reddit servers.
|
||||||
|
|
||||||
|
Example initial config:
|
||||||
|
|
||||||
.. code-block:: ini
|
.. code-block:: ini
|
||||||
|
|
||||||
[rtv]
|
[oauth]
|
||||||
username=MyUsername
|
auto_login=False
|
||||||
password=MySecretPassword
|
|
||||||
|
|
||||||
|
[rtv]
|
||||||
# Log file location
|
# Log file location
|
||||||
log=/tmp/rtv.log
|
log=/tmp/rtv.log
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,23 @@ from .__version__ import __version__
|
|||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
|
def get_config_fp():
|
||||||
|
HOME = os.path.expanduser('~')
|
||||||
|
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME',
|
||||||
|
os.path.join(HOME, '.config'))
|
||||||
|
|
||||||
|
config_paths = [
|
||||||
|
os.path.join(XDG_CONFIG_HOME, 'rtv', 'rtv.cfg'),
|
||||||
|
os.path.join(HOME, '.rtv')
|
||||||
|
]
|
||||||
|
|
||||||
|
# get the first existing config file
|
||||||
|
for config_path in config_paths:
|
||||||
|
if os.path.exists(config_path):
|
||||||
|
break
|
||||||
|
|
||||||
|
return config_path
|
||||||
|
|
||||||
def open_config():
|
def open_config():
|
||||||
"""
|
"""
|
||||||
Search for a configuration file at the location ~/.rtv and attempt to load
|
Search for a configuration file at the location ~/.rtv and attempt to load
|
||||||
@@ -28,18 +45,8 @@ def open_config():
|
|||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
HOME = os.path.expanduser('~')
|
config_path = get_config_fp()
|
||||||
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config'))
|
config.read(config_path)
|
||||||
config_paths = [
|
|
||||||
os.path.join(XDG_CONFIG_HOME, 'rtv', 'rtv.cfg'),
|
|
||||||
os.path.join(HOME, '.rtv')
|
|
||||||
]
|
|
||||||
|
|
||||||
# read only the first existing config file
|
|
||||||
for config_path in config_paths:
|
|
||||||
if os.path.exists(config_path):
|
|
||||||
config.read(config_path)
|
|
||||||
break
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@@ -66,9 +73,14 @@ def load_oauth_config():
|
|||||||
|
|
||||||
config = open_config()
|
config = open_config()
|
||||||
|
|
||||||
defaults = {}
|
|
||||||
if config.has_section('oauth'):
|
if config.has_section('oauth'):
|
||||||
defaults = dict(config.items('oauth'))
|
defaults = dict(config.items('oauth'))
|
||||||
|
else:
|
||||||
|
# Populate OAuth section
|
||||||
|
config['oauth'] = {'auto_login': False}
|
||||||
|
with open(get_config_fp(), 'w') as cfg:
|
||||||
|
config.write(cfg)
|
||||||
|
defaults = dict(config.items('oauth'))
|
||||||
|
|
||||||
return defaults
|
return defaults
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user