2016-05-06 23:20:59 -04:00
|
|
|
"""
|
|
|
|
Given a configuration file, set up everything needed to kick
|
|
|
|
off the server.
|
|
|
|
"""
|
|
|
|
from importlib import import_module
|
|
|
|
import yaml
|
|
|
|
from pyramid.config import Configurator
|
2016-05-07 11:09:55 -04:00
|
|
|
from os.path import expanduser, join
|
2016-05-06 23:20:59 -04:00
|
|
|
|
|
|
|
# Needed for import_module call
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
|
|
import modules
|
|
|
|
|
|
|
|
|
2016-05-07 11:09:55 -04:00
|
|
|
def build_configuration(conf=None) -> Configurator:
|
|
|
|
if conf is None:
|
|
|
|
conf = join(expanduser('~'), '.repodrc')
|
2016-05-06 23:20:59 -04:00
|
|
|
|
|
|
|
with open(conf) as conf_file:
|
|
|
|
conf_dict = yaml.load(conf_file)
|
|
|
|
server_conf = Configurator()
|
|
|
|
for mountpoint, feed in conf_dict.items():
|
|
|
|
feed_package = import_module('modules.' + feed['package'])
|
|
|
|
feed_class = getattr(feed_package, feed['class'])
|
|
|
|
feed_instance = feed_class(**feed['args'])
|
|
|
|
|
|
|
|
server_conf.add_route(mountpoint, '/' + mountpoint + '/')
|
|
|
|
server_conf.add_view(feed_instance.view, route_name=mountpoint)
|
|
|
|
|
|
|
|
return server_conf
|