Пример #1
0
def main():
    parser = MyParser()
    parser.add_argument('-s', '--server', type=str, default='ws://127.0.0.1:5000/ivc', help='websocket RPC server, default: ws://127.0.0.1:5000/ivc')
    parser.add_argument('-f', '--file', type=str, help='Json file to send')

    args = parser.parse_args()
    if args.file is None:
        print('No JSON file is given\n')
        parser.print_help()
        sys.exit(2)

    ws_url = args.server+'?'+urllib.urlencode(
        {
            'login_code': 'broadcast_client',
            'login_passwd': 'passwd',
            'project': 'broadcast',
        })
    with open(args.file) as f:
        data = json.load(f)
    WSClientTransport.APP_FACTORY = IVTSession
    client = WSClientTransport(ws_url)
    client.connect()
    print data
    for entry in data:
        print entry
        client.app().broadcast(entry)
        log.info("{0} sent".format(entry))
    client.close()
    client.wait_close()
Пример #2
0
Файл: main.py Проект: dulton/IVR
def main():
    default_log_config(debug=True)
    import logging
    log = logging.getLogger(__name__)

    try:
        if len(sys.argv) == 2:
            config = parse_conf(sys.argv[1])
        else:
            config = parse_conf('ivt.yml')
        config = config_schema.validate(config)

        ivt = IVT(
            config['project'],
            config['login_code'],
            config['login_passwd'],
            config['keepalive_interval'],
            config['cameras'],
            preview_upload_server=config.get('preview_upload_server')
        )

        # start port
        port = SubProcessPort(
            port_name=config['login_code'],
            port_type=RTSP_PORT_PROGRAM_NAME,
            log_file= RTSP_PORT_PROGRAM_NAME + '.log',
        )
        port.start()

        # connect to IVC
        WSClientTransport.APP_FACTORY = ivt.ivt_session_factory
        url = config['ivc']+'?'+urllib.urlencode(
            {
                'login_code': config['login_code'],
                'login_passwd': config['login_passwd'],
                'project': config['project']
            }
        )
        while True:
            try:
                client = WSClientTransport(url)
                client.connect()
                client.wait_close()
                time.sleep(10)
            except:
                log.exception("Client session closed")
                time.sleep(10)

    except Exception:
        log.exception('Failed to start IVT')
Пример #3
0
 def run(self):
     while not self._quit:
         try:
             client = WSClientTransport(self.ws_url)
             client.connect()
             client.wait_close()
         except:
             log.exception("Client session closed")
         finally:
             if not self._quit:
                 self._retry_evt.wait(timeout=30)
                 self._retry_evt.clear()
     self._done_upgrade_evt.wait()
     log.info('Quit')
     sys.exit(0)
Пример #4
0
def main():
    default_log_config(debug=True)
    import logging
    log = logging.getLogger(__name__)

    try:
        if len(sys.argv) == 2:
            config = parse_conf(sys.argv[1])
        else:
            config = parse_conf('ivt.yml')
        config = config_schema.validate(config)

        ivt = IVT(config['project'],
                  config['login_code'],
                  config['login_passwd'],
                  config['keepalive_interval'],
                  config['cameras'],
                  preview_upload_server=config.get('preview_upload_server'))

        # start port
        port = SubProcessPort(
            port_name=config['login_code'],
            port_type=RTSP_PORT_PROGRAM_NAME,
            log_file=RTSP_PORT_PROGRAM_NAME + '.log',
        )
        port.start()

        # connect to IVC
        WSClientTransport.APP_FACTORY = ivt.ivt_session_factory
        url = config['ivc'] + '?' + urllib.urlencode(
            {
                'login_code': config['login_code'],
                'login_passwd': config['login_passwd'],
                'project': config['project']
            })
        while True:
            try:
                client = WSClientTransport(url)
                client.connect()
                client.wait_close()
                time.sleep(10)
            except:
                log.exception("Client session closed")
                time.sleep(10)

    except Exception:
        log.exception('Failed to start IVT')