Beispiel #1
0
def run(argv=None):
    """
    Run an irc bot from a config file

    Usage: irc3 [options] <config>...

    Options:

    --logdir DIRECTORY  Log directory to use instead of stderr
    --logdate           Show datetimes in console output
    -v,--verbose        Increase verbosity
    -r,--raw            Show raw irc log on the console
    -d,--debug          Add some debug commands/utils
    -i,--interactive    Load a ipython console with a bot instance
    --help-page         Output a reST page containing commands help
    """
    import os
    import docopt
    import textwrap
    args = argv or sys.argv[1:]
    args = docopt.docopt(textwrap.dedent(run.__doc__), args)
    cfg = utils.parse_config(*args['<config>'])
    cfg.update(
        verbose=args['--verbose'],
        debug=args['--debug'],
    )
    pythonpath = cfg.get('pythonpath', [])
    pythonpath.append(cfg['here'])
    for path in pythonpath:
        sys.path.append(os.path.expanduser(path))
    if args['--logdir'] or 'logdir' in cfg:
        logdir = os.path.expanduser(args['--logdir'] or cfg.get('logdir'))
        IrcBot.logging_config = config.get_file_config(logdir)
    if args['--logdate']:  # pragma: no cover
        fmt = IrcBot.logging_config['formatters']['console']
        fmt['format'] = config.TIMESTAMPED_FMT
    if args['--help-page']:  # pragma: no cover
        for v in IrcBot.logging_config['handlers'].values():
            v['level'] = 'ERROR'
    if args['--debug']:
        IrcBot.venusian_categories.append('irc3.debug')
    if args['--interactive']:  # pragma: no cover
        import irc3.testing
        bot = irc3.testing.IrcBot(**cfg)
    else:
        bot = IrcBot(**cfg)
    if args['--raw']:
        bot.include('irc3.plugins.log', venusian_categories=['irc3.debug'])
    if args['--help-page']:  # pragma: no cover
        bot.print_help_page()
    elif args['--interactive']:  # pragma: no cover
        import IPython
        IPython.embed()
    else:
        bot.run()
    if argv:
        return bot
Beispiel #2
0
def run(argv=None):
    """
    Run an irc bot from a config file

    Usage: irc3 [options] <config>...

    Options:

    --logdir DIRECTORY  Log directory to use instead of stderr
    --logdate           Show datetimes in console output
    -v,--verbose        Increase verbosity
    -r,--raw            Show raw irc log on the console
    -d,--debug          Add some debug commands/utils
    -i,--interactive    Load a ipython console with a bot instance
    --help-page         Output a reST page containing commands help
    """
    import os
    import docopt
    import textwrap
    args = argv or sys.argv[1:]
    args = docopt.docopt(textwrap.dedent(run.__doc__), args)
    cfg = utils.parse_config(*args['<config>'])
    cfg.update(
        verbose=args['--verbose'],
        debug=args['--debug'],
    )
    pythonpath = cfg.get('pythonpath', [])
    pythonpath.append(cfg['here'])
    for path in pythonpath:
        sys.path.append(os.path.expanduser(path))
    if args['--logdir'] or 'logdir' in cfg:
        logdir = os.path.expanduser(args['--logdir'] or cfg.get('logdir'))
        IrcBot.logging_config = config.get_file_config(logdir)
    if args['--logdate']:  # pragma: no cover
        fmt = IrcBot.logging_config['formatters']['console']
        fmt['format'] = config.TIMESTAMPED_FMT
    if args['--help-page']:  # pragma: no cover
        for v in IrcBot.logging_config['handlers'].values():
            v['level'] = 'ERROR'
    if args['--debug']:
        IrcBot.venusian_categories.append('irc3.debug')
    if args['--interactive']:  # pragma: no cover
        import irc3.testing
        bot = irc3.testing.IrcBot(**cfg)
    else:
        bot = IrcBot(**cfg)
    if args['--raw']:
        bot.include('irc3.plugins.log', venusian_categories=['irc3.debug'])
    if args['--help-page']:  # pragma: no cover
        bot.print_help_page()
    elif args['--interactive']:  # pragma: no cover
        import IPython
        IPython.embed()
    else:
        bot.run()
    if argv:
        return bot
Beispiel #3
0
    def from_argv(cls, argv=None, **kwargs):
        prog = cls.server and 'irc3d' or 'irc3'
        doc = """
        Run an {prog} instance from a config file

        Usage: {prog} [options] <config>...

        Options:

        -h, --help          Display this help and exit
        --version           Output version information and exit
        --logdir DIRECTORY  Log directory to use instead of stderr
        --logdate           Show datetimes in console output
        --host HOST         Server name or ip
        --port PORT         Server port
        -v,--verbose        Increase verbosity
        -r,--raw            Show raw irc log on the console
        -d,--debug          Add some debug commands/utils
        -i,--interactive    Load a ipython console with a bot instance
        """.format(prog=prog)
        if not cls.server:
            doc += """
            --help-page         Output a reST page containing commands help
            """.strip()
        import os
        import docopt
        import textwrap
        args = argv or sys.argv[1:]
        args = docopt.docopt(textwrap.dedent(doc), args, version=version)
        cfg = utils.parse_config(
            cls.server and 'server' or 'bot', *args['<config>'])
        cfg.update(
            verbose=args['--verbose'],
            debug=args['--debug'],
        )
        cfg.update(kwargs)
        if args['--host']:  # pragma: no cover
            host = args['--host']
            cfg['host'] = host
            if host in ('127.0.0.1', 'localhost'):
                cfg['ssl'] = False
        if args['--port']:  # pragma: no cover
            cfg['port'] = args['--port']
        if args['--logdir'] or 'logdir' in cfg:
            logdir = os.path.expanduser(args['--logdir'] or cfg.get('logdir'))
            cls.logging_config = config.get_file_config(logdir)
        if args['--logdate']:  # pragma: no cover
            fmt = cls.logging_config['formatters']['console']
            fmt['format'] = config.TIMESTAMPED_FMT
        if args.get('--help-page'):  # pragma: no cover
            for v in cls.logging_config['handlers'].values():
                v['level'] = 'ERROR'
        if args['--raw']:
            cfg['raw'] = True
        context = cls.from_config(cfg)
        if args.get('--help-page'):  # pragma: no cover
            context.print_help_page()
        elif args['--interactive']:  # pragma: no cover
            import IPython
            IPython.embed()
            sys.exit(0)
        else:
            context.run(forever=not bool(kwargs))
        if kwargs or argv:
            return context
