Skip to content

Commit

Permalink
Merge branch 'bbot-2.0' into new-presets
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidsec authored Jun 18, 2024
2 parents 4bc9398 + b229d45 commit 25e5a69
Show file tree
Hide file tree
Showing 232 changed files with 8,277 additions and 3,737 deletions.
2 changes: 2 additions & 0 deletions bbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# version placeholder (replaced by poetry-dynamic-versioning)
__version__ = "v0.0.0"

from .scanner import Scanner, Preset
2 changes: 0 additions & 2 deletions bbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ async def _main():

# start by creating a default scan preset
preset = Preset(_log=True, name="bbot_cli_main")
# populate preset symlinks
preset.all_presets
# parse command line arguments and merge into preset
try:
preset.parse_args()
Expand Down
1 change: 1 addition & 0 deletions bbot/core/config/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _get_config(self, filename, name="config"):
return OmegaConf.create()

def get_custom_config(self):
self.ensure_config_file()
return self._get_config(self.config_filename, name="config")

def get_default_config(self):
Expand Down
16 changes: 8 additions & 8 deletions bbot/core/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ def include_logger(self, logger):
for handler in self.log_handlers.values():
self.add_log_handler(handler)

def stderr_filter(self, record):
if record.levelno == logging.TRACE and self.log_level > logging.DEBUG:
return False
if record.levelno < self.log_level:
return False
return True

@property
def log_handlers(self):
if self._log_handlers is None:
Expand All @@ -189,16 +196,9 @@ def log_handlers(self):
f"{log_dir}/bbot.debug.log", when="d", interval=1, backupCount=14
)

def stderr_filter(record):
if record.levelno == logging.TRACE and self.log_level > logging.DEBUG:
return False
if record.levelno < self.log_level:
return False
return True

# Log to stderr
stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.addFilter(stderr_filter)
stderr_handler.addFilter(self.stderr_filter)
# log to files
debug_handler.addFilter(lambda x: x.levelno == logging.TRACE or (x.levelno < logging.VERBOSE))
main_handler.addFilter(lambda x: x.levelno != logging.TRACE and x.levelno >= logging.VERBOSE)
Expand Down
42 changes: 14 additions & 28 deletions bbot/core/core.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import logging
import traceback
from copy import copy
import multiprocessing
from pathlib import Path
from omegaconf import OmegaConf


DEFAULT_CONFIG = None


Expand All @@ -22,27 +22,6 @@ class BBOTCore:
- load quickly
"""

class BBOTProcess(multiprocessing.Process):

def __init__(self, *args, **kwargs):
self.logging_queue = kwargs.pop("logging_queue")
self.log_level = kwargs.pop("log_level")
super().__init__(*args, **kwargs)

def run(self):
log = logging.getLogger("bbot.core.process")
try:
from bbot.core import CORE

CORE.logger.setup_queue_handler(self.logging_queue, self.log_level)
super().run()
except KeyboardInterrupt:
log.warning(f"Got KeyboardInterrupt in {self.name}")
log.trace(traceback.format_exc())
except BaseException as e:
log.warning(f"Error in {self.name}: {e}")
log.trace(traceback.format_exc())

def __init__(self):
self._logger = None
self._files_config = None
Expand All @@ -52,10 +31,6 @@ def __init__(self):
self._config = None
self._custom_config = None

# ensure bbot home dir
if not "home" in self.config:
self.custom_config["home"] = "~/.bbot"

# bare minimum == logging
self.logger
self.log = logging.getLogger("bbot.core")
Expand Down Expand Up @@ -105,6 +80,9 @@ def default_config(self):
global DEFAULT_CONFIG
if DEFAULT_CONFIG is None:
self.default_config = self.files_config.get_default_config()
# ensure bbot home dir
if not "home" in self.default_config:
self.default_config["home"] = "~/.bbot"
return DEFAULT_CONFIG

@default_config.setter
Expand Down Expand Up @@ -166,7 +144,15 @@ def files_config(self):
return self._files_config

def create_process(self, *args, **kwargs):
process = self.BBOTProcess(*args, logging_queue=self.logger.queue, log_level=self.logger.log_level, **kwargs)
if os.environ.get("BBOT_TESTING", "") == "True":
import threading

kwargs.pop("custom_name", None)
process = threading.Thread(*args, **kwargs)
else:
from .helpers.process import BBOTProcess

process = BBOTProcess(*args, **kwargs)
process.daemon = True
return process

Expand Down
Loading

0 comments on commit 25e5a69

Please sign in to comment.