Commit 5977687e524f1623ce4751346f2d6f467b3129ad

Authored by Erickson Silva
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,6 +13,7 @@ import os, argparse, thread, logging, sys
13 MySQLdb=None 13 MySQLdb=None
14 RUN_MODE=None 14 RUN_MODE=None
15 BUNDLES_PATH=None 15 BUNDLES_PATH=None
  16 +BUNDLES_LIST=None
16 conn=None 17 conn=None
17 lock = Lock() 18 lock = Lock()
18 app=Flask(__name__, static_url_path="", static_folder="/var/www/") 19 app=Flask(__name__, static_url_path="", static_folder="/var/www/")
@@ -37,6 +38,7 @@ def dict_mode(): @@ -37,6 +38,7 @@ def dict_mode():
37 STANDALONE_SIGNS_PATH=os.path.join(SIGNS_PATH, "STANDALONE") 38 STANDALONE_SIGNS_PATH=os.path.join(SIGNS_PATH, "STANDALONE")
38 WEBGL_SIGNS_PATH=os.path.join(SIGNS_PATH, "WEBGL") 39 WEBGL_SIGNS_PATH=os.path.join(SIGNS_PATH, "WEBGL")
39 BUNDLES_PATH={"IOS":IOS_SIGNS_PATH, "ANDROID":ANDROID_SIGNS_PATH, "STANDALONE":STANDALONE_SIGNS_PATH, "WEBGL":WEBGL_SIGNS_PATH} 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 def connect_database(): 43 def connect_database():
42 import MySQLdb as mysql 44 import MySQLdb as mysql
@@ -81,6 +83,10 @@ def init_mode(args): @@ -81,6 +83,10 @@ def init_mode(args):
81 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." 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 elif RUN_MODE == "translate": 84 elif RUN_MODE == "translate":
83 print "# Server started in translation mode.\n# Only endpoint '/translate' available." 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 def check_database(): 91 def check_database():
86 cursor = conn.cursor() 92 cursor = conn.cursor()
@@ -228,15 +234,18 @@ def load_statistics_page(): @@ -228,15 +234,18 @@ def load_statistics_page():
228 php_output = check_output(["php", page_path]) 234 php_output = check_output(["php", page_path])
229 return php_output 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 @app.route("/<platform>/<sign>", methods=['GET']) 242 @app.route("/<platform>/<sign>", methods=['GET'])
232 @check_run_mode 243 @check_run_mode
233 def get_sign(platform, sign): 244 def get_sign(platform, sign):
234 platform = platform.encode("UTF-8") 245 platform = platform.encode("UTF-8")
235 sign = sign.encode("UTF-8") 246 sign = sign.encode("UTF-8")
236 if " " in sign or platform not in BUNDLES_PATH: abort(400) 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 thread.start_new_thread(update_database_statistic, (sign, platform, file_exists)) 249 thread.start_new_thread(update_database_statistic, (sign, platform, file_exists))
241 if file_exists: 250 if file_exists:
242 return send_from_directory(BUNDLES_PATH[platform], sign) 251 return send_from_directory(BUNDLES_PATH[platform], sign)