def root():
    """
    Run the enclosed code as root (uid 0)

    Usage:

    with root():
        ...

    """
    logger.debug('Entering ROOT mode')
    old_euid = os.geteuid()
    os.seteuid(0)
    yield
    os.seteuid(old_euid)
    logger.debug('Exited ROOT mode')