コード例 #1
0
    def test_set_task(self):
        id, sample = self.add_task()
        db_task = self.db.view_task(id)
        task = Task()
        task.set_task(db_task)

        assert task.id == id
        assert task.category == "file"
        assert task.path == cwd(analysis=id)
        assert task.db_task == db_task
        assert task.target == sample
        assert len(task.targets) == 1
        assert isinstance(task.targets[0], Target)
コード例 #2
0
def process_task_range(tasks):
    db, task_ids = Database(), []
    for entry in tasks.split(","):
        if entry.isdigit():
            task_ids.append(int(entry))
        elif entry.count("-") == 1:
            start, end = entry.split("-")
            if not start.isdigit() or not end.isdigit():
                log.warning("Invalid range provided: %s", entry)
                continue
            task_ids.extend(range(int(start), int(end) + 1))
        elif entry:
            log.warning("Invalid range provided: %s", entry)

    for task_id in sorted(set(task_ids)):
        db_task = db.view_task(task_id)
        task = Task()
        if not db_task:
            task_json = cwd("task.json", analysis=task_id)
            if os.path.isfile(task_json):
                task_dict = json_decode(open(task_json, "rb").read())
            else:
                task_dict = {
                    "id": task_id,
                    "category": "file",
                    "target": "",
                    "options": {},
                    "package": None,
                    "custom": None,
                }

            task.load_task_dict(task_dict)
        else:
            task.set_task(db_task)

        process_task(task)