def start(self, force=False, inprocess=False):

        if inprocess:
            server = MessageServer(self._address, self.storeLocal,
                                   self._pidFile, self.echo)

            for address in self.forwardAddresses:
                client = MessageServerClient(address)
                server.forwardClients.add(client)

            server.start()
            return

        if self.isRunning and not force:
            printInDebugMode('Cannot start message server, already running')
            return

        command = self._createStartCommand()

        printInDebugMode('Starting message server with command: %s' % command)

        j.system.process.runDaemon(command)

        remainingSeconds = self._START_TIMEOUT
        time.sleep(5)
        while not self.isRunning:
            printInDebugMode('Waiting %d more seconds for message server to be'
                             ' started' % remainingSeconds)

            time.sleep(1)
            remainingSeconds -= 1

            if not remainingSeconds:
                raise RuntimeError('Failed to start message server')

        printInDebugMode('Started message server')
Example #2
0
File: inf.py Project: team55/vkbot
        return 'Good'
    return r


def leaveHandler(conf):
    conf = vk.getUserId(conf)
    if conf > CONF_START:
        conf -= CONF_START
    if vk.leaveConf(conf):
        return 'Ok'
    else:
        return 'Fail'


if config.get('inf.server_port', 'i'):
    srv = MessageServer()
    srv.addHandler('reply', lambda x: bot.interact('flat ' + x, False))
    srv.addHandler('stem', lambda x: bot.interact('stem ' + x, False))
    srv.addHandler('ignore', ignoreHandler)
    srv.addHandler('unignore', unignoreHandler)
    srv.addHandler('ban', banHandler)
    srv.addHandler('unban', unbanHandler)
    srv.addHandler('reload', reload)
    srv.addHandler('isignored', isignoredHandler)
    srv.addHandler('leave', leaveHandler)
    srv.listen()
    log.info('Running TCP server on port ' + config.get('inf.server_port'))

dialogs = 0
reply_all = timeto('includeread', includeread_interval)
Example #3
0
            "p4c-bm2-ss", path, "-o build/compiled.json",
            "--p4runtime-files build/program.p4info.txt", "--p4v 16"
        ]
        compiler = subprocess.run(" ".join(cmd),
                                  stderr=subprocess.PIPE,
                                  shell=True)
        if compiler.stderr:
            raise IOError(
                f"Could not compile program:\n {compiler.stderr.decode()}")

        self.software_path = "build/compiled.json"

    def update(self, program) -> None:
        self.uninstall()
        self.install(program)

    def uninstall(self) -> None:
        self.logger.info("Software uninstalled")
        self.software_path = None

    def restart(self) -> None:
        if self.process is not None:
            self.stop()
            self.start()


if __name__ == "__main__":
    driver = SimpleSwitchDriver("s1")
    with MessageServer("", 5555, driver.handle_message) as server:
        server.run()
Example #4
0
 def start_daemon(self):
     self.server = MessageServer("", 5555, self.handle_message)
     self.server.start()
Example #5
0
#!/usr/bin/python3

from vars import log_file, socket_port
import logging
import os
from server import MessageServer

if os.path.exists(log_file):
    os.remove(log_file)

logging.basicConfig(level=logging.DEBUG, filename=log_file)

MessageServer(socket_port).start()
Example #6
0
        return '\n'.join(result)
    else:
        return 'No one banned!'

# noinspection PyUnusedLocal
def ignlistHandler(*p):
    if friend_controller.noadd:
        result = sorted(i for i in friend_controller.noadd if i > CONF_START)
        result = [str(j) + ' ' + vk.printableName(j, user_fmt='') for j in result]
        return '\n'.join(result)
    else:
        return 'No confs ignored!'


if config.get('server.port', 'i') > 0:
    srv = MessageServer(config.get('server.port', 'i'))
    srv.addHandler('reply', lambda x: bot.interact('flat ' + x, False))
    srv.addHandler('stem', lambda x: bot.interact('stem ' + x, False))
    srv.addHandler('ignore', ignoreHandler)
    srv.addHandler('unignore', unignoreHandler)
    srv.addHandler('ban', banHandler)
    srv.addHandler('unban', unbanHandler)
    srv.addHandler('reload', reloadHandler)
    srv.addHandler('isignored', isignoredHandler)
    srv.addHandler('leave', leaveHandler)
    srv.addHandler('banlist', banlistHandler)
    srv.addHandler('ignlist', ignlistHandler)
    srv.listen()
    logging.info('Running TCP server on port ' + config.get('server.port'))

friend_controller = vkbot.createFriendController()