From 7f857e40144c98bfb2708b99cec0d5a813cce5bf Mon Sep 17 00:00:00 2001 From: wikilibras Date: Tue, 3 May 2016 18:03:33 -0300 Subject: [PATCH] Ajustes na interface para o lançamento. --- .gitignore | 8 +++++--- bpy_checkout.py | 8 +++++--- corretor.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ requirements.txt | 3 ++- view/template.html | 6 +++--- 5 files changed, 61 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a1537e9..d610f62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,13 @@ .* +!*.gitignore +!*.gitempty *~ -!.gitignore -!.gitempty *.log *.pyc +corretor.conf +corretor.wsgi settings_local.py env/ -video/* +videos/ tmp/ uploads/ diff --git a/bpy_checkout.py b/bpy_checkout.py index c4c04c5..77b35f2 100644 --- a/bpy_checkout.py +++ b/bpy_checkout.py @@ -15,9 +15,11 @@ def main(): sys.exit(4) action = None for i in bpy.data.actions: - if (str(i.name.upper()) == str(action_name)): - action = i - break + # ignore action name + #if (str(i.name.upper()) == str(action_name)): + # pass + action = i + break if (action == None): sys.exit(5) if not (action_fake_is_valid): diff --git a/corretor.py b/corretor.py index 977e451..3308b6b 100644 --- a/corretor.py +++ b/corretor.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- + from flask import request, make_response from werkzeug import secure_filename import pbclient import os import pyutil import checkout +import requests +import shutil +import tempfile class Corretor: @@ -28,7 +32,10 @@ class Corretor: return projects[0] if len(projects) > 0 else None def __setup_project(self, project): - self.__create_tasks(project) + self.__update_project_info(project) + + def __setup_project(self, project): + #self.__create_tasks(project) self.__update_project_info(project) def __create_tasks(self, project): @@ -42,21 +49,21 @@ class Corretor: 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']) project.info['thumbnail'] = self.config['HOST_STATIC_FILES_ENDPOINT'] + "/img/thumbnail.png" project.info['sched'] = "incremental" + project.info['published'] = True project.allow_anonymous_contributors = False - #project.published = True pbclient.update_project(project) def __find_task(self, project_id, task_id): tasks = pbclient.find_tasks(project_id, id=task_id) return tasks[0] if len(tasks) > 0 else None - + def __find_taskruns(self, project_id, task_id): return pbclient.find_taskruns(project_id, id=task_id) - + def __number_of_taskruns(self, project_id, task_id): taskruns = self.__find_taskruns(project_id, task_id) return len(taskruns) - + def __close_task(self, project_id, task_id): pyutil.log("Closing the task with ID=" + str(task_id) + ".") task = self.__find_task(project_id, task_id) @@ -66,19 +73,42 @@ class Corretor: return "The task with ID=" + str(task_id) + " was closed." def finish_task(self): + user_id = request.form['upload_session_id'] + pyutil.log(str(user_id)) task_id = request.form['task_id'] + api_host = self.config['SERVER_HOST'] + api_dbhost = self.config['API_DB_HOST'] + sign_name = request.form['sign_name'] project_id = request.form['project_id'] number_of_approval = int(request.form['number_of_approval']) agreement_number = self.config['AGREEMENT_NUMBER'] result_msg = "" code = 200 if (number_of_approval >= agreement_number): + tmp_dir = tempfile.NamedTemporaryFile().name + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + blend_path = os.path.join(tmp_dir, sign_name + ".blend") + video_path = os.path.join(tmp_dir, sign_name + ".webm") + blend_url = ('http://%s/corretor/uploads/%s/%s.blend' % (api_host, user_id, sign_name)) + video_url = ('http://%s/corretor/uploads/%s/%s.webm' % (api_host, user_id, sign_name)) + blend_downloaded = self.get_file(blend_url, blend_path) + video_downloaded = self.get_file(video_url, video_path) + if (blend_downloaded and video_downloaded): + files_to_upload = [ ("video", (video_path, open(video_path,"rb"))), ("video", (blend_path, open(blend_path, "rb"))) ] + values = { "nome": sign_name, "selo": 5, "wikilibras": True, "overwrite": True } + r = requests.post(("%s/addsinal" % (api_dbhost)), files=files_to_upload, data=values) + pyutil.log("Request: " + str(r)) + pyutil.log(str(r.headers)) + shutil.rmtree(tmp_dir) + else: + pyutil.log("files: %s or %s was not downloaded" % (blend_url, video_url)) result_msg = self.__close_task(project_id, task_id) else: result_msg = "The task with ID=" + str(task_id) + " didn't reach the agreement number yet." pyutil.log(result_msg) return make_response(result_msg, code) - + def render_video(self): upload_session_id = request.form['upload_session_id'] sign_name = request.form['sign_name'] @@ -125,6 +155,16 @@ class Corretor: allowed_extensions = set(['blend']) return '.' in filename and filename.rsplit('.', 1)[1] in allowed_extensions + def get_file(self, url, filename): + r = requests.get(url, stream = True) + if (r.status_code == 200): + with open(filename, 'wb') as f: + for chunk in r.iter_content(chunk_size = 1024): + if chunk: + f.write(chunk) + return True + return False + def upload_file(self): upload_session_id = request.form['upload_session_id'] sign_name = request.form['sign_name'] diff --git a/requirements.txt b/requirements.txt index 28647d4..241ea2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask==0.9 pybossa-client -flask-cors \ No newline at end of file +flask-cors +requests >= 1.2 diff --git a/view/template.html b/view/template.html index 10bc3ea..74faf49 100755 --- a/view/template.html +++ b/view/template.html @@ -19,13 +19,13 @@ tarefas disponíveis!
Voltar ou, olhar outros projetos. + href="/pybossa/project">ou, olhar outros projetos.
-
+
-- libgit2 0.21.2