Skip to content

Context

moin2gitwiki context object - carries state between components

This contains the basic context object, which has various global state information in it such as the logging objects.

Moin2GitContext

Moin2GitContext Context Object - holds state, logging, etc

Called from the cli code. Sets up all the common requirements.

Attributes:

Name Type Description
debug bool

if true we output more debugging chatter

verbose bool

if true we output more progress information

syslog bool

if true we additionally log to syslog at debug level

logger Logger

Logging object

moin_data

Path of the MoinMoin data directory

users Moin2GitUserSet

Moin user set object

create_context(**kwargs) classmethod

Create the context object

Builds the requirements for the context object and returns an object

Source code in moin2gitwiki/context.py
@classmethod
def create_context(cls, **kwargs):
    """
    Create the context object

    Builds the requirements for the context object and returns an object
    """
    if "logger" not in kwargs:
        logger = logging.getLogger("moin2gitwiki")
        kwargs["logger"] = logger
    if "moin_data" in kwargs:
        moin_data = kwargs["moin_data"]
        del kwargs["moin_data"]
    else:
        moin_data = None
    if "user_map" in kwargs:
        user_map = kwargs["user_map"]
        del kwargs["user_map"]

    if moin_data:
        #
        # make the paths absolute
        kwargs["_moin_data"] = Path(moin_data).resolve(strict=True)
        #
        # get the proxies
        proxies: Dict[str, str] = {}
        if "proxies" in kwargs:
            for proxy_setting in kwargs["proxies"]:
                key, value = proxy_setting.split("=", maxsplit=1)
                proxies[key] = value
        kwargs["proxies"] = proxies
    #
    # build the context object
    context = cls(**kwargs)
    context.configure_logger()
    #
    # get the users
    if user_map is not None:
        context.users = Moin2GitUserSet.load_users_from_file(
            path=user_map,
            logger=context.logger,
        )
    elif moin_data:
        context.users = Moin2GitUserSet.load_users_from_wiki_data(
            wiki_data_path=context.moin_data,
            logger=context.logger,
        )
    #
    return context

get_file_handler(self)

Sets up and returns the file logging handler

Returns:

Type Description
TimedRotatingFileHandler

file_handler: logger file handler

Source code in moin2gitwiki/context.py
def get_file_handler(self) -> logging.handlers.TimedRotatingFileHandler:
    """
    Sets up and returns the file logging handler

    Returns:
        file_handler: logger file handler
    """
    file_handler = logging.handlers.TimedRotatingFileHandler(
        LOG_FILE,
        when="midnight",
    )
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(FILE_FORMATTER)
    return file_handler