The user may not specify tags to assign to each release profile type in the YAML configuration file. See the README.md for more information.pull/5/head
parent
cb44ab36cb
commit
545f1ac289
@ -0,0 +1,46 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------------
|
||||||
|
def find_profile_by_name(config, profile_type):
|
||||||
|
for profile in config['profile']:
|
||||||
|
if profile['type'] == profile_type:
|
||||||
|
return profile
|
||||||
|
return None
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------------
|
||||||
|
def load_config(args, logger):
|
||||||
|
if args.config_file:
|
||||||
|
config_path = Path(args.config_file)
|
||||||
|
else:
|
||||||
|
# Look for `trash.yml` in the same directory as the main (entrypoint) python script.
|
||||||
|
config_path = Path(__name__).parent / 'trash.yml'
|
||||||
|
|
||||||
|
logger.debug(f'Using configuration file: {config_path}')
|
||||||
|
|
||||||
|
if config_path.exists():
|
||||||
|
with open(config_path, 'r') as f:
|
||||||
|
config_yaml = f.read()
|
||||||
|
load_config_string(args, logger, config_yaml)
|
||||||
|
else:
|
||||||
|
logger.debug('Config file could not be loaded because it does not exist')
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------------
|
||||||
|
def load_config_string(args, logger, config_yaml):
|
||||||
|
config = yaml.load(config_yaml, Loader=yaml.Loader)
|
||||||
|
|
||||||
|
server_name, type_name = args.type.split(':')
|
||||||
|
server_config = config[server_name]
|
||||||
|
|
||||||
|
if not args.base_uri:
|
||||||
|
args.base_uri = server_config['base_uri']
|
||||||
|
|
||||||
|
if not args.api_key:
|
||||||
|
args.api_key = server_config['api_key']
|
||||||
|
|
||||||
|
if args.subcommand == 'profile':
|
||||||
|
profile = find_profile_by_name(server_config, type_name)
|
||||||
|
if profile:
|
||||||
|
if args.tags is None:
|
||||||
|
args.tags = []
|
||||||
|
args.tags.extend(t for t in profile['tags'] if t not in args.tags)
|
@ -0,0 +1,30 @@
|
|||||||
|
from inspect import cleandoc
|
||||||
|
|
||||||
|
from app import cmd
|
||||||
|
from app.logic import config
|
||||||
|
from tests.mock_logger import MockLogger
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_tags():
|
||||||
|
yaml = cleandoc('''
|
||||||
|
sonarr:
|
||||||
|
base_uri: http://localhost:8989
|
||||||
|
api_key: a95cc792074644759fefe3ccab544f6e
|
||||||
|
profile:
|
||||||
|
- type: anime
|
||||||
|
tags:
|
||||||
|
- anime
|
||||||
|
- type: web-dl
|
||||||
|
tags:
|
||||||
|
- tv
|
||||||
|
''')
|
||||||
|
|
||||||
|
args = cmd.setup_and_parse_args(['profile', 'sonarr:anime'])
|
||||||
|
config.load_config_string(args, MockLogger(), yaml)
|
||||||
|
assert args.base_uri == 'http://localhost:8989'
|
||||||
|
assert args.api_key == 'a95cc792074644759fefe3ccab544f6e'
|
||||||
|
assert args.tags == ['anime']
|
||||||
|
|
||||||
|
args = cmd.setup_and_parse_args(['profile', 'sonarr:web-dl'])
|
||||||
|
config.load_config_string(args, MockLogger(), yaml)
|
||||||
|
assert args.tags == ['tv']
|
Loading…
Reference in new issue