Commit 88ff1b6dad51da93c0999dca3302733db6a7dccb

Authored by Adabriand Furtado
2 parents 84627d9b ab285f7a
Exists in master

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

Showing 2 changed files with 54 additions and 43 deletions   Show diff stats
1 -PROJECT_NAME = corretor  
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 = corretor
  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 + )
@@ -10,17 +10,18 @@ import requests @@ -10,17 +10,18 @@ import requests
10 import shutil 10 import shutil
11 import tempfile 11 import tempfile
12 12
  13 +
13 class Corretor: 14 class Corretor:
14 15
15 def __init__(self, configuration, template_env): 16 def __init__(self, configuration, template_env):
16 - self.config = configuration  
17 - self.env = template_env  
18 - self.__setup_pb_client()  
19 - self.__setup_upload_folder() 17 + self.config = configuration
  18 + self.env = template_env
  19 + self.__setup_pb_client()
  20 + self.__setup_upload_folder()
20 21
21 def __setup_pb_client(self): 22 def __setup_pb_client(self):
22 - pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])  
23 - pbclient.set('api_key', self.config['PYBOSSA_API_KEY']) 23 + pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
  24 + pbclient.set('api_key', self.config['PYBOSSA_API_KEY'])
24 25
25 def __setup_upload_folder(self): 26 def __setup_upload_folder(self):
26 upload_folder = self.config['UPLOAD_FOLDER'] 27 upload_folder = self.config['UPLOAD_FOLDER']
@@ -41,16 +42,16 @@ class Corretor: @@ -41,16 +42,16 @@ class Corretor:
41 video_ava = "/videos/" + sign + "_AVATAR.webm" 42 video_ava = "/videos/" + sign + "_AVATAR.webm"
42 blend = "/videos/" + sign + "_AVATAR.blend" 43 blend = "/videos/" + sign + "_AVATAR.blend"
43 task = dict(sign_name=sign, submission_date=pyutil.get_date_now(), 44 task = dict(sign_name=sign, submission_date=pyutil.get_date_now(),
44 - video_ref=video_ref, video_ava=video_ava, blend=blend) 45 + video_ref=video_ref, video_ava=video_ava, blend=blend)
45 pbclient.create_task(project.id, task) 46 pbclient.create_task(project.id, task)
46 47
47 def __update_project_info(self, project): 48 def __update_project_info(self, project):
48 template = self.env.get_template('index.html') 49 template = self.env.get_template('index.html')
49 project.info['task_presenter'] = template.render( 50 project.info['task_presenter'] = template.render(
50 - server=self.config['HOST_STATIC_FILES_ENDPOINT'],  
51 - server_backend=self.config['HOST_ENDPOINT'],  
52 - app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'],  
53 - api_db_host=self.config['API_DB_HOST']) 51 + server=self.config['HOST_STATIC_FILES_ENDPOINT'],
  52 + server_backend=self.config['HOST_ENDPOINT'],
  53 + app_shortname=self.config['PYBOSSA_APP_SHORT_NAME'],
  54 + api_db_host=self.config['API_DB_HOST'])
54 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" 55 project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png"
55 project.info['sched'] = "incremental" 56 project.info['sched'] = "incremental"
56 project.info['published'] = True 57 project.info['published'] = True
@@ -104,21 +105,24 @@ class Corretor: @@ -104,21 +105,24 @@ class Corretor:
104 pyutil.log("video file: %s was not downloaded" % (video_url)) 105 pyutil.log("video file: %s was not downloaded" % (video_url))
105 else: 106 else:
106 files_to_upload = [ 107 files_to_upload = [
107 - ("video", (video_path, open(video_path,"rb"))), 108 + ("video", (video_path, open(video_path, "rb"))),
108 ("video", (blend_path, open(blend_path, "rb"))) 109 ("video", (blend_path, open(blend_path, "rb")))
109 ] 110 ]
110 body = { 111 body = {
111 "nome": sign_name, 112 "nome": sign_name,
112 - "idTask": task_id, 113 + "idtask": task_id,
113 "selo": 5 114 "selo": 5
114 } 115 }
115 r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files_to_upload, data=body) 116 r = requests.post(("%s/updatesinal" % (api_dbhost)), files=files_to_upload, data=body)
116 - pyutil.log(r.text) 117 + code = r.status_code
  118 + if (code == 200):
  119 + result_msg = self.__close_task(project_id, task_id)
  120 + else:
  121 + result_msg = r.text
117 shutil.rmtree(tmp_dir) 122 shutil.rmtree(tmp_dir)
118 - result_msg = self.__close_task(project_id, task_id)  
119 else: 123 else:
120 result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." 124 result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet."
121 - pyutil.log(result_msg) 125 + pyutil.log(str(result_msg).encode("UTF-8", errors="ignore"))
122 return make_response(result_msg, code) 126 return make_response(result_msg, code)
123 127
124 def render_video(self): 128 def render_video(self):
@@ -169,10 +173,10 @@ class Corretor: @@ -169,10 +173,10 @@ class Corretor:
169 return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions 173 return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions
170 174
171 def get_file(self, url, filename): 175 def get_file(self, url, filename):
172 - r = requests.get(url, stream = True) 176 + r = requests.get(url, stream=True)
173 if (r.status_code == 200): 177 if (r.status_code == 200):
174 with open(filename, 'wb') as f: 178 with open(filename, 'wb') as f:
175 - for chunk in r.iter_content(chunk_size = 1024): 179 + for chunk in r.iter_content(chunk_size=1024):
176 if chunk: 180 if chunk:
177 f.write(chunk) 181 f.write(chunk)
178 return True 182 return True