Commit 88ff1b6dad51da93c0999dca3302733db6a7dccb
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
Makefile
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 | 9 | ifndef LOCALHOST |
9 | 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 | 12 | endif |
12 | 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 | 15 | endif |
15 | 16 | endif |
16 | 17 | |
17 | 18 | ifndef LOCALHOST |
18 | - LOCALHOST := localhost | |
19 | + LOCALHOST ?= 127.0.0.1 | |
19 | 20 | endif |
20 | 21 | |
21 | -install: uninstall config | |
22 | - @( \ | |
22 | +install: uninstall config env | |
23 | + | |
24 | +env: | |
25 | + @ ( \ | |
23 | 26 | virtualenv ./env/; \ |
24 | 27 | . ./env/bin/activate; \ |
25 | 28 | pip install -U pip; \ |
... | ... | @@ -27,14 +30,14 @@ install: uninstall config |
27 | 30 | pip install -U ndg-httpsclient; \ |
28 | 31 | pip install -r requirements.txt; \ |
29 | 32 | ) |
33 | + | |
34 | +create_project update_project: | |
35 | + @ echo "http://${LOCALHOST}/${PROJECT_NAME}-backend/$@" | |
30 | 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 | 38 | endif |
34 | 39 | |
35 | 40 | config: |
36 | - @ $(info Using interface: ${NETWORK_INTERFACE}) | |
37 | - @ $(info Using local IP: ${LOCALHOST}) | |
38 | 41 | @ cp settings_local.py.tmpl settings_local.py |
39 | 42 | @ $(call SED_REPLACE_ALL_PATH,<path-to-project>,${PROJECT_DIR},settings_local.py) |
40 | 43 | @ $(call SED_REPLACE_ALL,localhost,${LOCALHOST},settings_local.py) |
... | ... | @@ -48,32 +51,36 @@ endif |
48 | 51 | @ $(call SED_REPLACE_ALL,user1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) |
49 | 52 | @ $(call SED_REPLACE_ALL,group1,$$USER,./contrib/apache/${PROJECT_NAME}.conf) |
50 | 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 | 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 | 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 | 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 | 62 | fi |
63 | + | |
64 | +apache: | |
60 | 65 | @ sudo a2dissite pybossa.conf |
61 | - @ sudo a2ensite ${VLIBRAS_NAME}.conf | |
66 | + @ sudo a2ensite wikilibras.conf | |
62 | 67 | @ sudo apachectl configtest |
68 | + @ sudo service apache2 start | |
63 | 69 | @ sudo service apache2 reload |
64 | 70 | |
65 | 71 | clean: |
66 | 72 | @ find . -regextype posix-awk -regex "(.*.log|.*.pyc)" -type f -print -delete |
67 | 73 | |
68 | -uninstall: clean | |
74 | +uninstall: | |
69 | 75 | @ rm -rf ./env/ |
76 | + $(MAKE) clean | |
70 | 77 | @ rm -f ./settings_local.py |
71 | 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 | 82 | run: |
76 | 83 | @ ( \ |
77 | 84 | . ./env/bin/activate; \ |
78 | 85 | python main.py; \ |
79 | - ) | |
86 | + ) | ... | ... |
corretor.py
... | ... | @@ -10,17 +10,18 @@ import requests |
10 | 10 | import shutil |
11 | 11 | import tempfile |
12 | 12 | |
13 | + | |
13 | 14 | class Corretor: |
14 | 15 | |
15 | 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 | 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 | 26 | def __setup_upload_folder(self): |
26 | 27 | upload_folder = self.config['UPLOAD_FOLDER'] |
... | ... | @@ -41,16 +42,16 @@ class Corretor: |
41 | 42 | video_ava = "/videos/" + sign + "_AVATAR.webm" |
42 | 43 | blend = "/videos/" + sign + "_AVATAR.blend" |
43 | 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 | 46 | pbclient.create_task(project.id, task) |
46 | 47 | |
47 | 48 | def __update_project_info(self, project): |
48 | 49 | template = self.env.get_template('index.html') |
49 | 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 | 55 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
55 | 56 | project.info['sched'] = "incremental" |
56 | 57 | project.info['published'] = True |
... | ... | @@ -104,21 +105,24 @@ class Corretor: |
104 | 105 | pyutil.log("video file: %s was not downloaded" % (video_url)) |
105 | 106 | else: |
106 | 107 | files_to_upload = [ |
107 | - ("video", (video_path, open(video_path,"rb"))), | |
108 | + ("video", (video_path, open(video_path, "rb"))), | |
108 | 109 | ("video", (blend_path, open(blend_path, "rb"))) |
109 | 110 | ] |
110 | 111 | body = { |
111 | 112 | "nome": sign_name, |
112 | - "idTask": task_id, | |
113 | + "idtask": task_id, | |
113 | 114 | "selo": 5 |
114 | 115 | } |
115 | 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 | 122 | shutil.rmtree(tmp_dir) |
118 | - result_msg = self.__close_task(project_id, task_id) | |
119 | 123 | else: |
120 | 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 | 126 | return make_response(result_msg, code) |
123 | 127 | |
124 | 128 | def render_video(self): |
... | ... | @@ -169,10 +173,10 @@ class Corretor: |
169 | 173 | return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions |
170 | 174 | |
171 | 175 | def get_file(self, url, filename): |
172 | - r = requests.get(url, stream = True) | |
176 | + r = requests.get(url, stream=True) | |
173 | 177 | if (r.status_code == 200): |
174 | 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 | 180 | if chunk: |
177 | 181 | f.write(chunk) |
178 | 182 | return True | ... | ... |