Commit b9cd4fec92dfdcf4062afc576faf9bdc816297a5

Authored by Adabriand Furtado
2 parents 3ea27ec7 91524c57
Exists in master

Merge branch 'master' of https://gitlab.lavid.ufpb.br/wikilibras/validador_sinais

Showing 3 changed files with 77 additions and 52 deletions   Show diff stats
1 -PROJECT_NAME = validador  
2 -VLIBRAS_NAME = vlibras-wiki  
3 -PYBOSSA_CONF = /etc/apache2/sites-available/pybossa.conf  
4 -PROJECT_DIR = $(CURDIR)  
5 -SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)"  
6 -SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)" 1 +PROJECT_NAME = validador
  2 +VLIBRAS_WIKILIBRAS_ENV := /etc/profile.d/lavid/vlibras/wikilibras_env.sh
  3 +PROJECT_DIR := $(CURDIR)
  4 +SED_REPLACE_ALL = sed -i "s/$(1)/$(2)/g" "$(3)"
  5 +SED_REPLACE_ALL_PATH = sed -i "s\#$(1)\#$(2)\#g" "$(3)"
  6 +
  7 +-include ${VLIBRAS_WIKILIBRAS_ENV}
7 8
8 ifndef LOCALHOST 9 ifndef LOCALHOST
9 ifndef NETWORK_INTERFACE 10 ifndef NETWORK_INTERFACE
10 - NETWORK_INTERFACE := $(shell ip route | awk '{print $$5; exit}') 11 + NETWORK_INTERFACE := $(shell ip route | grep "default" | awk '{print $$5; exit}')
11 endif 12 endif
12 ifdef NETWORK_INTERFACE 13 ifdef NETWORK_INTERFACE
13 - LOCALHOST := $(shell ip addr list ${NETWORK_INTERFACE} | grep "inet " | cut -d ' ' -f6 | cut -d/ -f1) 14 + LOCALHOST ?= $(shell ip route get 1 | awk '{print $$7; exit}')
14 endif 15 endif
15 endif 16 endif
16 17
17 ifndef LOCALHOST 18 ifndef LOCALHOST
18 - LOCALHOST := localhost 19 + LOCALHOST ?= 127.0.0.1
19 endif 20 endif
20 21
21 -install: uninstall config  
22 - @( \ 22 +install: uninstall config env
  23 +
  24 +env:
  25 + @ ( \
23 virtualenv ./env/; \ 26 virtualenv ./env/; \
24 . ./env/bin/activate; \ 27 . ./env/bin/activate; \
25 pip install -U pip; \ 28 pip install -U pip; \
@@ -27,14 +30,14 @@ install: uninstall config @@ -27,14 +30,14 @@ install: uninstall config
27 pip install -U ndg-httpsclient; \ 30 pip install -U ndg-httpsclient; \
28 pip install -r requirements.txt; \ 31 pip install -r requirements.txt; \
29 ) 32 )
  33 +
  34 +create_project update_project:
  35 + @ echo "http://${LOCALHOST}/${PROJECT_NAME}-backend/$@"
30 ifdef PYBOSSA_API_KEY 36 ifdef PYBOSSA_API_KEY
31 - @ curl "http://${LOCALHOST}/${PROJECT_NAME}-backend/create_project" && echo ""  
32 - @ echo "http://${LOCALHOST}/${PROJECT_NAME}-backend/create_project" 37 + @ curl "http://${LOCALHOST}/${PROJECT_NAME}-backend/$@" && echo ""
33 endif 38 endif
34 39
35 config: 40 config:
36 - @ $(info Using interface: ${NETWORK_INTERFACE})  
37 - @ $(info Using local IP: ${LOCALHOST})  
38 @ cp settings_local.py.tmpl settings_local.py 41 @ cp settings_local.py.tmpl settings_local.py
39 @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},settings_local.py) 42 @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},settings_local.py)
40 @ $(call SED_REPLACE_ALL,localhost,${LOCALHOST},settings_local.py) 43 @ $(call SED_REPLACE_ALL,localhost,${LOCALHOST},settings_local.py)
@@ -48,32 +51,36 @@ endif @@ -48,32 +51,36 @@ endif
48 @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) 51 @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/${PROJECT_NAME}.conf)
49 @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) 52 @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/${PROJECT_NAME}.conf)
50 @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/apache/${PROJECT_NAME}.conf) 53 @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},./contrib/apache/${PROJECT_NAME}.conf)
51 - @ sudo cp -u ${PYBOSSA_CONF} /etc/apache2/sites-available/${VLIBRAS_NAME}.conf  
52 - @ if grep -q "${PROJECT_NAME}" "/etc/apache2/sites-available/${VLIBRAS_NAME}.conf"; \ 54 + @ sudo cp -u "/etc/apache2/sites-available/pybossa.conf" /etc/apache2/sites-available/wikilibras.conf
  55 + @ if grep -q "WSGIScriptAlias /${PROJECT_NAME}" "/etc/apache2/sites-available/wikilibras.conf"; \
