diff --git a/toot/config.py b/toot/config.py index 565293a..c11a4ee 100644 --- a/toot/config.py +++ b/toot/config.py @@ -7,7 +7,6 @@ from functools import wraps from os.path import dirname from toot import User, App -from toot.config_legacy import load_legacy_config from toot.exceptions import ConsoleError from toot.output import print_out @@ -31,20 +30,11 @@ def user_id(user): def make_config(path): - """Creates a config file. - - Attempts to load data from legacy config files if they exist. - """ - apps, user = load_legacy_config() - - apps = {a.instance: a._asdict() for a in apps} - users = {user_id(user): user._asdict()} if user else {} - active_user = user_id(user) if user else None - + """Creates an empty toot configuration file.""" config = { - "apps": apps, - "users": users, - "active_user": active_user, + "apps": {}, + "users": {}, + "active_user": None, } print_out("Creating config file at {}".format(path)) diff --git a/toot/config_legacy.py b/toot/config_legacy.py deleted file mode 100644 index d5e21a6..0000000 --- a/toot/config_legacy.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- - -import os - -from . import User, App - -# The dir where all toot configuration is stored -CONFIG_DIR = os.environ['HOME'] + '/.config/toot/' - -# Subfolder where application access keys for various instances are stored -INSTANCES_DIR = CONFIG_DIR + 'instances/' - -# File in which user access token is stored -CONFIG_USER_FILE = CONFIG_DIR + 'user.cfg' - - -def load_user(path): - if not os.path.exists(path): - return None - - with open(path, 'r') as f: - lines = f.read().split() - try: - return User(*lines) - except TypeError: - return None - - -def load_apps(path): - if not os.path.exists(path): - return [] - - for name in os.listdir(path): - with open(path + name) as f: - values = f.read().split() - try: - yield App(*values) - except TypeError: - pass - - -def add_username(user, apps): - """When using broser login, username was not stored so look it up""" - if not user: - return None - - apps = [a for a in apps if a.instance == user.instance] - - if not apps: - return None - - from toot.api import verify_credentials - creds = verify_credentials(apps.pop(), user) - - return User(user.instance, creds['username'], user.access_token) - - -def load_legacy_config(): - apps = list(load_apps(INSTANCES_DIR)) - user = load_user(CONFIG_USER_FILE) - user = add_username(user, apps) - - return apps, user