#!/usr/bin/env python3

# Pôle compétence logiciel libre 2019-2020
# Derived from samba-tool
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# make sure the script dies immediately when hitting control-C,
# rather than raising KeyboardInterrupt. As we do all database
# operations using transactions, this is safe.
import sys
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

from gpo_utils.main import cmd_gpo_tool

cmd = cmd_gpo_tool()
subcommand = None
args = ()

if len(sys.argv) > 1:
    subcommand = sys.argv[1]
    if len(sys.argv) > 2:
        args = sys.argv[2:]

try:
    command, argv = cmd._resolve("gpo-tool", subcommand, *args)
    retval = command._run(*argv)
except (SystemExit) as err:
    retval = err.code
except (Exception) as err:
    cmd.show_command_error(err)
    retval = 1
sys.exit(retval)
