def change_task_list(request, task): p = request.user.profile trello_key = p.trello_api_key trello_secret = p.trello_api_secret client = TrelloClient(api_key=trello_key, api_secret=trello_secret) todo_board = client.get_board(board_id=task.trello_id) last_list = todo_board.list_lists()[-1] card = Card(card_id=str(task.task_id), parent=todo_board) card.change_list(list_id=str(last_list.id))
def _finish_card(self, card: Card, done_list: List, used_resources: dict, uid: str): print(f"Finished card {card.name}") card.comment(f"✔️ Finished: {datetime.datetime.now()}") card.change_list(done_list.id) labels = card.labels or [] for label in labels: if label.name in used_resources: used_resources[label.name] -= 1 log_file = Path(f"{uid}.log") if log_file.exists(): with open(log_file) as fp: card.attach(name=f"{uid}.log", file=fp)
def _schedule_card( self, card: Card, board_config: dict, ongoing_list: List, used_resources: dict, ): resources = board_config.get("resources", {}) uses_resources = [] labels = card.labels or [] limit = board_config.get('limit', 0) if limit and ongoing_list.cardsCnt() >= limit: return for label in labels: if label.name in resources: uses_resources.append(label.name) for label in uses_resources: if used_resources[label] >= resources[label]: return for label in uses_resources: used_resources[label] += 1 uid = str(uuid.uuid4()) cmd = board_config["command"].format(msg=card.description, uid=uid) print(f"Scheduling card {card.name}") process = subprocess.Popen(cmd, shell=True, start_new_session=True) card.change_list(ongoing_list.id) card.comment(f"⏲ Started: {datetime.datetime.now()}") card.comment(f"💻 PID: {process.pid}") card.comment(f"🔑 UID: {uid}")