Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,41 @@

import os
import yaml
from logger import configure_logger
from .account import Account


LOGGER = configure_logger(__name__)


def read_config_files(folder):
files = [os.path.join(folder, f) for f in os.listdir(folder)]
accounts = []
for filename in files:
if filename.endswith(".yml"):
with open(filename, 'r') as stream:
config = yaml.safe_load(stream)
for account in config.get('accounts', []):
accounts.append(Account.load_from_config(account))
if not filename.endswith(".yml"):
# Skipping files that do not end with .yml
continue
accounts.extend(_read_config_file(filename))

return accounts


def _read_config_file(filename):
accounts = []
try:
with open(filename, 'r') as stream:
config = yaml.safe_load(stream)
for account in config.get('accounts', []):
accounts.append(Account.load_from_config(account))
return accounts
except Exception as error:
LOGGER.error(
"Could not process %s due to an error: %s. ",
filename,
error
)
LOGGER.error(
"Make sure the content of YAML files (.yml) are not empty and "
"contain a valid YAML data structure.",
)
raise