# Path: i3configger/base.py
# DEBUG = os.getenv("DEBUG", False)
# _REAL_EXCEPTHOOK = sys.excepthook
# def configure_logging(verbosity: int, logPath, isDaemon=False):
# def get_version():
# def i3configger_excepthook(type_, value, traceback):
# 
# Path: i3configger/build.py
# def build_all():
# def generate_contents(cnf: config.I3configgerConfig, prts, msg):
# def make_header(partialsPath):
# def generate_main_content(partialsPath, selected, ctx):
# def get_bar_setting(barCnf, prts, ctx):
# def generate_i3bar_content(prts, selectValue, ctx):
# def check_config(content):
# def persist_results(pathContentsMap):
# 
# Path: i3configger/config.py
# class MARK:
# class I3configgerConfig:
#     COMMENT = "#"
#     SET = "set"
#     VAR = "$"
# SUFFIX = ".conf"
# I3BAR = "i3bar"
# DEFAULTS = {
#     "main": {
#         "target": "../config",
#         "i3_refresh_msg": "reload",
#         "status_command": "i3status",
#         "log": None,
#         "notify": False,
#     },
#     "bars": {
#         "defaults": {"template": "tpl", "target": "..", "select": "default"},
#         "targets": {},
#     },
# }
# CONFIG_CANDIDATES = [
#     Path("~/.i3").expanduser(),
#     Path(os.getenv("XDG_CONFIG_HOME", "~/.config/")).expanduser() / "i3",
# ]
#     PARTIALS_NAME = "config.d"
#     CONFIG_NAME = "i3configger.json"
#     MESSAGES_NAME = ".messages.json"
#     def __init__(self, load=True):
#     def __str__(self):
#     def load(self):
#     def get_bar_targets(self):
# def fetch(path: Path) -> dict:
# def freeze(path, obj):
# def ensure_i3_configger_sanity():
# def get_i3wm_config_path():
# 
# Path: i3configger/exc.py
# class I3configgerException(Exception):
# class BuildError(I3configgerException):
# class ConfigError(I3configgerException):
# class MessageError(I3configgerException):
# class PartialsError(I3configgerException):
# class ParseError(I3configgerException):
# class ContextError(I3configgerException):
# class UserError(I3configgerException):
# 
# Path: i3configger/ipc.py
# def configure(cnf=None, deactivate=False):
# def communicate(msg="new config active", refresh=False, urgency="low"):
#     def configure(cls, which):
#     def reload_i3(cls):
#     def restart_i3(cls):
#     def _send_i3_msg(cls, msg):
#     def get_config_error_report(cls, path):
#     def configure(cls, notify):
#     def notify_send(cls, msg, urgency="low"):
#     def configure(cls, command):
#     def send_sigusr1(cls):
# def nop(*args, **kwargs):
# class I3:
# class Notify:
# class I3bar:
#     METHOD_MAP = {"restart": restart_i3, "reload": reload_i3}
# 
# Path: i3configger/message.py
# class CMD:
# class Messenger:
#     MERGE = "merge"
#     PRUNE = "prune"
#     SELECT = "select"
#     SELECT_NEXT = "select-next"
#     SELECT_PREVIOUS = "select-previous"
#     SET = "set"
#     SHADOW = "shadow"
#     DEL = "del"
#     COMMAND_METHOD_MAP = {
#         CMD.MERGE: _process_merge,
#         CMD.PRUNE: _process_prune,
#         CMD.SELECT: _process_select,
#         CMD.SELECT_NEXT: _process_select_shift,
#         CMD.SELECT_PREVIOUS: _process_select_shift,
#         CMD.SET: _process_set,
#         CMD.SHADOW: _process_shadow,
#     }
#     def get_all_commands(cls):
# def save(message):
#     def __init__(self, messagesPath, prts, message=None):
#     def digest_message(self):
#     def _process_merge(self):
#     def _process_prune(self):
#     def _transform(self, func):
#     def _process_set(self):
#     def _process_select(self):
#     def _process_shadow(self):
#     def _process_select_shift(self):
#     def fetch_messages(self, exludes=None):
#     def ensure_message_keys(self, state, prts, exludes):
# 
# Path: i3configger/watch.py
# _MASK = (
#     flags.CREATE
#     | flags.ATTRIB
#     | flags.DELETE
#     | flags.MODIFY
#     | flags.CLOSE_WRITE
#     | flags.MOVED_FROM
#     | flags.MOVED_TO
#     | flags.DELETE_SELF
#     | flags.MOVE_SELF
# )
# def watch_guarded():
# def watch_unguarded():
# def get_i3configger_process():
# def daemonized(verbosity, logPath):
# def exorcise():


import argparse
import logging
import sys
from i3configger import base, build, config, exc, ipc, message, watch
        _main(args)
    except exc.I3configgerException as e:
        if args.v > 2:
            raise
        sys.exit(f"[FATAL] {e}")


def _main(args):
    config.ensure_i3_configger_sanity()
    cnf = config.I3configgerConfig()
    ipc.configure(cnf)
    base.configure_logging(verbosity=args.v, logPath=cnf.payload["main"]["log"])
    if args.version:
        print(f"i3configger {base.get_version()}")
        return 0

    if args.kill:
        watch.exorcise()
        return 0

    if args.message:
        message.save(args.message)
    if watch.get_i3configger_process():
        if not args.message:
            raise exc.UserError("already running - did you mean to send a message?")
        log.info(f"{args.message} is saved - now let the running process do the work")
        return 0

    if args.daemon:
        watch.daemonized(args.v, args.log)

