示例#1
0
def setup_logger():
    debug = _conf["DEBUG"] if "DEBUG" in _conf else False
    log_to_file = _conf["LOG_TO_FILE"] if "LOG_TO_FILE" in _conf else False
    log_backup_count = _conf[
        "LOG_BACKUP_COUNT"] if "LOG_BACKUP_COUNT" in _conf else 30

    try:
        # if colorlog installed (pip install colorlog)
        from colorlog import ColoredFormatter
        import logging.config

        logconf = {
            'version': 1,
            'formatters': {
                'colored': {
                    '()':
                    'colorlog.ColoredFormatter',
                    'format':
                    "%(asctime)-15s %(log_color)s%(levelname)-5s %(process)5d [%(threadName)s] %(message)s"
                }
            },
            'handlers': {
                'stream': {
                    'class': 'logging.StreamHandler',
                    'formatter': 'colored',
                    'level': 'DEBUG' if debug else 'INFO'
                },
            },
            'loggers': {
                '': {
                    'handlers': ["stream"],
                    'level': 'DEBUG' if debug else 'INFO',
                },
            },
        }
        logging.config.dictConfig(logconf)
    except ImportError:
        import logging
        import logging.handlers
        FORMAT = "%(asctime)-15s %(levelname)-5s %(process)5d [%(threadName)s] %(message)s"
        logging.basicConfig(level=logging.DEBUG if debug else logging.INFO,
                            format=FORMAT)

    # log to file
    if log_to_file:
        os.makedirs(Config.logdir(), exist_ok=True)
        filehandler = logging.handlers.TimedRotatingFileHandler(
            os.path.join(Config.logdir(), "digiskr.log"),
            when="midnight",
            interval=1,
            backupCount=log_backup_count)
        filehandler.setLevel(logging.DEBUG)
        filehandler.setFormatter(
            logging.Formatter(
                "%(asctime)-15s %(levelname)-5s %(process)5d [%(threadName)s] %(message)s"
            ))
        logging.getLogger('').addHandler(filehandler)
示例#2
0
def new_kiwiworker(o, band_hops_str, idx):
    options = copy(o)

    def _extract_band(band_hops_str):
        local = str(band_hops_str).split('|')
        # ['FT8', 'FT4', 'FT8', 'FT8']
        mode_hops = [
            config.MODES[b[-1]] if b[-1] in config.MODES else "FT8"
            for b in local
        ]
        # ['20', '30', '40', '60']
        band_hops = [
            b[:-1] if b[-1] not in [str(n) for n in range(0, 9)] else b
            for b in local
        ]
        # [14074, 10140, 7074, 5357] in KHz
        freq_hops = [
            config.BANDS[mode_hops[i]][b] * 1000
            for i, b in enumerate(band_hops)
        ]
        return mode_hops, band_hops, freq_hops

    options.band_hops_str = band_hops_str
    options.mode_hops, options.band_hops, options.freq_hops = _extract_band(
        band_hops_str)
    options.idx = idx
    options.timestamp = int(time.time() + os.getpid() + idx) & 0xffffffff
    # tmp dirs preparation
    for i, mode in enumerate(options.mode_hops):
        dir = os.path.join(Config.tmpdir(), options.station, mode,
                           options.band_hops[i])
        if not os.path.isdir(dir):
            os.makedirs(dir, exist_ok=True)
        else:
            os.popen("rm -f %s/*.wav" % dir)

    worker = KiwiWorker(target=WsjtSoundRecorder(options),
                        name="%s-%s" %
                        (options.station, options.band_hops_str))

    return worker
示例#3
0
from digiskr import config, DecoderQueue
from digiskr.pskreporter import PskReporter
from digiskr.wsprnet import Wsprnet
from digiskr.audio import WsjtSoundRecorder
import logging
import os
import sys
import time
import threading
import gc
from datetime import datetime
from copy import copy

sys.path.append('./lib')

_conf = Config.get()
_run_event = threading.Event()
_run_event.set()
_sr_tasks = []
threading.currentThread().setName("main")


def setup_logger():
    debug = _conf["DEBUG"] if "DEBUG" in _conf else False
    log_to_file = _conf["LOG_TO_FILE"] if "LOG_TO_FILE" in _conf else False
    try:
        # if colorlog installed (pip install colorlog)
        from colorlog import ColoredFormatter
        import logging.config

        logconf = {