예제 #1
0
    def setUp(self):
        global redmine_url

        redmine_interface.setup(redmine_url, testtrackers)
예제 #2
0
def _main():
    global redmine_enabled

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-c', '--conf', help='specify path to custom config file')
    args = parser.parse_args()

    if args.conf:
        if os.path.isfile(args.conf):
            conf_file = args.conf
        else:
            print "Specified config file %s not found!" % args.conf
            exit(64)

        if not os.access(conf_file, os.R_OK):
            print "Can't read %s!" % conf_file
            exit(65)
    else:
        conf_file = "%s/conf/bot.conf" % os.path.dirname(
            os.path.abspath(__file__))

    print "Using config file %s" % conf_file

    config = ConfigParser.ConfigParser()
    config_dict = {}
    if config.read(conf_file):
        config_dict['channel'] = config.get('settings', 'channel')
        config_dict['technux_bot'] = config.get('settings', 'botname')
        config_dict['realname'] = config.get('settings', 'realname')
        config_dict['ircserver'] = config.get('settings', 'server')
        logfile = config.get('settings', 'logfile')
        config_dict['passwd'] = config.get('settings', 'passwd')
        config_dict['greeting'] = config.get('text', 'greeting')
        config_dict['usagemsg'] = config.get('text', 'usage')
        config_dict['info'] = config.get('text', 'info')
        redmine_url = config.get('redmine', 'url')
        redmine_trackers = config.get('redmine', 'trackers')
    else:
        print "ERROR: %s could not be found!" % (conf_file)
        sys.exit(66)

    if redmine_enabled is True and redmine_url is not "":
        redmine_interface.setup(redmine_url, redmine_trackers.split(','))
    else:
        print "Redmine url not specified. " \
              "Support for redmine commands disabled"
        redmine_enabled = False

    try:
        bot_setup(config_dict)

        # If logfile is set, redirect console printouts to logfile
        if logfile:
            sys.stdout = open(logfile, 'w')

        # variables frequently accessed below
        channel = config_dict['channel']
        technux_bot = config_dict['technux_bot']

        while True:
            ircmsg = SOCKET_IRC.recv(2048)
            ircmsg = ircmsg.strip('\n\r')  # Remove linebreaks
            print(ircmsg)  # Log irc msg to console or file

            # messages from the IRC server
            if keep_alive(ircmsg) is False:
                continue

            # don't start a thread unless the msg is directed
            # to the bot by a nick
            if (ircmsg.find("PRIVMSG %s :%s: " %
                            (channel, technux_bot)) != -1) \
                or (ircmsg.find("PRIVMSG %s :Hello %s" %
                                (channel, technux_bot)) != -1):
                t = threading.Thread(target=handle_msg,
                                     args=(ircmsg, config_dict))
                t.start()

    except KeyboardInterrupt:
        print "\n\n'Ctrl + C' detected"
    except socket.gaierror as (err, msg):
        print err
        print msg