示例#1
0
文件: err.py 项目: rroemhild/err
            raise Exception('You cannot run in text and daemon mode at the same time')
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')
示例#2
0
文件: err.py 项目: rroemhild/err
 def action():
     from errbot.main import main
     main(backend, logger, config)
示例#3
0
文件: err.py 项目: carriercomm/lctv
        if args['text']:
            raise Exception('You cannot run in text and daemon mode at the same time')
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')

if __name__ == "__main__":
    main()
示例#4
0
文件: err.py 项目: carriercomm/lctv
def main():

    execution_dir = getcwd()

    # By default insert the execution path (useful to be able to execute err from
    # the source tree directly without installing it.
    sys.path.insert(0, execution_dir)

    parser = argparse.ArgumentParser(description='The main entry point of the XMPP bot err.')
    parser.add_argument('-c', '--config', default=None,
                        help='Full path to your config.py (default: config.py in current working directory).')
    parser.add_argument('-r', '--restore', nargs='?', default=None, const='default',
                        help='Restores a bot from backup.py. (default: backup.py from the bot data directory).')
    parser.add_argument('-l', '--list', action='store_true', help='Lists all the backends found.')

    backend_group = parser.add_mutually_exclusive_group()
    backend_group.add_argument('-X', '--xmpp', action='store_true', help='XMPP backend [DEFAULT]')
    backend_group.add_argument('-H', '--hipchat', action='store_true', help='Hipchat backend')
    backend_group.add_argument('-I', '--irc', action='store_true', help='IRC backend')
    backend_group.add_argument('-S', '--slack', action='store_true', help='Slack backend')
    backend_group.add_argument('-T', '--text', action='store_true', help='locale text debug backend')
    backend_group.add_argument('-G', '--graphic', action='store_true', help='local graphical debug mode backend')
    backend_group.add_argument('-N', '--null', action='store_true', help='no backend')

    if not ON_WINDOWS:
        option_group = parser.add_argument_group('arguments to run it as a Daemon')
        option_group.add_argument('-d', '--daemon', action='store_true', help='Detach the process from the console')
        option_group.add_argument('-p', '--pidfile', default=None,
                                  help='Specify the pid file for the daemon (default: current bot data directory)')

    args = vars(parser.parse_args())  # create a dictionary of args
    config_path = args['config']
    # setup the environment to be able to import the config.py
    if config_path:
        # appends the current config in order to find config.py
        sys.path.insert(0, path.dirname(path.abspath(config_path)))
    else:
        config_path = execution_dir + sep + 'config.py'

    config = get_config(config_path)  # will exit if load fails
    if args['list']:
        from errbot.main import enumerate_backends
        print('Available backends:')
        for backend_name in enumerate_backends(config):
            print('\t\t%s' % backend_name)
        sys.exit(0)

    # this is temporary until the modes are removed to translate the mode names to backend names
    classic_vs_plugin_names = {'text': 'Text',
                               'graphic': 'Graphic',
                               'hipchat': 'Hipchat',
                               'irc': 'IRC',
                               'xmpp': 'XMPP',
                               'slack': 'Slack',
                               'null': 'Null'}

    filtered_mode = [mname for mname in classic_vs_plugin_names.keys() if args[mname]]
    if args['restore']:
        backend = 'Null'  # we don't want any backend when we restore
    elif filtered_mode:
        backend = classic_vs_plugin_names[filtered_mode[0]]
        if backend != 'Text':
            log.warn("""Deprecation notice:
            Please add BACKEND='%s' to your config.py instead of using the '--%s' command line parameter.
            The backend command line parameters will be removed on the next version of Err.
            """ % (backend, filtered_mode[0]))
    elif hasattr(config, 'BACKEND'):
        backend = config.BACKEND
    else:
        log.warn("""Deprecation notice:
        Err is defaulting to XMPP because you did not specify any backend.
        Please add BACKEND='XMPP' to your config.py if you really want that.
        This behaviour will be removed on the next version of Err.
        """)
        backend = 'XMPP'  # default value

    log.info("Selected backend '%s'." % backend)

    # Check if at least we can start to log something before trying to start
    # the bot (esp. daemonize it).

    log.info("Checking for '%s'..." % config.BOT_DATA_DIR)
    if not path.exists(config.BOT_DATA_DIR):
        raise Exception("The data directory '%s' for the bot does not exist" % config.BOT_DATA_DIR)
    if not access(config.BOT_DATA_DIR, W_OK):
        raise Exception("The data directory '%s' should be writable for the bot" % config.BOT_DATA_DIR)

    if (not ON_WINDOWS) and args['daemon']:
        if args['text']:
            raise Exception('You cannot run in text and daemon mode at the same time')
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')
示例#5
0
文件: err.py 项目: Dafvid/err
            def action():
                from errbot.main import main

                main(bot_class, logger, config)
