예제 #1
0
    def _check_card(self, card: Card, done_list: List, used_resources: dict):
        print(f"Checking card {card.name}")
        pid = None
        uid = None

        for comment in card.fetch_comments():
            comment_text = comment["data"]["text"]
            if "PID:" in comment_text:
                pid = int(comment_text.split("PID:")[1].strip())
            if "UID:" in comment_text:
                uid = comment_text.split("UID:")[1].strip()

        if pid is None:
            raise ValueError(f"PID not found in card {card.name}")

        if uid is None:
            raise ValueError(f"UID not found in card {card.name}")

        if not psutil.pid_exists(pid):
            card.comment(
                f"⚠️ Warning: Could not find the process, assuming it finised."
            )
            return self._finish_card(card, done_list, used_resources, uid)

        process = psutil.Process(int(pid))

        if process.status() in [psutil.STATUS_RUNNING, psutil.STATUS_SLEEPING]:
            return

        self._finish_card(card, done_list, used_resources, uid)
예제 #2
0
    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)
예제 #3
0
 def run_task_move(self, card: Card, to_list: trello.List):
   card_labels = card.labels
   if card_labels is None:
     card_labels = []
   # find all labels need to apply after moving
   labels_to_apply: List[Label] = []
   for label in card_labels:
     label_list = self.label_mapping.get(label, [])
     labels_to_apply += label_list
   # find all members need to assign after moving
   members_to_assign: List[str] = []
   for label in card_labels:
     member_list = self.member_via_label.get(label.id, [])
     members_to_assign += member_list
   # find all comments need to make after moving
   comments_to_make: List[str] = []
   for label in card_labels:
     comment_list = self.comment_via_label.get(label.id, [])
     comments_to_make += comment_list
   # remove all members
   for member in card.idMembers:
     card.unassign(member)
   # remove all labels
   for label in card_labels:
     card.remove_label(label)
   # find comment for list
   comments_via_list = self.comment_from_list.get(card.list_id, [])
   comments_to_make += comments_via_list
   # move card
   card.change_board(to_list.board.id, to_list.id)
   # assign members
   for member in members_to_assign:
     card.assign(member)
   # label
   for label in labels_to_apply:
     try:
       card.add_label(label)
     except:
       pass
   # comment
   for comment in comments_to_make:
     card.comment(comment)
예제 #4
0
 def run_task_copy(self, card: Card, to_list: trello.List):
   card_labels = card.labels
   if card_labels is None:
     card_labels = []
   # find all labels need to apply after moving
   labels_to_apply: List[Label] = []
   for label in card_labels:
     label_list = self.label_mapping.get(label, [])
     labels_to_apply += label_list
   labels_to_apply = set([x.id for x in labels_to_apply])
   # find all members need to assign after moving
   members_to_assign: List[str] = []
   for label in card_labels:
     member_list = self.member_via_label.get(label.id, [])
     members_to_assign += member_list
   members_to_assign = set(members_to_assign)
   # find all comments need to make after moving
   comments_to_make: List[str] = []
   for label in card_labels:
     comment_list = self.comment_via_label.get(label.id, [])
     comments_to_make += comment_list
   # copy card
   new_card = copy_card(card, to_list, labels_to_apply, members_to_assign)
   # comments
   for comment in comments_to_make:
     new_card.comment(comment)
   if self.config.get('comment_original_card_share_link_to_copied_card', False):
     new_card.comment(card.short_url)
     card.comment(new_card.short_url)
   # remove mapping labels and add label via labels_to_change_with_label_mapping_labels if present
   labels_to_remove = [label for label in card_labels if label.id in self.label_to_list_mapping]
   change_label_mapping = self.config.get('labels_to_change_with_label_mapping_labels', {})
   for label in labels_to_remove:
     card.remove_label(label)
     if change_label_mapping.get(label.id, None):
       try:
         card.add_label(Label(self.client, change_label_mapping.get(label.id, None), ''))
       except:
         pass
예제 #5
0
    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}")