Exemple #1
0
 def __init__(self, conn, table):
     self.conn = conn
     self.cursor = conn.cursor()
     self.table = table
     self.commit = False
     self.fields = self.get_table_fields()
     self.logger = get_logger()
Exemple #2
0
def main():
    logger = get_logger()
    if not PASSWORD:
        logger.error(u'Please write the password in the settings.py')
        sys.exit(2)
    if not DEBUG:
        try:
            with open(PIDPATH, 'r') as f: os.kill(int(f.read()), 9)
        except: pass
        try:
            pid = os.fork()
            if pid > 0: sys.exit(0)
        except OSError, e:
            logger.error("Fork #1 failed: %d (%s)", e.errno, e.strerror)
            sys.exit(1)
        os.setsid()
        os.umask(0)
        try:
            pid = os.fork()
            if pid > 0:
                logger.info("Daemon PID %d" , pid)
                with open(PIDPATH, 'w') as f: f.write(str(pid))
                sys.exit(0)
        except OSError, e:
            logger.error("Daemon started failed: %d (%s)", e.errno, e.strerror)
            os.exit(1)
Exemple #3
0
def restart(signum, stack):
    logger = get_logger()
    logger.info('Restart...')
    PID = int(open(PIDPATH, 'r').read())
    pf = os.path.join(os.path.dirname(__file__), __file__)
    cmd = r'kill -9 {0} && python {1} '.format(PID, pf)
    subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE,
                     stderr = subprocess.PIPE, shell = True)
Exemple #4
0
 def __init__(self, bot_jid, stream):
     self.bot_jid = bot_jid
     self._stream = stream
     self.cmd_handler = CommandHandler(message_bus = self)
     self.admin_cmd_handler = AdminCMDHandler(message_bus = self)
     self._thread_pool = ThreadPool(5)
     self._thread_pool.start()         # 启动线程池
     self.logger = get_logger()
     return
Exemple #5
0
    def __init__(self):
        my_jid = JID(USER+'/Bot')
        self.my_jid = my_jid
        settings = XMPPSettings({
                            "software_name": "Clubot",
                            "software_version": __version__,
                            "software_os": "Linux",
                            "tls_verify_peer": False,
                            "starttls": True,
                            "ipv6":False,
                            })

        settings["password"] = PASSWORD
        version_provider = VersionProvider(settings)
        self.connected = False
        self.client = Client(my_jid, [self, version_provider], settings)
        self.logger = get_logger()
        self.trytimes = 0
        empty_status()
Exemple #6
0
        except OSError, e:
            logger.error("Daemon started failed: %d (%s)", e.errno, e.strerror)
            os.exit(1)
    while True:
        bot = BotChat()
        try:
            bot.run()
        except pyxmpp2.exceptions.SASLAuthenticationFailed:
            logger.error('Username or Password Error!!!')
            sys.exit(2)
        bot.connected = False
        if not bot.connected:
            bot.disconnect()
            bot.trytimes += 1
            sleeptime = 10 * bot.trytimes
            logger = get_logger()
            logger.info('Connect failed, will retry in {0}s of '
                        '{1} times'.format(sleeptime, bot.trytimes))
            time.sleep(sleeptime)


def restart(signum, stack):
    logger = get_logger()
    logger.info('Restart...')
    PID = int(open(PIDPATH, 'r').read())
    pf = os.path.join(os.path.dirname(__file__), __file__)
    cmd = r'kill -9 {0} && python {1} '.format(PID, pf)
    subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE,
                     stderr = subprocess.PIPE, shell = True)

signal.signal(signal.SIGHUP, restart)