Commit 7f857e40144c98bfb2708b99cec0d5a813cce5bf
1 parent
96bfe4ef
Exists in
master
Ajustes na interface para o lançamento.
Showing
5 changed files
with
61 additions
and
16 deletions
Show diff stats
.gitignore
bpy_checkout.py
... | ... | @@ -15,9 +15,11 @@ def main(): |
15 | 15 | sys.exit(4) |
16 | 16 | action = None |
17 | 17 | for i in bpy.data.actions: |
18 | - if (str(i.name.upper()) == str(action_name)): | |
19 | - action = i | |
20 | - break | |
18 | + # ignore action name | |
19 | + #if (str(i.name.upper()) == str(action_name)): | |
20 | + # pass | |
21 | + action = i | |
22 | + break | |
21 | 23 | if (action == None): |
22 | 24 | sys.exit(5) |
23 | 25 | if not (action_fake_is_valid): | ... | ... |
corretor.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | + | |
2 | 3 | from flask import request, make_response |
3 | 4 | from werkzeug import secure_filename |
4 | 5 | import pbclient |
5 | 6 | import os |
6 | 7 | import pyutil |
7 | 8 | import checkout |
9 | +import requests | |
10 | +import shutil | |
11 | +import tempfile | |
8 | 12 | |
9 | 13 | class Corretor: |
10 | 14 | |
... | ... | @@ -28,7 +32,10 @@ class Corretor: |
28 | 32 | return projects[0] if len(projects) > 0 else None |
29 | 33 | |
30 | 34 | def __setup_project(self, project): |
31 | - self.__create_tasks(project) | |
35 | + self.__update_project_info(project) | |
36 | + | |
37 | + def __setup_project(self, project): | |
38 | + #self.__create_tasks(project) | |
32 | 39 | self.__update_project_info(project) |
33 | 40 | |
34 | 41 | def __create_tasks(self, project): |
... | ... | @@ -42,21 +49,21 @@ class Corretor: |
42 | 49 | project.info['task_presenter'] = template.render(server=self.config['HOST_STATIC_FILES_ENDPOINT'], server_backend=self.config['HOST_ENDPOINT'], app_shortname=self.config['PYBOSSA_APP_SHORT_NAME']) |
43 | 50 | project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" |
44 | 51 | project.info['sched'] = "incremental" |
52 | + project.info['published'] = True | |
45 | 53 | project.allow_anonymous_contributors = False |
46 | - #project.published = True | |
47 | 54 | pbclient.update_project(project) |
48 | 55 | |
49 | 56 | def __find_task(self, project_id, task_id): |
50 | 57 | tasks = pbclient.find_tasks(project_id, id=task_id) |
51 | 58 | return tasks[0] if len(tasks) > 0 else None |
52 | - | |
59 | + | |
53 | 60 | def __find_taskruns(self, project_id, task_id): |
54 | 61 | return pbclient.find_taskruns(project_id, id=task_id) |
55 | - | |
62 | + | |
56 | 63 | def __number_of_taskruns(self, project_id, task_id): |
57 | 64 | taskruns = self.__find_taskruns(project_id, task_id) |
58 | 65 | return len(taskruns) |
59 | - | |
66 | + | |
60 | 67 | def __close_task(self, project_id, task_id): |
61 | 68 | pyutil.log("Closing the task with ID=" + str(task_id) + ".") |
62 | 69 | task = self.__find_task(project_id, task_id) |
... | ... | @@ -66,19 +73,42 @@ class Corretor: |
66 | 73 | return "The task with ID=" + str(task_id) + " was closed." |
67 | 74 | |
68 | 75 | def finish_task(self): |
76 | + user_id = request.form['upload_session_id'] | |
77 | + pyutil.log(str(user_id)) | |
69 | 78 | task_id = request.form['task_id'] |
79 | + api_host = self.config['SERVER_HOST'] | |
80 | + api_dbhost = self.config['API_DB_HOST'] | |
81 | + sign_name = request.form['sign_name'] | |
70 | 82 | project_id = request.form['project_id'] |
71 | 83 | number_of_approval = int(request.form['number_of_approval']) |
72 | 84 | agreement_number = self.config['AGREEMENT_NUMBER'] |
73 | 85 | result_msg = "" |
74 | 86 | code = 200 |
75 | 87 | if (number_of_approval >= agreement_number): |
88 | + tmp_dir = tempfile.NamedTemporaryFile().name | |
89 | + if not os.path.exists(tmp_dir): | |
90 | + os.makedirs(tmp_dir) | |
91 | + blend_path = os.path.join(tmp_dir, sign_name + ".blend") | |
92 | + video_path = os.path.join(tmp_dir, sign_name + ".webm") | |
93 | + blend_url = ('http://%s/corretor/uploads/%s/%s.blend' % (api_host, user_id, sign_name)) | |
94 | + video_url = ('http://%s/corretor/uploads/%s/%s.webm' % (api_host, user_id, sign_name)) | |
95 | + blend_downloaded = self.get_file(blend_url, blend_path) | |
96 | + video_downloaded = self.get_file(video_url, video_path) | |
97 | + if (blend_downloaded and video_downloaded): | |
98 | + files_to_upload = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] | |
99 | + values = { "nome": sign_name, "selo": 5, "wikilibras": True, "overwrite": True } | |
100 | + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files_to_upload, data=values) | |
101 | + pyutil.log("Request: " + str(r)) | |
102 | + pyutil.log(str(r.headers)) | |
103 | + shutil.rmtree(tmp_dir) | |
104 | + else: | |
105 | + pyutil.log("files: %s or %s was not downloaded" % (blend_url, video_url)) | |
76 | 106 | result_msg = self.__close_task(project_id, task_id) |
77 | 107 | else: |
78 | 108 | result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." |
79 | 109 | pyutil.log(result_msg) |
80 | 110 | return make_response(result_msg, code) |
81 | - | |
111 | + | |
82 | 112 | def render_video(self): |
83 | 113 | upload_session_id = request.form['upload_session_id'] |
84 | 114 | sign_name = request.form['sign_name'] |
... | ... | @@ -125,6 +155,16 @@ class Corretor: |
125 | 155 | allowed_extensions = set(['blend']) |
126 | 156 | return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions |
127 | 157 | |
158 | + def get_file(self, url, filename): | |
159 | + r = requests.get(url, stream = True) | |
160 | + if (r.status_code == 200): | |
161 | + with open(filename, 'wb') as f: | |
162 | + for chunk in r.iter_content(chunk_size = 1024): | |
163 | + if chunk: | |
164 | + f.write(chunk) | |
165 | + return True | |
166 | + return False | |
167 | + | |
128 | 168 | def upload_file(self): |
129 | 169 | upload_session_id = request.form['upload_session_id'] |
130 | 170 | sign_name = request.form['sign_name'] | ... | ... |
requirements.txt
view/template.html
... | ... | @@ -19,13 +19,13 @@ |
19 | 19 | tarefas disponíveis! </span> <br /> |
20 | 20 | <div class="alert-actions"> |
21 | 21 | <a class="btn small" href="/">Voltar</a> <a class="btn small" |
22 | - href="/project">ou, olhar outros projetos.</a> | |
22 | + href="/pybossa/project">ou, olhar outros projetos.</a> | |
23 | 23 | </div> |
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | |
27 | 27 | <div id="main-container" class="container"> |
28 | - <div id="corretor-header"> | |
28 | + <!--div id="corretor-header"> | |
29 | 29 | <table id="table-1" class="table-responsive borderless"> |
30 | 30 | <thead"> |
31 | 31 | <tr> |
... | ... | @@ -47,7 +47,7 @@ |
47 | 47 | </tbody> |
48 | 48 | </table> |
49 | 49 | </div> |
50 | - <div class="line-separator"></div> | |
50 | + <div class="line-separator"></div--> | |
51 | 51 | <div id="corretor-container" class="row body-container"> |
52 | 52 | <div id="avatar-container" class="col-sm-6 video-container"> |
53 | 53 | <div class="row"> | ... | ... |