-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (38 loc) · 1.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
""" Docker Registry UI Backend """
import asyncio
import logging
import os
from types import SimpleNamespace
import sys
from sanic import Sanic
from api import api
from api.repositories import get_repositories
from api.scheduler import scheduler
from api.static import static
from helpers.data_retrieval import fetch
from helpers.init_functions import init_app, init_args, init_db
app = Sanic(__name__)
def main():
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper(),
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
if sys.platform == 'win32':
asyncio.set_event_loop(asyncio.ProactorEventLoop())
app.blueprint(api)
app.blueprint(scheduler)
app.blueprint(static)
args = init_args(sys.argv[1:])
init_db(app, args)
init_app(app, args)
logging.info("Welcome to the Docker Registry UI, I'll now retrieve the repositories for %s", args.registry)
if not args.cli:
app.run(host=args.listen, port=int(args.port), debug=args.debug)
else:
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch(app))
request = SimpleNamespace()
setattr(request, "app", app)
response = loop.run_until_complete(get_repositories(request))
print(response.body.decode("utf-8"))
if __name__ == "__main__":
main()