diff --git a/task_manager.py b/task_manager.py index 733db46..6d36541 100644 --- a/task_manager.py +++ b/task_manager.py @@ -1,13 +1,12 @@ # -*- coding: UTF-8 -*- import json -import os import pbclient import pyutil import requests -import shutil import logging + class task_creator(): def __init__(self, json_data): self.data = {} @@ -30,23 +29,23 @@ class task_creator(): pbclient.set('endpoint', self.data["pb_endpoint"]) def get_pb_project_id(self, pb_short_name): - projects = pbclient.find_project(short_name = pb_short_name) + projects = pbclient.find_project(short_name=pb_short_name) if (len(projects) > 0): return projects[0].id else: return None def to_string(self): - return json.dumps(self.data, sort_keys = True, ensure_ascii = False, indent = 4) + return json.dumps(self.data, sort_keys=True, ensure_ascii=False, indent=4) def __get__(self, endpoint): try: - r = requests.get(('http://%s:%s/%s' % (self.data["db_host"], self.data["db_port"], endpoint)), timeout = self.data["db_timeout"]) + r = requests.get(('http://%s:%s/%s' % (self.data["db_host"], self.data["db_port"], endpoint)), timeout=self.data["db_timeout"]) return r except: return {} - def get_newtasks(self, selo = None): + def get_newtasks(self, selo=None): url = "newtasks?task_manager_alive=true" if (isinstance(selo, int)): url += "?selo=%d" % (selo) @@ -79,35 +78,45 @@ class task_creator(): blend_file = i["blender"] video_ref = i["file"] video_ava = i["avatar"] + proj_name = None + proj_id = None + if (id_selo == 7): - proj_name = "wikilibras"; + proj_name = "wikilibras" elif (id_selo == 4): - proj_name = "corretor"; - elif ((id_selo == 1) or (id_selo == 5)): - proj_name = "validador"; + proj_name = "corretor" + elif (id_selo in [1, 5]): + proj_name = "validador" else: continue + proj_id = self.data[proj_name]["project_id"] public_users = "/public/users" - if (usuario != None): + + if (usuario is not None): public_users += "/" + usuario - if (estado != None): + if (estado is not None): public_users += "/" + estado - if (classe != None): + if (classe is not None): public_users += "/" + classe + task = dict( - sign_name = nome_sinal, - submission_date = pyutil.get_date_now() + sign_name=nome_sinal, + submission_date=pyutil.get_date_now() ) - if (video_ref != None): + + if ((video_ref is not None) and (id_selo in [4, 1, 5, 7])): task["video_ref"] = ("%s/%s" % (public_users, video_ref)) - if (video_ava != None): + + if ((video_ava is not None) and (id_selo in [4, 1, 5])): task["video_ava"] = ("%s/%s" % (public_users, video_ava)) - if (blend_file != None): + + if ((blend_file is not None) and (id_selo in [4])): task["blend"] = ("%s/%s" % (public_users, blend_file)) + # print(repr(task).decode("unicode-escape")) - # print(json.dumps(task, ensure_ascii = True, indent = 4, sort_keys = False)) + # print(json.dumps(task, ensure_ascii=True, indent=4, sort_keys=False)) response_task = pbclient.create_task(proj_id, task) pyutil.log("[%s] created task[%d] '%s'" % (proj_name, int(response_task.id), nome_sinal)) # TODO -- libgit2 0.21.2