#84 Update how we run the application to latest aiohttp.
Merged 5 years ago by pingou. Opened 5 years ago by cverna.
cverna/mdapi update_aiohttp  into  master

file modified
+2 -11
@@ -1,14 +1,5 @@ 

  #!/usr/bin/env python3

  

- import asyncio

- import mdapi

- 

- 

- loop = asyncio.get_event_loop()

- loop.run_until_complete(mdapi.init(loop))

- 

- try:

-     loop.run_forever()

- except KeyboardInterrupt:

-     pass

+ from mdapi.server import main

  

+ main()

file modified
+5 -41
@@ -25,20 +25,15 @@ 

  import functools

  import json

  import logging

- import logging.config

  import os

- import urllib

- from urllib.parse import parse_qs

  

  import asyncio

  import werkzeug

  from aiohttp import web

- from multidict import MultiDict

  

  import mdapi.lib as mdapilib

  

  

- 

  CONFIG = dict()

  obj = werkzeug.import_string('mdapi.default_config')

  for key in dir(obj):
@@ -75,7 +70,7 @@ 

  

          '''

          response = yield from function(request, *args, **kwargs)

-         url_arg = parse_qs(request.query_string)

+         url_arg = request.query

          callback = url_arg.get('callback')

          if callback and request.method == 'GET':

              if isinstance(callback, list):
@@ -139,11 +134,9 @@ 

  

  def _get_pretty(request):

      pretty = False

-     get_params = MultiDict(urllib.parse.parse_qsl(

-         request.query_string.lower()))

-     if get_params.get('pretty'):

-         if str(get_params.get('pretty', None)) in ['1', 'true']:

-             pretty = True

+     params = request.query

+     if params.get('pretty') in ['1', 'true']:

+         pretty = True

      # Assume pretty if html is requested and pretty is not disabled

      elif 'text/html' in request.headers.get('ACCEPT', ''):

          pretty = True
@@ -336,7 +329,7 @@ 

      # I am not really sure what doesn't work but it seems this endpoint is

      # returning an object instead of the expected generator despite it being

      # flagged as an asyncio coroutine

-     url_arg = parse_qs(request.query_string)

+     url_arg = request.query

      callback = url_arg.get('callback')

      if callback and request.method == 'GET':

          if isinstance(callback, list):
@@ -451,32 +444,3 @@ 

      for route in routes:

          app.router.add_route('GET', prefix + route[0], route[1])

      return app

- 

- 

- @asyncio.coroutine

- def init(loop):

-     logging.basicConfig()

-     logging.config.dictConfig(CONFIG.get('LOGGING') or {'version': 1})

- 

-     app = web.Application(loop=loop)

-     app = _set_routes(app)

- 

-     srv = yield from loop.create_server(

-         app.make_handler(),

-         CONFIG.get('HOST', '127.0.0.1'),

-         CONFIG.get('PORT', 8080))

-     print(

-         "Server started at http://%s:%s" % (

-             CONFIG.get('HOST', '127.0.0.1'),

-             CONFIG.get('PORT', 8080))

-     )

-     return srv

- 

- 

- if __name__ == '__main__':

-     loop = asyncio.get_event_loop()

-     loop.run_until_complete(init(loop))

-     try:

-         loop.run_forever()

-     except KeyboardInterrupt:

-         pass

file added
+20
@@ -0,0 +1,20 @@ 

+ import logging

+ import logging.config

+ 

+ from aiohttp import web

+ 

+ from mdapi import CONFIG, _set_routes

+ 

+ 

+ def main():

+ 

+     logging.basicConfig()

+     logging.config.dictConfig(CONFIG.get("LOGGING") or {"version": 1})

+ 

+     app = web.Application()

+     app = _set_routes(app)

+ 

+     host = CONFIG.get("HOST", "127.0.0.1")

+     port = CONFIG.get("PORT", 8080)

+ 

+     web.run_app(app, host=host, port=port)

file modified
+1 -2
@@ -1,7 +1,6 @@ 

- aiohttp

+ aiohttp >= 3.5.4

  fedora_messaging

  # this is a requirement of aiohttp but better safe than sorry

- multidict

  requests

  sqlalchemy

  werkzeug

file modified
+1 -1
@@ -149,7 +149,7 @@ 

      ("conflicts", "mariadb", 200),

      ("enhances", "httpd", 200),

      ("recommends", "flac", 200),

-     ("suggests", "R-tools", 200),

+     ("suggests", "httpd", 200),

      ("supplements", "(hunspell and langpacks-fr)", 200),

  ])

  async def test_view_property_koji(cli, action, package, status_code):

This commit updates how we run mdapi, aiohttp makes it easier to
start the application without having to deal with the event loop.
In this commit we also create a dedicated server module which job
is to start the application.

Signed-off-by: Clement Verna cverna@tutanota.com

rebased onto 0a38322afd8aab3b2d236954609f257ab972de05

5 years ago

Should we add a minimal version of aiohttp supported?

rebased onto 93980dc7050e3e78fb15d4c0f569745c7149a2b2

5 years ago

Should we add a minimal version of aiohttp supported?

updated :-)

rebased onto 90adfc3

5 years ago

Pull-Request has been merged by pingou

5 years ago