Commit ffdbfb7ef641867a846da4b923d27deebc9cffa7
1 parent
6ea2d50c
Exists in
devel
Corrige identações e endpoint de estatísticas
Showing
1 changed file
with
14 additions
and
12 deletions
Show diff stats
src/TranslationServer.py
@@ -13,12 +13,12 @@ conn=None | @@ -13,12 +13,12 @@ conn=None | ||
13 | app=Flask(__name__, static_url_path="", static_folder="/var/www/") | 13 | app=Flask(__name__, static_url_path="", static_folder="/var/www/") |
14 | 14 | ||
15 | def check_run_mode(func): | 15 | def check_run_mode(func): |
16 | - @wraps(func) | ||
17 | - def decorated_function(*args, **kwargs): | ||
18 | - if RUN_MODE == "translate": | ||
19 | - abort(404) | ||
20 | - return func(*args, **kwargs) | ||
21 | - return decorated_function | 16 | + @wraps(func) |
17 | + def decorated_function(*args, **kwargs): | ||
18 | + if (RUN_MODE == "translate" or (RUN_MODE == "dict" and request.path == "/statistics")): | ||
19 | + abort(404) | ||
20 | + return func(*args, **kwargs) | ||
21 | + return decorated_function | ||
22 | 22 | ||
23 | def dict_mode(): | 23 | def dict_mode(): |
24 | global BUNDLES_PATH | 24 | global BUNDLES_PATH |
@@ -67,9 +67,10 @@ def check_database(): | @@ -67,9 +67,10 @@ def check_database(): | ||
67 | cursor.execute(create_signs_table) | 67 | cursor.execute(create_signs_table) |
68 | cursor.execute(create_platforms_table) | 68 | cursor.execute(create_platforms_table) |
69 | cursor.execute(insert_platforms_default, ("ANDROID", 0)) | 69 | cursor.execute(insert_platforms_default, ("ANDROID", 0)) |
70 | - cursor.execute(insert_platforms_default, ("IOS", 0)) | ||
71 | - cursor.execute(insert_platforms_default, ("WEBGL", 0)) | ||
72 | - cursor.execute(insert_platforms_default, ("STANDALONE", 0)) | 70 | + cursor.execute(insert_platforms_default, ("IOS", 0)) |
71 | + cursor.execute(insert_platforms_default, ("WEBGL", 0)) | ||
72 | + cursor.execute(insert_platforms_default, ("STANDALONE", 0)) | ||
73 | + conn.commit() | ||
73 | cursor.close() | 74 | cursor.close() |
74 | 75 | ||
75 | def insert_sign_db(sign_name, value, has): | 76 | def insert_sign_db(sign_name, value, has): |
@@ -122,6 +123,7 @@ def translate(): | @@ -122,6 +123,7 @@ def translate(): | ||
122 | return traduzir(text) | 123 | return traduzir(text) |
123 | 124 | ||
124 | @app.route("/statistics") | 125 | @app.route("/statistics") |
126 | +@check_run_mode | ||
125 | def load_statistics_page(): | 127 | def load_statistics_page(): |
126 | page_path = os.path.join(app.static_folder, "statistics") | 128 | page_path = os.path.join(app.static_folder, "statistics") |
127 | php_output = check_output(["php", page_path]) | 129 | php_output = check_output(["php", page_path]) |
@@ -137,7 +139,7 @@ def get_sign(): | @@ -137,7 +139,7 @@ def get_sign(): | ||
137 | if __name__ == "__main__": | 139 | if __name__ == "__main__": |
138 | parser = argparse.ArgumentParser(description='Translation server and signs download for VLibras.') | 140 | parser = argparse.ArgumentParser(description='Translation server and signs download for VLibras.') |
139 | parser.add_argument('--port', help='Port where the server will be available.', default=3000) | 141 | parser.add_argument('--port', help='Port where the server will be available.', default=3000) |
140 | - parser.add_argument("--mode", help="So that the server will work.", default="translate") | ||
141 | - args = parser.parse_args() | ||
142 | - init_mode(args) | 142 | + parser.add_argument("--mode", help="So that the server will work.", default="translate") |
143 | + args = parser.parse_args() | ||
144 | + init_mode(args) | ||
143 | app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False) | 145 | app.run(host="0.0.0.0", port=int(args.port), threaded=True, debug=False) |
144 | \ No newline at end of file | 146 | \ No newline at end of file |