corretor.py
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pbclient
import os
import pyutil
class Corretor:
def __init__(self, configuration, template_env):
self.config = configuration
self.env = template_env
pbclient.set('endpoint', self.config['PYBOSSA_ENDPOINT'])
pbclient.set('api_key', self.config['PYBOSSA_API_KEY'])
def __find_project(self, app_short_name):
projects = pbclient.find_project(short_name=app_short_name)
return projects[0] if len(projects) > 0 else None
def __setup_project(self, project):
self.__create_tasks(project)
self.__update_project_info(project)
def __create_tasks(self, project):
test_signs = ["ENSINADO", "ENTANTO", "ENTENDIDO"]
for sign in test_signs:
task = dict(sign_name=sign)
pbclient.create_task(project.id, task)
def __update_project_info(self, project):
template = self.env.get_template('template.html')
project.info['task_presenter'] = template.render(server=self.config['HOST_ENDPOINT'])
project.info['thumbnail'] = self.config['HOST_ENDPOINT'] + "/img/thumbnail.png"
pbclient.update_project(project)
def create_project(self):
app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
project = self.__find_project(app_short_name)
result_msg = ""
if (project):
result_msg = "The project " + app_short_name + " was already created."
else:
project = pbclient.create_project(self.config['PYBOSSA_APP_NAME'], app_short_name, self.config['PYBOSSA_APP_DESCRIPTION'])
if (project):
self.__setup_project(project)
result_msg = "The project " + app_short_name + " was created."
else:
result_msg = "The project " + app_short_name + " couldn't be created. Check the server log for details."
pyutil.log(result_msg)
return result_msg
def update_project(self):
app_short_name = self.config['PYBOSSA_APP_SHORT_NAME']
project = self.__find_project(app_short_name)
self.__update_project_info(project)
result_msg = "The project " + app_short_name + " was updated."
pyutil.log(result_msg)
return result_msg