diff --git a/.vscode/settings.json b/.vscode/settings.json index 59fa702..1de9f05 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "python.pythonPath": "/usr/bin/python3.6" + "python.pythonPath": "/usr/bin/python3.6", + "python.linting.pylintEnabled": true } \ No newline at end of file diff --git a/api/__init__.py b/api/__init__.py index 1bf7665..e69de29 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1,7 +0,0 @@ -from . import missing -from os import listdir - -versions = {} - -for d in [d for d in listdir(__name__) if d not in ["__init__.py", "__pycache__", "missing.py"]]: - versions[d] = __import__("%s.%s" % (__name__, d), fromlist=[""]) diff --git a/api/missing.py b/api/_missing.py similarity index 74% rename from api/missing.py rename to api/_missing.py index edb32b1..e308e1e 100644 --- a/api/missing.py +++ b/api/_missing.py @@ -1,7 +1,5 @@ from objects import glob -allowed_args = ["file_hash", "file_version", "timestamp"] - def handle(request): print(request) diff --git a/api/v1/__init__.py b/api/v1/__init__.py index 7156d53..e69de29 100644 --- a/api/v1/__init__.py +++ b/api/v1/__init__.py @@ -1,6 +0,0 @@ -from os import listdir - -handlers = {} - -for d in [d.rstrip(".py") for d in listdir(__name__.replace(".", "/")) if d not in ["__init__.py", "__pycache__"]]: - handlers[d] = __import__("%s.%s" % (__name__, d), fromlist=[""]) \ No newline at end of file diff --git a/api/v1/getFile.py b/api/v1/getFile.py index 171bc25..d6b4d56 100644 --- a/api/v1/getFile.py +++ b/api/v1/getFile.py @@ -1,36 +1,12 @@ +import tornado.gen +import tornado.web + from objects import glob allowed_args = ["file_hash", "file_version", "timestamp"] -def handle(request): - if len([x for x in request.args if x in allowed_args]) == 0: - return { - "error": "Missing valid args", - "allowed": allowed_args - } - - for i in range(len(allowed_args)): # Gets the first valid argument and sets it as the method handler - method = request.args.get(allowed_args[i]) - method_name = allowed_args[i] - if method is not None: - break - - return callback(method_name, request.args.get(method_name)) +def handle(requestsManager.asyncRequestHandler): + return {} def callback(method, data): - cur = glob.sql.cursor() - - if method is "timestamp": - cur.execute("SELECT * FROM updates WHERE timestamp <= '{}' ORDER BY timestamp DESC LIMIT 1".format( - data - )) - else: - query = "SELECT * FROM updates WHERE {} = {} LIMIT 1" - if method is "file_hash": - query = "SELECT * FROM updates WHERE {} = '{}' LIMIT 1" - cur.execute(query.format( - method, - data - )) - - return cur.fetchone() \ No newline at end of file + return None \ No newline at end of file diff --git a/main.py b/main.py index 93ab342..f9a31bd 100644 --- a/main.py +++ b/main.py @@ -6,29 +6,40 @@ import tornado.ioloop import tornado.web import tornado.netutil - def make_app(): - routes = [] + """ + Make tornado application instance + :return: Tornado Application instance + """ def get_files(dir): + """ + Get all file-/directory-names in a directory with a simple blacklist + + :param str: directory to read + :return: String[] of file/directory + """ return [d for d in listdir(dir) if not d.startswith("_")] - def map_out(dir): + def map_routes(dir): + """ + Map out a directory array of modules in a given directory + + :param str: directory to map out and import + :return: tuple( endpoint, module.handle )[] routes + """ + routes = [] apis = get_files(dir) for api in apis: - endpoint = "" if api.endswith(".py"): api = api.rstrip(".py") routes.append( - { - "/%s/%s" % (dir, api): __import__("%s.%s" % (dir.replace("/", "."), api), fromlist=[""]) - }) + ( + r"/%s/%s" % (dir, api), __import__("%s.%s" % (dir.replace("/", "."), api), fromlist=[""]).handle + )) else: - map_out("%s/%s" % (dir, api)) - - map_out("api") - return routes - - r"/api/%s/%s" + routes += map_routes("%s/%s" % (dir, api)) + return routes + routes = map_routes("api") return tornado.web.Application(routes) diff --git a/web/asyncTornado.py b/web/asyncTornado.py new file mode 100644 index 0000000..1f02d36 --- /dev/null +++ b/web/asyncTornado.py @@ -0,0 +1,6 @@ +import tornado +import tornado.web +import tornado.gen + +class asyncRequestHandler(tornado.web.RequestHandler): + \ No newline at end of file