Skip to content

Commit

Permalink
style: Automatic code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 4, 2024
1 parent a84ccd7 commit 619c145
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/cuckoo/common/cape_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
import tempfile
from collections.abc import Iterable, Mapping
from pathlib import Path
from contextlib import suppress
from pathlib import Path

from lib.cuckoo.common.config import Config
from lib.cuckoo.common.constants import CUCKOO_ROOT
Expand All @@ -22,7 +22,8 @@
HAS_MALWARECONFIGS = False
HAVE_CAPE_EXTRACTORS = False
with suppress(ImportError):
from cape_parsers import load_cape_parsers, load_mwcp_parsers, load_malwareconfig_parsers # load_malduck_parsers
from cape_parsers import load_cape_parsers, load_malwareconfig_parsers, load_mwcp_parsers # load_malduck_parsers

HAS_MWCP = True
HAS_MALWARECONFIGS = True
HAVE_CAPE_EXTRACTORS = True
Expand Down Expand Up @@ -85,6 +86,7 @@

if process_cfg.CAPE_extractors.enabled:
from lib.cuckoo.common.load_extra_modules import cape_load_custom_decoders

cape_malware_parsers = {}
if HAVE_CAPE_EXTRACTORS:
cape_malware_parsers = load_cape_parsers()
Expand Down
11 changes: 5 additions & 6 deletions lib/cuckoo/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@
tasks_tags = Table(
"tasks_tags",
Base.metadata,
Column("task_id", Integer, ForeignKey("tasks.id", ondelete='cascade')),
Column("tag_id", Integer, ForeignKey("tags.id", ondelete='cascade')),
Column("task_id", Integer, ForeignKey("tasks.id", ondelete="cascade")),
Column("tag_id", Integer, ForeignKey("tags.id", ondelete="cascade")),
)


Expand Down Expand Up @@ -269,7 +269,7 @@ class Guest(Base):
manager = Column(String(255), nullable=False)
started_on = Column(DateTime(timezone=False), default=datetime.now, nullable=False)
shutdown_on = Column(DateTime(timezone=False), nullable=True)
task_id = Column(Integer, ForeignKey("tasks.id", ondelete='cascade'), nullable=False, unique=True)
task_id = Column(Integer, ForeignKey("tasks.id", ondelete="cascade"), nullable=False, unique=True)

def __repr__(self):
return f"<Guest({self.id}, '{self.name}')>"
Expand Down Expand Up @@ -2093,16 +2093,15 @@ def list_tasks(
return tasks

def check_tasks_timeout(self, timeout):
"""Find tasks which were added_on more than timeout ago and clean
"""
"""Find tasks which were added_on more than timeout ago and clean"""
tasks: List[Task] = []
ids_to_delete = []
if timeout == 0:
return
search = self.session.query(Task).filter(Task.status == TASK_PENDING).order_by(Task.added_on.desc())
tasks = search.all()
for task in tasks:
if task.added_on + timedelta(seconds = timeout) < datetime.now():
if task.added_on + timedelta(seconds=timeout) < datetime.now():
ids_to_delete.append(task.id)
if len(ids_to_delete) > 0:
self.session.query(Task).filter(Task.id.in_(ids_to_delete)).delete(synchronize_session=False)
Expand Down
2 changes: 1 addition & 1 deletion lib/cuckoo/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def do_main_loop_work(self, error_queue: queue.Queue) -> SchedulerCycleDelay:

if self.cfg.cuckoo.get("task_timeout", False):
if self.next_timeout_time < time.time():
self.next_timeout_time = time.time() + self.cfg.cuckoo.get("task_timeout_scan_interval", 30)
self.next_timeout_time = time.time() + self.cfg.cuckoo.get("task_timeout_scan_interval", 30)
with self.db.session.begin():
self.db.check_tasks_timeout(self.cfg.cuckoo.get("task_pending_timeout", 0))

Expand Down

0 comments on commit 619c145

Please sign in to comment.