-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc239d9
commit 4421f55
Showing
7 changed files
with
421 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from aiohttp import web | ||
from arteria.handlers.base import base_routes | ||
|
||
archive_services_routes = web.RouteTableDef() | ||
|
||
|
||
|
||
routes = [base_routes, archive_services_routes] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import argparse | ||
|
||
from aiohttp import web | ||
from arteria.services.base_service import BaseService | ||
|
||
parser = argparse.ArgumentParser(description="archive-services server") | ||
parser.add_argument('--config_file') | ||
|
||
base_service = BaseService() | ||
def main(): | ||
config = base_service.get_config() | ||
app = base_service.get_app(config) | ||
|
||
web.run_app(app, port=config.get("port")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,15 @@ | ||
import yaml | ||
import argparse | ||
import logging.config | ||
|
||
from aiohttp import web | ||
from arteria.models.config import Config | ||
from arteria.handlers.arteria_runfolder_handlers import routes | ||
|
||
from arteria.services.base_service import BaseService | ||
|
||
parser = argparse.ArgumentParser(description="arteria-runfolder server") | ||
parser.add_argument('--config_file') | ||
|
||
|
||
base_service = BaseService() | ||
def main(): | ||
config = get_config() | ||
app = get_app(config) | ||
config = base_service.get_config() | ||
app = base_service.get_app(config) | ||
|
||
web.run_app(app, port=config.get("port")) | ||
|
||
|
||
def get_config(): | ||
""" | ||
Retrieves passed config file name | ||
Loads the config dictionary to Config | ||
""" | ||
args = parser.parse_args() | ||
config_file = args.config_file | ||
return Config().from_yaml(config_file) | ||
|
||
|
||
def get_app(config): | ||
""" | ||
Creates an Application instance | ||
Sets up logger from configuration file specified in the config | ||
Registers the request handler | ||
""" | ||
app = web.Application() | ||
inistialize_logger(config) | ||
[app.router.add_routes(route) for route in routes] | ||
return app | ||
|
||
|
||
def inistialize_logger(config): | ||
""" | ||
Sets up logger from configuration file | ||
""" | ||
logger_file = config.get("logger_config_file") | ||
try: | ||
# When config file has section headers i.e [version].. | ||
logging.config.fileConfig(logger_file) | ||
except RuntimeError: | ||
# When config file has yaml format (without section headers) | ||
with open(logger_file, 'r') as stream: | ||
config = yaml.load(stream, Loader=yaml.FullLoader) | ||
logging.config.dictConfig(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import yaml | ||
import argparse | ||
import logging.config | ||
|
||
from aiohttp import web | ||
from arteria.models.config import Config | ||
from arteria.handlers.arteria_runfolder_handlers import routes | ||
|
||
|
||
parser = argparse.ArgumentParser(description="arteria-runfolder server") | ||
parser.add_argument('--config_file') | ||
|
||
|
||
class BaseService: | ||
def main(self): | ||
config = self.get_config() | ||
app = self.get_app(config) | ||
|
||
web.run_app(app, port=config.get("port")) | ||
|
||
|
||
def get_config(self): | ||
""" | ||
Retrieves passed config file name | ||
Loads the config dictionary to Config | ||
""" | ||
args = parser.parse_args() | ||
config_file = args.config_file | ||
return Config().from_yaml(config_file) | ||
|
||
|
||
def get_app(self, config): | ||
""" | ||
Creates an Application instance | ||
Sets up logger from configuration file specified in the config | ||
Registers the request handler | ||
""" | ||
app = web.Application() | ||
self.inistialize_logger(config) | ||
[app.router.add_routes(route) for route in routes] | ||
return app | ||
|
||
|
||
def inistialize_logger(self, config): | ||
""" | ||
Sets up logger from configuration file | ||
""" | ||
logger_file = config.get("logger_config_file") | ||
try: | ||
# When config file has section headers i.e [version].. | ||
logging.config.fileConfig(logger_file) | ||
except RuntimeError: | ||
# When config file has yaml format (without section headers) | ||
with open(logger_file, 'r') as stream: | ||
config = yaml.load(stream, Loader=yaml.FullLoader) | ||
logging.config.dictConfig(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from arteria.services.base_service import BaseService | ||
|
||
|
||
@pytest.fixture() | ||
async def client(aiohttp_client, config): | ||
""" | ||
Instantiate a web client with a specific config. | ||
""" | ||
base_service = BaseService() | ||
return await aiohttp_client(base_service.get_app(config)) |
Oops, something went wrong.