diff --git a/src/TranslationServer.py b/src/TranslationServer.py index 529dc25..18e9d40 100644 --- a/src/TranslationServer.py +++ b/src/TranslationServer.py @@ -13,6 +13,7 @@ import os, argparse, thread, logging, sys MySQLdb=None RUN_MODE=None BUNDLES_PATH=None +BUNDLES_LIST=None conn=None lock = Lock() app=Flask(__name__, static_url_path="", static_folder="/var/www/") @@ -37,6 +38,7 @@ def dict_mode(): STANDALONE_SIGNS_PATH=os.path.join(SIGNS_PATH, "STANDALONE") WEBGL_SIGNS_PATH=os.path.join(SIGNS_PATH, "WEBGL") BUNDLES_PATH={"IOS":IOS_SIGNS_PATH, "ANDROID":ANDROID_SIGNS_PATH, "STANDALONE":STANDALONE_SIGNS_PATH, "WEBGL":WEBGL_SIGNS_PATH} + list_bundles() def connect_database(): import MySQLdb as mysql @@ -81,6 +83,10 @@ def init_mode(args): print "# Server started in full mode. Requests will be accepted for translation of texts, download bundles. All bundles requests will be stored in a database.\n# Endpoints '/translate', '//' and '/statistics' are available." elif RUN_MODE == "translate": print "# Server started in translation mode.\n# Only endpoint '/translate' available." + +def list_bundles(): + global BUNDLES_LIST + BUNDLES_LIST = set(os.listdir(BUNDLES_PATH["STANDALONE"])) def check_database(): cursor = conn.cursor() @@ -228,15 +234,18 @@ def load_statistics_page(): php_output = check_output(["php", page_path]) return php_output +@app.route("/update", methods=['GET']) +def update_list_bundles(): + list_bundles() + return "Successfully updated list.", 200 + @app.route("//", methods=['GET']) @check_run_mode def get_sign(platform, sign): platform = platform.encode("UTF-8") sign = sign.encode("UTF-8") if " " in sign or platform not in BUNDLES_PATH: abort(400) - path = BUNDLES_PATH[platform] - bundle_path = os.path.join(path, sign) - file_exists = os.path.exists(os.path.join(path, sign)) + file_exists = sign in BUNDLES_LIST thread.start_new_thread(update_database_statistic, (sign, platform, file_exists)) if file_exists: return send_from_directory(BUNDLES_PATH[platform], sign) -- libgit2 0.21.2