示例#6
0
文件: err.py 项目: Synforge/err
def main():

    execution_dir = getcwd()

    # By default insert the execution path (useful to be able to execute err from
    # the source tree directly without installing it.
    sys.path.insert(0, execution_dir)

    parser = argparse.ArgumentParser(description='The main entry point of the errbot.')
    parser.add_argument('-c', '--config', default=None,
                        help='Full path to your config.py (default: config.py in current working directory).')

    mode_selection = parser.add_mutually_exclusive_group()
    mode_selection.add_argument('-v', '--version', action='version', version='Errbot version {}'.format(VERSION))
    mode_selection.add_argument('-r', '--restore', nargs='?', default=None, const='default',
                                help='restore a bot from backup.py (default: backup.py from the bot data directory)')
    mode_selection.add_argument('-l', '--list', action='store_true', help='list all available backends')
    mode_selection.add_argument('--new-plugin', nargs='?', default=None, const='current_dir',
                                help='create a new plugin in the specified directory')
    mode_selection.add_argument('-T', '--text', dest="backend", action='store_const', const="Text",
                                help='force local text backend')
    mode_selection.add_argument('-G', '--graphic', dest="backend", action='store_const', const="Graphic",
                                help='force local graphical backend')

    if not ON_WINDOWS:
        option_group = parser.add_argument_group('optional daemonization arguments')
        option_group.add_argument('-d', '--daemon', action='store_true', help='Detach the process from the console')
        option_group.add_argument('-p', '--pidfile', default=None,
                                  help='Specify the pid file for the daemon (default: current bot data directory)')

    args = vars(parser.parse_args())  # create a dictionary of args

    # This must come BEFORE the config is loaded below, to avoid printing
    # logs as a side effect of config loading.
    if args['new_plugin']:
        directory = os.getcwd() if args['new_plugin'] == "current_dir" else args['new_plugin']
        for handler in logging.getLogger().handlers:
            logger.removeHandler(handler)
        try:
            new_plugin_wizard(directory)
        except KeyboardInterrupt:
            sys.exit(1)
        except Exception as e:
            sys.stderr.write(str(e) + "\n")
            sys.exit(1)
        finally:
            sys.exit(0)

    config_path = args['config']
    # setup the environment to be able to import the config.py
    if config_path:
        # appends the current config in order to find config.py
        sys.path.insert(0, path.dirname(path.abspath(config_path)))
    else:
        config_path = execution_dir + sep + 'config.py'

    config = get_config(config_path)  # will exit if load fails
    if args['list']:
        from errbot.main import enumerate_backends
        print('Available backends:')
        for backend_name in enumerate_backends(config):
            print('\t\t%s' % backend_name)
        sys.exit(0)

    if args['restore']:
        backend = 'Null'  # we don't want any backend when we restore
    elif args['backend'] is None:
        if not hasattr(config, 'BACKEND'):
            log.fatal("The BACKEND configuration option is missing in config.py")
            sys.exit(1)
        backend = config.BACKEND
    else:
        backend = args['backend']

    log.info("Selected backend '%s'." % backend)

    # Check if at least we can start to log something before trying to start
    # the bot (esp. daemonize it).

    log.info("Checking for '%s'..." % config.BOT_DATA_DIR)
    if not path.exists(config.BOT_DATA_DIR):
        raise Exception("The data directory '%s' for the bot does not exist" % config.BOT_DATA_DIR)
    if not access(config.BOT_DATA_DIR, W_OK):
        raise Exception("The data directory '%s' should be writable for the bot" % config.BOT_DATA_DIR)

    if (not ON_WINDOWS) and args['daemon']:
        if args['text']:
            raise Exception('You cannot run in text and daemon mode at the same time')
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action, chdir=os.getcwd())
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')
示例#7
0
文件: err.py 项目: arrrrr/err
            raise Exception("You cannot run in text and daemon mode at the same time")

        if args["pidfile"]:
            pid = args["pidfile"]
        else:
            from config import BOT_DATA_DIR

            pid = BOT_DATA_DIR + sep + "err.pid"

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        uid = getpwnam(args["user"]).pw_uid if args["user"] else None
        gid = getgrnam(args["group"]).gr_gid if args["group"] else None

        # noinspection PyBroadException
        try:
            with daemon.DaemonContext(
                detach_process=True, working_directory=getcwd(), pidfile=pidfile, uid=uid, gid=gid
            ):  # put the initial working directory to be sure not to lost it after daemonization
                from errbot.main import main

                main(bot_class, logger)
        except Exception as _:
            logging.exception("Failed to daemonize the process")
    from errbot.main import main

    main(bot_class, logger)
    logging.info("Process exiting")
