Commit 5977687e524f1623ce4751346f2d6f467b3129ad
1 parent
16431795
Exists in
devel
[TranslationServer] Modifica forma de checagem dos bundles para 'set'
Showing
1 changed file
with
12 additions
and
3 deletions
Show diff stats
src/TranslationServer.py
... | ... | @@ -13,6 +13,7 @@ import os, argparse, thread, logging, sys |
13 | 13 | MySQLdb=None |
14 | 14 | RUN_MODE=None |
15 | 15 | BUNDLES_PATH=None |
16 | +BUNDLES_LIST=None | |
16 | 17 | conn=None |
17 | 18 | lock = Lock() |
18 | 19 | app=Flask(__name__, static_url_path="", static_folder="/var/www/") |
... | ... | @@ -37,6 +38,7 @@ def dict_mode(): |
37 | 38 | STANDALONE_SIGNS_PATH=os.path.join(SIGNS_PATH, "STANDALONE") |
38 | 39 | WEBGL_SIGNS_PATH=os.path.join(SIGNS_PATH, "WEBGL") |
39 | 40 | BUNDLES_PATH={"IOS":IOS_SIGNS_PATH, "ANDROID":ANDROID_SIGNS_PATH, "STANDALONE":STANDALONE_SIGNS_PATH, "WEBGL":WEBGL_SIGNS_PATH} |
41 | + list_bundles() | |
40 | 42 | |
41 | 43 | def connect_database(): |
42 | 44 | import MySQLdb as mysql |
... | ... | @@ -81,6 +83,10 @@ def init_mode(args): |
81 | 83 | 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', '/<PLATFORM>/<SIGN>' and '/statistics' are available." |
82 | 84 | elif RUN_MODE == "translate": |
83 | 85 | print "# Server started in translation mode.\n# Only endpoint '/translate' available." |
86 | + | |
87 | +def list_bundles(): | |
88 | + global BUNDLES_LIST | |
89 | + BUNDLES_LIST = set(os.listdir(BUNDLES_PATH["STANDALONE"])) | |
84 | 90 | |
85 | 91 | def check_database(): |
86 | 92 | cursor = conn.cursor() |
... | ... | @@ -228,15 +234,18 @@ def load_statistics_page(): |
228 | 234 | php_output = check_output(["php", page_path]) |
229 | 235 | return php_output |
230 | 236 | |
237 | +@app.route("/update", methods=['GET']) | |
238 | +def update_list_bundles(): | |
239 | + list_bundles() | |
240 | + return "Successfully updated list.", 200 | |
241 | + | |
231 | 242 | @app.route("/<platform>/<sign>", methods=['GET']) |
232 | 243 | @check_run_mode |
233 | 244 | def get_sign(platform, sign): |
234 | 245 | platform = platform.encode("UTF-8") |
235 | 246 | sign = sign.encode("UTF-8") |
236 | 247 | if " " in sign or platform not in BUNDLES_PATH: abort(400) |
237 | - path = BUNDLES_PATH[platform] | |
238 | - bundle_path = os.path.join(path, sign) | |
239 | - file_exists = os.path.exists(os.path.join(path, sign)) | |
248 | + file_exists = sign in BUNDLES_LIST | |
240 | 249 | thread.start_new_thread(update_database_statistic, (sign, platform, file_exists)) |
241 | 250 | if file_exists: |
242 | 251 | return send_from_directory(BUNDLES_PATH[platform], sign) | ... | ... |