def get_http_config(): """ Read configuration from multiple places and start an HTTP server. Configuration is obtain with the following priority: command line > default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser(description="Headliner is a JSON API that returns personalized content obtained from providers") parser.add_argument("--host", metavar="host", type=str, help="Hostname to bind to", default=None) parser.add_argument("--port", metavar="port", type=int, help="Port to bind to", default=None) parser.add_argument("--no-debug", action="store_true", help="Turn off debug mode", default=False) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) if options.host is not None: config.server['host'] = options.host if options.port is not None: config.server['port'] = options.port if options.no_debug is not None: config.server['debug'] = not options.no_debug return config
def setUp(self): config = read_config_file() pool = redis.ConnectionPool( host=config.redis["host"], port=config.redis["port"], db=config.redis["database"], password=config.redis["password"], ) self.client = redis.Redis(connection_pool=pool) self.store = ArticleStore(pool)
def get_periodic_shell_config(): """ Read configuration, then start a task that is periodic """ parser = argparse.ArgumentParser(description="This will populate the datastore with articles") parser.add_argument("--purge", action="store_true", help="Purge the datastore before populating", default=False) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) config.server["purge"] = options.purge return config
def get_scheduler_config(): """ Read configuration from multiple places and start an aggregator scheduler. Configuration is obtain with the following priority: default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser(description="Headliner Scheduler is a program that sends tasks periodically. Tasks are configured in headliner's configuration file.") parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) return config
def get_worker_config(): """ Read configuration from multiple places and start an aggregator worker. Configuration is obtain with the following priority: default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser(description="Headliner Worker is a program that executes tasks sent through the message broker.") parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) return config
def reads_config_from_file(self): config_file = self.create_config_file({ 'foo': { 'bar': 'baz', }, }) options = Options() options.config = config_file config = read_config_file(options) self.assertEqual(config.foo['bar'], 'baz') os.remove(config_file)
def get_http_config(): """ Read configuration from multiple places and start an HTTP server. Configuration is obtain with the following priority: command line > default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser( description= "Headliner is a JSON API that returns personalized content obtained from providers" ) parser.add_argument("--host", metavar="host", type=str, help="Hostname to bind to", default=None) parser.add_argument("--port", metavar="port", type=int, help="Port to bind to", default=None) parser.add_argument("--no-debug", action="store_true", help="Turn off debug mode", default=False) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) if options.host is not None: config.server['host'] = options.host if options.port is not None: config.server['port'] = options.port if options.no_debug is not None: config.server['debug'] = not options.no_debug return config
def get_scheduler_config(): """ Read configuration from multiple places and start an aggregator scheduler. Configuration is obtain with the following priority: default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser( description= "Headliner Scheduler is a program that sends tasks periodically. Tasks are configured in headliner's configuration file." ) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) return config
def get_worker_config(): """ Read configuration from multiple places and start an aggregator worker. Configuration is obtain with the following priority: default config path > specified json config > up.headliner.settings """ parser = argparse.ArgumentParser( description= "Headliner Worker is a program that executes tasks sent through the message broker." ) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) return config
def get_periodic_shell_config(): """ Read configuration, then start a task that is periodic """ parser = argparse.ArgumentParser( description="This will populate the datastore with articles") parser.add_argument("--purge", action="store_true", help="Purge the datastore before populating", default=False) parser.add_argument("--config", metavar="config", type=str, help="Specify a json configuration file", default=None) options = parser.parse_args() config = read_config_file(options) config.server["purge"] = options.purge return config
def setUp(self): self.app = webapp.test_client() self.config = read_config_file()
from up.headliner import Application from up.headliner.utils import read_config_file from up.headliner import http config = read_config_file() app = Application.instance(config) http.load_routes(config.server["routes"]) print "starting app" webapp = http.webapp