示例#8
0
文件: err.py 项目: Dafvid/err
    if (not ON_WINDOWS) and args['daemon']:
        if args['text']:
            raise Exception('You cannot run in text and daemon mode at the same time')

        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main

                main(bot_class, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main

    main(bot_class, logger, config)
    log.info('Process exiting')
示例#9
0
        if args['pidfile']:
            pid = args['pidfile']
        else:
            from config import BOT_DATA_DIR

            pid = BOT_DATA_DIR + sep + 'err.pid'

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        uid = getpwnam(args['user']).pw_uid if args['user'] else None
        gid = getgrnam(args['group']).gr_gid if args['group'] else None

        #noinspection PyBroadException
        try:
            with daemon.DaemonContext(
                    detach_process=True,
                    working_directory=getcwd(),
                    pidfile=pidfile,
                    uid=uid,
                    gid=gid
            ):  # put the initial working directory to be sure not to lost it after daemonization
                from errbot.main import main
                main(bot_class, logger)
        except Exception as _:
            logging.exception('Failed to daemonize the process')
    from errbot.main import main
    main(bot_class, logger)
    logging.info('Process exiting')
示例#10
0
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        # noinspection PyBroadException
        try:

            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err",
                               pid=pid,
                               action=action,
                               chdir=os.getcwd())
            log.info("Daemonizing")
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')


if __name__ == "__main__":
    main()
示例#11
0
            def action():
                from errbot.main import main

                main(bot_class, logger, config)
