Support subfeeds.conf and default subfeed
This commit is contained in:
parent
ec2382e1bd
commit
a678b67019
|
@ -7,7 +7,14 @@ import traceback
|
||||||
from flask import Flask, render_template, request, jsonify, abort, redirect, url_for
|
from flask import Flask, render_template, request, jsonify, abort, redirect, url_for
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from inquisitor.configs import logger, DUNGEON_PATH, CACHE_PATH, subfeeds, init_default_logging
|
from inquisitor.configs import (
|
||||||
|
DUNGEON_PATH,
|
||||||
|
SOURCES_PATH,
|
||||||
|
CACHE_PATH,
|
||||||
|
subfeeds,
|
||||||
|
get_subfeed_overrides,
|
||||||
|
logger,
|
||||||
|
init_default_logging)
|
||||||
from inquisitor import sources, loader, timestamp
|
from inquisitor import sources, loader, timestamp
|
||||||
|
|
||||||
# Globals
|
# Globals
|
||||||
|
@ -35,9 +42,22 @@ def feed():
|
||||||
|
|
||||||
@app.route("/feed/<string:feed_name>/")
|
@app.route("/feed/<string:feed_name>/")
|
||||||
def subfeed(feed_name):
|
def subfeed(feed_name):
|
||||||
if feed_name not in subfeeds:
|
# Check for and apply subfeed overrides
|
||||||
|
subfeed_overrides = get_subfeed_overrides()
|
||||||
|
subfeed_config = subfeed_overrides or subfeeds or {}
|
||||||
|
|
||||||
|
# The built-in inquisitor subfeed contains sources not in another subfeed
|
||||||
|
if feed_name == 'inquisitor':
|
||||||
|
all_sources = os.listdir(DUNGEON_PATH)
|
||||||
|
for subfeed, sources in subfeed_config.items():
|
||||||
|
for source_name in sources:
|
||||||
|
if source_name in all_sources:
|
||||||
|
all_sources.remove(source_name)
|
||||||
|
return feed_for_sources(all_sources)
|
||||||
|
|
||||||
|
if feed_name not in subfeed_config:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
return feed_for_sources(subfeeds[feed_name])
|
return feed_for_sources(subfeed_config[feed_name])
|
||||||
|
|
||||||
def feed_for_sources(source_names):
|
def feed_for_sources(source_names):
|
||||||
# Determine exclusion filters
|
# Determine exclusion filters
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
from .resolver import data_path as DUNGEON_PATH
|
from .resolver import data_path as DUNGEON_PATH
|
||||||
from .resolver import source_path as SOURCES_PATH
|
from .resolver import source_path as SOURCES_PATH
|
||||||
from .resolver import cache_path as CACHE_PATH
|
from .resolver import cache_path as CACHE_PATH
|
||||||
from .resolver import logger, add_logging_handler, init_default_logging, subfeeds
|
from .resolver import (
|
||||||
|
logger,
|
||||||
|
subfeeds)
|
||||||
|
from .resolver import (
|
||||||
|
add_logging_handler,
|
||||||
|
init_default_logging,
|
||||||
|
get_subfeed_overrides)
|
|
@ -31,6 +31,7 @@ DEFAULT_VERBOSITY = 'false'
|
||||||
# sources within a subfeed separated by spaces
|
# sources within a subfeed separated by spaces
|
||||||
CONFIG_SUBFEEDS = 'Subfeeds'
|
CONFIG_SUBFEEDS = 'Subfeeds'
|
||||||
DEFAULT_SUBFEEDS = None
|
DEFAULT_SUBFEEDS = None
|
||||||
|
SUBFEED_CONFIG_FILE = 'subfeeds.conf'
|
||||||
|
|
||||||
|
|
||||||
def read_config_file(config_path):
|
def read_config_file(config_path):
|
||||||
|
@ -67,6 +68,18 @@ def read_config_file(config_path):
|
||||||
return accumulated_configs
|
return accumulated_configs
|
||||||
|
|
||||||
|
|
||||||
|
def parse_subfeed_value(value):
|
||||||
|
sf_defs = [sf.strip() for sf in value.split('\n') if sf.strip()]
|
||||||
|
subfeeds = {}
|
||||||
|
for sf_def in sf_defs:
|
||||||
|
if ':' not in sf_def:
|
||||||
|
raise ValueError(f'Invalid subfeed definition: {sf_def}')
|
||||||
|
sf_name, sf_sources = sf_def.split(':', maxsplit=1)
|
||||||
|
sf_sources = sf_sources.split()
|
||||||
|
subfeeds[sf_name.strip()] = [source.strip() for source in sf_sources]
|
||||||
|
return subfeeds
|
||||||
|
|
||||||
|
|
||||||
# Read envvar for config file location, with fallback to default
|
# Read envvar for config file location, with fallback to default
|
||||||
config_path = os.path.abspath(
|
config_path = os.path.abspath(
|
||||||
os.environ.get(CONFIG_ENVVAR) or
|
os.environ.get(CONFIG_ENVVAR) or
|
||||||
|
@ -105,14 +118,25 @@ is_verbose = (is_verbose == 'true')
|
||||||
|
|
||||||
subfeeds = configs.get(CONFIG_SUBFEEDS) or DEFAULT_SUBFEEDS
|
subfeeds = configs.get(CONFIG_SUBFEEDS) or DEFAULT_SUBFEEDS
|
||||||
if subfeeds:
|
if subfeeds:
|
||||||
sf_defs = [sf.strip() for sf in subfeeds.split('\n') if sf.strip()]
|
subfeeds = parse_subfeed_value(subfeeds)
|
||||||
subfeeds = {}
|
|
||||||
for sf_def in sf_defs:
|
|
||||||
if ':' not in sf_def:
|
def get_subfeed_overrides():
|
||||||
raise ValueError(f'Invalid subfeed definition: {sf_def}')
|
"""
|
||||||
sf_name, sf_sources = sf_def.split(':', maxsplit=1)
|
Check for and parse the secondary subfeed configuration file
|
||||||
sf_sources = sf_sources.split()
|
"""
|
||||||
subfeeds[sf_name.strip()] = [source.strip() for source in sf_sources]
|
path = os.path.join(source_path, SUBFEED_CONFIG_FILE)
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
return None
|
||||||
|
overrides = read_config_file(path)
|
||||||
|
if CONFIG_SUBFEEDS not in overrides:
|
||||||
|
return None
|
||||||
|
value = overrides[CONFIG_SUBFEEDS]
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
parsed_value = parse_subfeed_value(value)
|
||||||
|
return parsed_value
|
||||||
|
|
||||||
|
|
||||||
# Set up logging
|
# Set up logging
|
||||||
logger = logging.getLogger("inquisitor")
|
logger = logging.getLogger("inquisitor")
|
||||||
|
|
Loading…
Reference in New Issue