53 then \ 56 then \
54 - echo "A previous WSGI daemon definition for '${PROJECT_NAME}' in: /etc/apache2/sites-available/${VLIBRAS_NAME}.conf"; \ 57 + echo "\33[33;1mA previous WSGI daemon definition for '${PROJECT_NAME}' in: /etc/apache2/sites-available/wikilibras.conf\33[0m"; \
55 else \ 58 else \
56 - sudo sed -i -e "/Header/,/VirtualHost>/d" /etc/apache2/sites-available/${VLIBRAS_NAME}.conf; \ 59 + sudo sed -i -e "/Header/,/VirtualHost>/d" /etc/apache2/sites-available/wikilibras.conf; \
57 sudo sed -n -e '/WSGIDaemonProcess/,/VirtualHost>/p' ./contrib/apache/${PROJECT_NAME}.conf | \ 60 sudo sed -n -e '/WSGIDaemonProcess/,/VirtualHost>/p' ./contrib/apache/${PROJECT_NAME}.conf | \
58 - sudo tee -a /etc/apache2/sites-available/${VLIBRAS_NAME}.conf > /dev/null; \ 61 + sudo tee -a /etc/apache2/sites-available/wikilibras.conf > /dev/null; \
59 fi 62 fi
  63 +
  64 +apache:
60 @ sudo a2dissite pybossa.conf 65 @ sudo a2dissite pybossa.conf
61 - @ sudo a2ensite ${VLIBRAS_NAME}.conf 66 + @ sudo a2ensite wikilibras.conf
62 @ sudo apachectl configtest 67 @ sudo apachectl configtest
  68 + @ sudo service apache2 start
63 @ sudo service apache2 reload 69 @ sudo service apache2 reload
64 70
65 clean: 71 clean:
66 @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete 72 @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete
67 73
68 -uninstall: clean 74 +uninstall:
69 @ rm -rf ./env/ 75 @ rm -rf ./env/
  76 + $(MAKE) clean
70 @ rm -f ./settings_local.py 77 @ rm -f ./settings_local.py
71 @ rm -f ./contrib/${PROJECT_NAME}.wsgi 78 @ rm -f ./contrib/${PROJECT_NAME}.wsgi
72 - @ sudo rm -f /etc/apache2/sites-available/${VLIBRAS_NAME}.conf  
73 - @ sudo rm -f /etc/apache2/sites-enabled/${VLIBRAS_NAME}.conf 79 + @ sudo rm -f /etc/apache2/sites-available/wikilibras.conf
  80 + @ sudo rm -f /etc/apache2/sites-enabled/wikilibras.conf
74 81
75 run: 82 run:
76 @ ( \ 83 @ ( \
77 . ./env/bin/activate; \ 84 . ./env/bin/activate; \
78 python main.py; \ 85 python main.py; \
79 - ) 86 + )
settings_local.py.tmpl
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
  2 +