# Path: i3configger/base.py
# DEBUG = os.getenv("DEBUG", False)
# _REAL_EXCEPTHOOK = sys.excepthook
# def configure_logging(verbosity: int, logPath, isDaemon=False):
# def get_version():
# def i3configger_excepthook(type_, value, traceback):
# 
# Path: i3configger/build.py
# def build_all():
# def generate_contents(cnf: config.I3configgerConfig, prts, msg):
# def make_header(partialsPath):
# def generate_main_content(partialsPath, selected, ctx):
# def get_bar_setting(barCnf, prts, ctx):
# def generate_i3bar_content(prts, selectValue, ctx):
# def check_config(content):
# def persist_results(pathContentsMap):
# 
# Path: i3configger/config.py
# class MARK:
# class I3configgerConfig:
#     COMMENT = "#"
#     SET = "set"
#     VAR = "$"
# SUFFIX = ".conf"
# I3BAR = "i3bar"
# DEFAULTS = {
#     "main": {
#         "target": "../config",
#         "i3_refresh_msg": "reload",
#         "status_command": "i3status",
#         "log": None,
#         "notify": False,
#     },
#     "bars": {
#         "defaults": {"template": "tpl", "target": "..", "select": "default"},
#         "targets": {},
#     },
# }
# CONFIG_CANDIDATES = [
#     Path("~/.i3").expanduser(),
#     Path(os.getenv("XDG_CONFIG_HOME", "~/.config/")).expanduser() / "i3",
# ]
#     PARTIALS_NAME = "config.d"
#     CONFIG_NAME = "i3configger.json"
#     MESSAGES_NAME = ".messages.json"
#     def __init__(self, load=True):
#     def __str__(self):
#     def load(self):
#     def get_bar_targets(self):
# def fetch(path: Path) -> dict:
# def freeze(path, obj):
# def ensure_i3_configger_sanity():
# def get_i3wm_config_path():
# 
# Path: i3configger/exc.py
# class I3configgerException(Exception):
# class BuildError(I3configgerException):
# class ConfigError(I3configgerException):
# class MessageError(I3configgerException):
# class PartialsError(I3configgerException):
# class ParseError(I3configgerException):
# class ContextError(I3configgerException):
# class UserError(I3configgerException):
# 
# Path: i3configger/ipc.py
# def configure(cnf=None, deactivate=False):
# def communicate(msg="new config active", refresh=False, urgency="low"):
#     def configure(cls, which):
#     def reload_i3(cls):
#     def restart_i3(cls):
#     def _send_i3_msg(cls, msg):
#     def get_config_error_report(cls, path):
#     def configure(cls, notify):
#     def notify_send(cls, msg, urgency="low"):
#     def configure(cls, command):
#     def send_sigusr1(cls):
# def nop(*args, **kwargs):
# class I3:
# class Notify:
# class I3bar:
#     METHOD_MAP = {"restart": restart_i3, "reload": reload_i3}
# 
# Path: i3configger/message.py
# class CMD:
# class Messenger:
#     MERGE = "merge"
#     PRUNE = "prune"
#     SELECT = "select"
#     SELECT_NEXT = "select-next"
#     SELECT_PREVIOUS = "select-previous"
#     SET = "set"
#     SHADOW = "shadow"
#     DEL = "del"
#     COMMAND_METHOD_MAP = {
#         CMD.MERGE: _process_merge,
#         CMD.PRUNE: _process_prune,
#         CMD.SELECT: _process_select,
#         CMD.SELECT_NEXT: _process_select_shift,
#         CMD.SELECT_PREVIOUS: _process_select_shift,
#         CMD.SET: _process_set,
#         CMD.SHADOW: _process_shadow,
#     }
#     def get_all_commands(cls):
# def save(message):
#     def __init__(self, messagesPath, prts, message=None):
#     def digest_message(self):
#     def _process_merge(self):
#     def _process_prune(self):
#     def _transform(self, func):
#     def _process_set(self):
#     def _process_select(self):
#     def _process_shadow(self):
#     def _process_select_shift(self):
#     def fetch_messages(self, exludes=None):
#     def ensure_message_keys(self, state, prts, exludes):
# 
# Path: i3configger/watch.py
# _MASK = (
#     flags.CREATE
#     | flags.ATTRIB
#     | flags.DELETE
#     | flags.MODIFY
#     | flags.CLOSE_WRITE
#     | flags.MOVED_FROM
#     | flags.MOVED_TO
#     | flags.DELETE_SELF
#     | flags.MOVE_SELF
# )
# def watch_guarded():
# def watch_unguarded():
# def get_i3configger_process():
# def daemonized(verbosity, logPath):
# def exorcise():


# Path: i3configger/cli.py
import argparse
import logging
import sys
from i3configger import base, build, config, exc, ipc, message, watch

        _main(args)
    except exc.I3configgerException as e:
        if args.v > 2:
            raise
        sys.exit(f"[FATAL] {e}")


def _main(args):
    config.ensure_i3_configger_sanity()
    cnf = config.I3configgerConfig()
    ipc.configure(cnf)
    base.configure_logging(verbosity=args.v, logPath=cnf.payload["main"]["log"])
    if args.version:
        print(f"i3configger {base.get_version()}")
        return 0

    if args.kill:
        watch.exorcise()
        return 0

    if args.message:
        message.save(args.message)
    if watch.get_i3configger_process():
        if not args.message:
            raise exc.UserError("already running - did you mean to send a message?")
        log.info(f"{args.message} is saved - now let the running process do the work")
        return 0

    if args.daemon:
        watch.daemonized(args.v, args.log)

    elif args.watch: