#!@PYTHON@
# coding=utf-8
import os
import sys
import signal
import logging

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

# support running uninstalled
_dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if 'BLUEMAN_SOURCE' in os.environ:
    sys.path = [_dirname, os.path.join(_dirname, 'module', '.libs')] + sys.path
    os.environ["GSETTINGS_SCHEMA_DIR"] = os.path.join(_dirname, "data")

from blueman.Functions import create_parser, create_logger, set_proc_title
from blueman.main.Adapter import BluemanAdapters

# Workaround introspection bug, gnome bug 622084
signal.signal(signal.SIGINT, signal.SIG_DFL)

if __name__ == '__main__':
    parser = parser = create_parser()
    parser.add_argument("--socket-id", dest="socket_id", action="store", type=int, metavar="ID")
    parser.add_argument("adapter", nargs="?", metavar="ADAPTER NAME")
    args = parser.parse_args()

    if args.LEVEL.upper() == "DEBUG":
        log_level = logging.DEBUG
    elif args.LEVEL.upper() == "INFO":
        log_level = logging.INFO
    elif args.LEVEL.upper() == "WARNING":
        log_level = logging.WARNING
    elif args.LEVEL.upper() == "ERROR":
        log_level = logging.ERROR
    elif args.LEVEL.upper() == "CRITICAL":
        log_level = logging.CRITICAL
    else:
        log_level = logging.WARNING

    create_logger(log_level, "blueman-adapters", syslog=args.syslog)

    set_proc_title()

    blueman_adapters = BluemanAdapters(args.adapter, args.socket_id)
    Gtk.main()