2 # Validador Server Configuration 3 # Validador Server Configuration
3 SERVER_HOST = "localhost" 4 SERVER_HOST = "localhost"
4 SERVER_PORT = 8002 5 SERVER_PORT = 8002
@@ -12,7 +13,7 @@ APACHE_STATIC_FILES_ENDPOINT = &quot;/validador&quot; @@ -12,7 +13,7 @@ APACHE_STATIC_FILES_ENDPOINT = &quot;/validador&quot;
12 13
13 # PyBossa Configuration 14 # PyBossa Configuration
14 PYBOSSA_APP_NAME = "Validador de Sinais" 15 PYBOSSA_APP_NAME = "Validador de Sinais"
15 -PYBOSSA_APP_SHORT_NAME = "validador_sinais" 16 +PYBOSSA_APP_SHORT_NAME = "validador_sinais"
16 PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que especialistas aprovem sinais gerados pela comunidade." 17 PYBOSSA_APP_DESCRIPTION = "Esse projeto possibilitará que especialistas aprovem sinais gerados pela comunidade."
17 PYBOSSA_ENDPOINT = "http://localhost/pybossa" 18 PYBOSSA_ENDPOINT = "http://localhost/pybossa"
18 PYBOSSA_API_KEY = "my-api-key" 19 PYBOSSA_API_KEY = "my-api-key"
19 \ No newline at end of file 20 \ No newline at end of file
@@ -2,21 +2,20 @@ @@ -2,21 +2,20 @@
2 from flask import request, make_response 2 from flask import request, make_response
3 from werkzeug import secure_filename 3 from werkzeug import secure_filename
4 import pbclient 4 import pbclient
5 -import os  
6 import pyutil 5 import pyutil
7 import requests 6 import requests
8 -import tempfile 7 +
9 8
10 class Validador: 9 class Validador:
11 10
12 def __init__(self, configuration, template_env): 11 def __init__(self, configuration, template_env):
13 - self.config = configuration  
14 - self.env = template_env  
15 - self.__setup_pb_client() 12 + self.config = configuration
  13 + self.env = template_env
  14 + self.__setup_pb_client()
16 15
17 def __setup_pb_client(self): 16 def __setup_pb_client(self):
18 - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])  
19 - pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) 17 + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
  18 + pbclient.set('api_key', self.config['PYBOSSA_API_KEY'])
20 19
21 def __find_project(self, app_short_name): 20 def __find_project(self, app_short_name):
22 projects = pbclient.find_project(short_name=app_short_name) 21 projects = pbclient.find_project(short_name=app_short_name)
@@ -24,23 +23,26 @@ class Validador: @@ -24,23 +23,26 @@ class Validador:
24 23
25 def __setup_project(self, project): 24 def __setup_project(self, project):
26 self.__update_project_info(project) 25 self.__update_project_info(project)
27 - 26 +
28 def __create_tasks(self, project): 27 def __create_tasks(self, project):
29 test_signs = ["ENSINADO", "ENTANTO", "ENTENDIDO"] 28 test_signs = ["ENSINADO", "ENTANTO", "ENTENDIDO"]
30 for sign in test_signs: 29 for sign in test_signs:
31 video_ref = "/videos/" + sign + "_REF.webm" 30 video_ref = "/videos/" + sign + "_REF.webm"
32 video_ava = "/videos/" + sign + "_AVATAR.webm" 31 video_ava = "/videos/" + sign + "_AVATAR.webm"
33 - task = dict(sign_name=sign, submission_date=pyutil.get_date_now(),  
34 - video_ref=video_ref, video_ava=video_ava) 32 + task = dict(
  33 + sign_name=sign,
  34 + submission_date=pyutil.get_date_now(),
  35 + video_ref=video_ref,
  36 + video_ava=video_ava)
35 pbclient.create_task(project.id, task) 37 pbclient.create_task(project.id, task)
36 38
37 def __update_project_info(self, project): 39 def __update_project_info(self, project):
38 template = self.env.get_template('index.html') 40 template = self.env.get_template('index.html')
39 project.info['task_presenter'] = template.render( 41 project.info['task_presenter'] = template.render(
40 - server=self.config['HOST_STATIC_FILES_ENDPOINT'],  
41 - server_backend=self.config['HOST_ENDPOINT'],  
42 - app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'],  
43 - api_db_host=self.config['API_DB_HOST']) 42 + server=self.config['HOST_STATIC_FILES_ENDPOINT'],
  43 + server_backend=self.config['HOST_ENDPOINT'],
  44 + app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'],
  45 + api_db_host=self.config['API_DB_HOST'])
44 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" 46 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png"
45 project.info['sched'] = "incremental" 47 project.info['sched'] = "incremental"
46 project.info['published'] = True 48 project.info['published'] = True
@@ -92,10 +94,10 @@ class Validador: @@ -92,10 +94,10 @@ class Validador:
92 return "The task with ID=" + str(task_id) + " was closed." 94 return "The task with ID=" + str(task_id) + " was closed."
93 95
94 def get_file(self, url, filename): 96 def get_file(self, url, filename):
95 - r = requests.get(url, stream = True) 97 + r = requests.get(url, stream=True)
96 if (r.status_code == 200): 98 if (r.status_code == 200):
97 with open(filename, 'wb') as f: 99 with open(filename, 'wb') as f:
98 - for chunk in r.iter_content(chunk_size = 1024): 100 + for chunk in r.iter_content(chunk_size=1024):
99 if chunk: 101 if chunk:
100 f.write(chunk) 102 f.write(chunk)
101 return True 103 return True
@@ -109,24 +111,39 @@ class Validador: @@ -109,24 +111,39 @@ class Validador:
109 number_of_approval = int(request.form['number_of_approval']) 111 number_of_approval = int(request.form['number_of_approval'])
110 number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval']) 112 number_of_avatar_disapproval = int(request.form['number_of_avatar_disapproval'])
111 number_of_ref_disapproval = int(request.form['number_of_ref_disapproval']) 113 number_of_ref_disapproval = int(request.form['number_of_ref_disapproval'])
  114 + # pyutil.log("[VALIDADOR] number_of_approval: %d" % (number_of_approval))
  115 + # pyutil.log("[VALIDADOR] agreement_number: %d" % (agreement_number))
  116 + # pyutil.log("[VALIDADOR] number_of_avatar_disapproval: %d" % (number_of_avatar_disapproval))
112 agreement_number = self.config['AGREEMENT_NUMBER'] 117 agreement_number = self.config['AGREEMENT_NUMBER']
113 result_msg = "" 118 result_msg = ""
114 code = 200 119 code = 200
115 selo = None 120 selo = None
116 if (number_of_approval >= agreement_number): 121 if (number_of_approval >= agreement_number):
117 selo = 2 122 selo = 2
118 - result_msg = "selo was changed to 2 - especialista"  
119 - elif(number_of_avatar_disapproval >= agreement_number): 123 + elif (number_of_avatar_disapproval >= agreement_number):
120 selo = 4 124 selo = 4
121 - result_msg = "selo was changed to 4 - invalido_especialista"  
122 - elif(number_of_ref_disapproval >= agreement_number): 125 + elif (number_of_ref_disapproval >= agreement_number):
123 selo = 6 126 selo = 6
124 - result_msg = "selo was changed to 6 - invalido_animadores" 127 +
  128 + if (selo is None):
  129 + result_msg = "[VALIDADOR] The task with ID=" + str(task_id) + " didn't reach the agreement number yet."
125 else: 130 else:
126 - result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet."  
127 - if (selo != None):  
128 - values = { "nome": sign_name, "selo": selo, "wikilibras": True, "overwrite": True }  
129 - r = requests.post(("%s/gsinal" % (api_dbhost)), data = values) 131 + body = {
  132 + "nome": sign_name,
  133 + "idtask": task_id,
  134 + "selo": selo
  135 + }
  136 + r = requests.put("%s/updateselo" % (api_dbhost), data=body)
  137 + code = r.status_code
  138 + if (code == 200):
  139 + tipo_selo = dict({
  140 + 2: "especialista",
  141 + 4: "invalido_especialista",
  142 + 6: "invalido_animadores"
  143 + })
  144 + pyutil.log("[VALIDADOR] selo was changed to: %d - %s" % (selo, tipo_selo[selo]))
  145 + else:
  146 + result_msg = r.text
130 result_msg = self.__close_task(project_id, task_id) 147 result_msg = self.__close_task(project_id, task_id)
131 - pyutil.log(result_msg) 148 + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore"))
132 return make_response(result_msg, code) 149 return make_response(result_msg, code)