#! /usr/bin/env python

#
#    Postfix queue control python tool (pymailq)
#
#    Copyright (C) 2014 Denis Pompilio (jawa) <denis.pompilio@gmail.com>
#
#    This file is part of pymailq
#
#    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 2
#    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/>.

import argparse
import pymailq
from pymailq import shell


def main():
    """main function"""
    cli = shell.PyMailqShell()
    cli.cmdloop_nointerrupt()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Postfix queue control shell')
    parser.add_argument('--version', dest='version', action='store_const',
                        const=True, default=False,
                        help='show shell version')
    parser.add_argument('--debug', dest='debug', action='store_const',
                        const=True, default=False,
                        help='show shell debug and timing info')
    parser.add_argument('--config', dest='cfg_file',
                        help='specify a configuration file for PyMailq')

    args = parser.parse_args()

    if args.version:
        print("Shell version: %s" % pymailq.VERSION)
        exit()

    if args.debug:
        print("Setting shell in debug mode.")
        pymailq.DEBUG = True

    if args.cfg_file:
        print("Using custom configuration: " + str(args.cfg_file))
        pymailq.load_config(args.cfg_file)

    main()