Beispiel #4
0
    def from_argv(cls, argv=None, **kwargs):
        prog = cls.server and 'irc3d' or 'irc3'
        doc = """
        Run an {prog} instance from a config file

        Usage: {prog} [options] <config>...

        Options:

        --logdir DIRECTORY  Log directory to use instead of stderr
        --logdate           Show datetimes in console output
        -v,--verbose        Increase verbosity
        -r,--raw            Show raw irc log on the console
        -d,--debug          Add some debug commands/utils
        -i,--interactive    Load a ipython console with a bot instance
        """.format(prog=prog)
        if not cls.server:
            doc += """
            --help-page         Output a reST page containing commands help
            """.strip()
        import os
        import docopt
        import textwrap
        args = argv or sys.argv[1:]
        args = docopt.docopt(textwrap.dedent(doc), args)
        cfg = utils.parse_config(
            cls.server and 'server' or 'bot', *args['<config>'])
        cfg.update(kwargs)
        cfg.update(
            verbose=args['--verbose'],
            debug=args['--debug'],
        )
        pythonpath = cfg.get('pythonpath', [])
        pythonpath.append(cfg['here'])
        for path in pythonpath:
            sys.path.append(os.path.expanduser(path))
        if args['--logdir'] or 'logdir' in cfg:
            logdir = os.path.expanduser(args['--logdir'] or cfg.get('logdir'))
            cls.logging_config = config.get_file_config(logdir)
        if args['--logdate']:  # pragma: no cover
            fmt = cls.logging_config['formatters']['console']
            fmt['format'] = config.TIMESTAMPED_FMT
        if args.get('--help-page'):  # pragma: no cover
            for v in cls.logging_config['handlers'].values():
                v['level'] = 'ERROR'
        if args['--debug']:
            cls.venusian_categories.append(prog + '.debug')
        if args['--interactive']:  # pragma: no cover
            import irc3.testing
            context = getattr(irc3.testing, cls.__name__)(**cfg)
        else:
            context = cls(**cfg)
        if args['--raw']:
            context.include('irc3.plugins.log',
                            venusian_categories=[prog + '.debug'])
        if args.get('--help-page'):  # pragma: no cover
            context.print_help_page()
        elif args['--interactive']:  # pragma: no cover
            import IPython
            IPython.embed()
            sys.exit(0)
        else:
            context.run(forever=not bool(kwargs))
        if argv or kwargs:
            return context
Beispiel #5
0
    def from_argv(cls, argv=None, **kwargs):
        prog = cls.server and 'irc3d' or 'irc3'
        doc = """
        Run an {prog} instance from a config file

        Usage: {prog} [options] <config>...

        Options:

        --logdir DIRECTORY  Log directory to use instead of stderr
        --logdate           Show datetimes in console output
        -v,--verbose        Increase verbosity
        -r,--raw            Show raw irc log on the console
        -d,--debug          Add some debug commands/utils
        -i,--interactive    Load a ipython console with a bot instance
        """.format(prog=prog)
        if not cls.server:
            doc += """
            --help-page         Output a reST page containing commands help
            """.strip()
        import os
        import docopt
        import textwrap
        args = argv or sys.argv[1:]
        args = docopt.docopt(textwrap.dedent(doc), args)
        cfg = utils.parse_config(cls.server and 'server' or 'bot',
                                 *args['<config>'])
        cfg.update(kwargs)
        cfg.update(
            verbose=args['--verbose'],
            debug=args['--debug'],
        )
        pythonpath = cfg.get('pythonpath', [])
        pythonpath.append(cfg['here'])
        for path in pythonpath:
            sys.path.append(os.path.expanduser(path))
        if args['--logdir'] or 'logdir' in cfg:
            logdir = os.path.expanduser(args['--logdir'] or cfg.get('logdir'))
            cls.logging_config = config.get_file_config(logdir)
        if args['--logdate']:  # pragma: no cover
            fmt = cls.logging_config['formatters']['console']
            fmt['format'] = config.TIMESTAMPED_FMT
        if args.get('--help-page'):  # pragma: no cover
            for v in cls.logging_config['handlers'].values():
                v['level'] = 'ERROR'
        if args['--debug']:
            cls.venusian_categories.append(prog + '.debug')
        if args['--interactive']:  # pragma: no cover
            import irc3.testing
            context = getattr(irc3.testing, cls.__name__)(**cfg)
        else:
            context = cls(**cfg)
        if args['--raw']:
            context.include('irc3.plugins.log',
                            venusian_categories=[prog + '.debug'])
        if args.get('--help-page'):  # pragma: no cover
            context.print_help_page()
        elif args['--interactive']:  # pragma: no cover
            import IPython
            IPython.embed()
            sys.exit(0)
        else:
            context.run(forever=not bool(kwargs))
        if argv or kwargs:
            return context