예제 #1
0
    def __init__(self, filename=None):

        if not os.path.exists(HOME):
            initialize_home_directory()

        if not filename:
            filename = os.path.join(HOME, "settings.json")
            if not os.path.exists(filename):
                initialize_default_settings(filename)

        try:
            with open(filename) as fp:
                data = json.load(fp)
        except Exception as e:
            raise

        if 'daemon' in data:

            data = data['daemon']
            for key in data:

                if key == 'fetcher':
                    self.fetcher = imgurfetcher()
                    continue

                setattr(self, key, data[key])

            if self.backup == "yes":
                self.backup = True
            else:
                self.backup = False
예제 #2
0
    def __init__(self, filename=None):

        if not os.path.exists(HOME):
            initialize_home_directory()

        if not filename:
            filename = os.path.join(HOME, "settings.json")
            if not os.path.exists(filename):
                initialize_default_settings(filename)

        try:
            with open(filename) as fp:
                data = json.load(fp)
        except Exception as e:
            raise

        if 'daemon' in data:

            data = data['daemon']
            for key in data:

                if key == 'fetcher':
                    self.fetcher = imgurfetcher()
                    continue

                setattr(self, key, data[key])

            if self.backup == "yes":
                self.backup = True
            else:
                self.backup = False
예제 #3
0
import logging
import os
from pkg_resources import Requirement, resource_filename, resource_string
from bg_daemon.util import HOME, initialize_home_directory

# We set some sane defaults here, we filted differently if the logging
# calls are meant to be to the console or somewhere else
_BASE_PATH = HOME
_DEFAULT_LOG_FILENAME = os.path.join(_BASE_PATH, "bg_daemon.log")
_DEFAULT_LOG_LEVEL = logging.DEBUG
_DEFAULT_CONSOLE_LOG_LEEL = logging.INFO
_DEFAULT_FILE_LOG_LEVEL = logging.DEBUG

# define the hardcoded format string
_FORMAT_STRING = ("[%(asctime)s] [%(name)s] [%(levelname)s]"
                  "[%(funcName)s:%(lineno)s@%(filename)s]\n\t%(message)s")
formatter = logging.Formatter(_FORMAT_STRING)

# define the handler, we are going to write our log to a file
if not os.path.exists(HOME):
    initialize_home_directory()

file_handler = logging.FileHandler(_DEFAULT_LOG_FILENAME)
file_handler.setLevel(_DEFAULT_FILE_LOG_LEVEL)
file_handler.setFormatter(formatter)

# define the logger itself
logger = logging.getLogger('bg_daemon')
logger.setLevel(_DEFAULT_LOG_LEVEL)
logger.addHandler(file_handler)