Commit d109b936 authored by A. Wilcox's avatar A. Wilcox 🦊
Browse files

Trying my best to make this not suck so bad

parent 2cc35ce9
"""The core of Emily."""
import asyncio
from collections import defaultdict
in_plugins = []
in_proto_plugins = defaultdict(list)
in_protocols = set()
in_proto_insts = []
out_plugins = []
......@@ -12,9 +14,13 @@ event_loop = asyncio.get_event_loop()
def register_in(plugin):
inst = plugin()
for protocol in plugin.PROTOCOLS:
def register_out(plugin):
......@@ -22,14 +28,11 @@ def register_out(plugin):
def run():
for proto in in_protocols:
coros = []
for proto in in_proto_insts:
coros += proto.coros()
for out in out_plugins:
coros += out.coros()
asyncio.gather(coros, loop=event_loop)
asyncio.gather(*coros, loop=event_loop)
from emily.protocols import http
from emily.protocols.http import http_handle, HTTPProtocol
import json
class GitLab:
""" Processes information from GitLab Web Hooks. """
PROTOCOLS = (http,)
def __init__(self):
def http_can_handle(headers, body):
return 'X-Gitlab-Event' in headers
def http_handle(self, request):
if 'X-Gitlab-Event' not in request.headers:
return False
def http_handle(headers, body):
return True
......@@ -70,7 +70,7 @@ class IRC:
self.network_instances[network] = netinst
def coros(self):
return [inst.connect for inst in self.network_instances.values()]
return [inst.connect() for inst in self.network_instances.values()]
def push(self, project, push):
\ No newline at end of file
"""Basic protocol handling for Emily."""
from emily.protocols.http import HTTPProtocol as http
\ No newline at end of file
from emily.protocols.http import HTTPProtocol
__all__ = [HTTPProtocol]
from aiohttp import web
import asyncio
from taillight import Signal
from emily import config
http_handle = Signal(('http', 'handle'))
class HTTPProtocol():
def __init__(self, loop):
if 'http' not in config:
......@@ -13,10 +17,10 @@ class HTTPProtocol():
# listen on port = web.Application(loop=loop)'GET', '/{project}', self.get_handler)'POST', '/{project}', self.post_handler)'GET', '/{grp}/{project}', self.get_handler)'POST', '/{grp}/{project}', self.post_handler)'GET', '/{project}', self.handler)'POST', '/{project}', self.handler)'GET', '/{grp}/{project}', self.handler)'POST', '/{grp}/{project}', self.handler)
self.server = loop.create_server(,
'', int(config['http']['port']))
......@@ -24,10 +28,11 @@ class HTTPProtocol():
def coros(self):
return [self.server]
def get_handler(self, request):
"""Handle GET."""
def handler(self, request):
"""Handle requests."""
responses = yield from http_handle.call_async(request)
def post_handler(self, request):
"""Handle POST."""
if any(responses):
return web.Response(body=b'Okay')
return web.Response(body=b'Not handled')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment