コード例 #1
0
ファイル: gnoti.py プロジェクト: spance/Gmail-Notification
if __name__ == '__main__':
    argsParser = argparse.ArgumentParser(version=__version__,
                                         formatter_class=argparse.RawDescriptionHelpFormatter,
                                         description=__description__)
    argsGroup = argsParser.add_mutually_exclusive_group()
    argsGroup.add_argument('-a', '--add', dest='add_gmail', default=None, nargs=1,
                           help='setup account and authorization to take notification')
    argsGroup.add_argument('-l', '--list', action='store_true', default=None,
                           help='show the authorized accounts list')
    argsGroup.add_argument('-r', '--remove', dest='remove_gmail', default=None, nargs=1,
                           help='remove the authorized account')
    argsGroup.add_argument('--scheduled-task', action='store_true', default=None, help=argparse.SUPPRESS)

    args = argsParser.parse_args()

    if AppConfig.init_and_validate():
        this = globals()
        for k, v in dict(args.__dict__).iteritems():
            fun = this['__%s' % k]
            if v and fun and inspect.isfunction(fun):
                if fun.func_code.co_argcount:
                    fun(args)
                else:
                    fun()
                args = None
    else:
        sys.exit(-1)
    if args:
        print('Please use "--help" option to read help.')