示例#12
0
    if (not ON_WINDOWS) and args['daemon']:
        if args['text']:
            raise Exception('You cannot run in text and daemon mode at the same time')

        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main

                main(bot_class, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            logging.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main

    main(bot_class, logger, config)
    logging.info('Process exiting')
示例#13
0
文件: err.py 项目: oeuftete/errbot
 def action():
     from errbot.main import main
     main(backend, logger, config)
示例#14
0
文件: err.py 项目: oeuftete/errbot
def main():

    execution_dir = getcwd()

    # By default insert the execution path (useful to be able to execute err from
    # the source tree directly without installing it.
    sys.path.insert(0, execution_dir)

    parser = argparse.ArgumentParser(description='The main entry point of the errbot.')
    parser.add_argument('-c', '--config', default=None,
                        help='Full path to your config.py (default: config.py in current working directory).')

    mode_selection = parser.add_mutually_exclusive_group()
    mode_selection.add_argument('-v', '--version', action='version', version='Errbot version {}'.format(VERSION))
    mode_selection.add_argument('-r', '--restore', nargs='?', default=None, const='default',
                                help='restore a bot from backup.py (default: backup.py from the bot data directory)')
    mode_selection.add_argument('-l', '--list', action='store_true', help='list all available backends')
    mode_selection.add_argument('--new-plugin', nargs='?', default=None, const='current_dir',
                                help='create a new plugin in the specified directory')
    mode_selection.add_argument('-T', '--text', dest="backend", action='store_const', const="Text",
                                help='force local text backend')
    mode_selection.add_argument('-G', '--graphic', dest="backend", action='store_const', const="Graphic",
                                help='force local graphical backend')

    if not ON_WINDOWS:
        option_group = parser.add_argument_group('optional daemonization arguments')
        option_group.add_argument('-d', '--daemon', action='store_true', help='Detach the process from the console')
        option_group.add_argument('-p', '--pidfile', default=None,
                                  help='Specify the pid file for the daemon (default: current bot data directory)')

    args = vars(parser.parse_args())  # create a dictionary of args

    # This must come BEFORE the config is loaded below, to avoid printing
    # logs as a side effect of config loading.
    if args['new_plugin']:
        directory = os.getcwd() if args['new_plugin'] == "current_dir" else args['new_plugin']
        for handler in logging.getLogger().handlers:
            logger.removeHandler(handler)
        try:
            new_plugin_wizard(directory)
        except KeyboardInterrupt:
            sys.exit(1)
        except Exception as e:
            sys.stderr.write(str(e) + "\n")
            sys.exit(1)
        finally:
            sys.exit(0)

    config_path = args['config']
    # setup the environment to be able to import the config.py
    if config_path:
        # appends the current config in order to find config.py
        sys.path.insert(0, path.dirname(path.abspath(config_path)))
    else:
        config_path = execution_dir + sep + 'config.py'

    config = get_config(config_path)  # will exit if load fails
    if args['list']:
        from errbot.main import enumerate_backends
        print('Available backends:')
        for backend_name in enumerate_backends(config):
            print('\t\t%s' % backend_name)
        sys.exit(0)

    if args['restore']:
        backend = 'Null'  # we don't want any backend when we restore
    elif args['backend'] is None:
        if not hasattr(config, 'BACKEND'):
            log.fatal("The BACKEND configuration option is missing in config.py")
            sys.exit(1)
        backend = config.BACKEND
    else:
        backend = args['backend']

    log.info("Selected backend '%s'." % backend)

    # Check if at least we can start to log something before trying to start
    # the bot (esp. daemonize it).

    log.info("Checking for '%s'..." % config.BOT_DATA_DIR)
    if not path.exists(config.BOT_DATA_DIR):
        raise Exception("The data directory '%s' for the bot does not exist" % config.BOT_DATA_DIR)
    if not access(config.BOT_DATA_DIR, W_OK):
        raise Exception("The data directory '%s' should be writable for the bot" % config.BOT_DATA_DIR)

    if (not ON_WINDOWS) and args['daemon']:
        if args['backend'] == "Text":
            raise Exception('You cannot run in text and daemon mode at the same time')
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main
                main(backend, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action, chdir=os.getcwd())
            log.info("Daemonizing")
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(backend, logger, config, restore)
    log.info('Process exiting')
示例#15
0
文件: err.py 项目: revcozmo/err
        if args['restore']:
            raise Exception('You cannot restore a backup in daemon mode.')
        if args['pidfile']:
            pid = args['pidfile']
        else:
            pid = config.BOT_DATA_DIR + sep + 'err.pid'

        from errbot.pid import PidFile

        pidfile = PidFile(pid)

        # noinspection PyBroadException
        try:
            def action():
                from errbot.main import main

                main(bot_class, logger, config)

            daemon = Daemonize(app="err", pid=pid, action=action)
            daemon.start()
        except Exception:
            log.exception('Failed to daemonize the process')
        exit(0)
    from errbot.main import main
    restore = args['restore']
    if restore == 'default':  # restore with no argument, get the default location
        restore = path.join(config.BOT_DATA_DIR, 'backup.py')

    main(bot_class, logger, config, restore)
    log.info('Process exiting')