def start(emu, install_config, host_port, log_path=None):
    log = logger.init(log_path)

    # stat emulators
    emu_started = emu.start()
    if not emu_started:
        log.error('Failed to start emulators')
        return False

    sleep(3)
    install_players_apks = partial(install_apks, install_config.players_apks)
    install_players_apks(emu)

    with emurepo.owned_emu():
        emurepo.EMU = emu

    # start switcher
    start_switcher(team_count=TEAM_COUNT,
                   on_bootstrap=install_players_apks,
                   log=log)

    # start apk grabber
    start_grabber(TEAM2BACK, delay=GRAB_DELAY, log=log)

    # start echo-pulse sender
    start_echo_sender(delay=30, team_count=TEAM_COUNT, log=log)

    # start api
    host, port = host_port
    start_webapp(host, port)

    return emu, lambda: install_players_apks(emu)
示例#2
0
    def run(self):
        cur_emu = self.emu1
        next_emu = self.emu2

        while self.active:
            # wait first
            wait_for_pushes = wait_first_push(self.team_count, self.log)
            self.log.info('GOT FIRST PUSH')
            # wait others (with emu locked)
            resume_pushes = wait_for_pushes()
            self.log.info('GOT ALL PUSHES')
            with emurepo.owned_emu():
                # semantic definitions
                emu_to_prepare = cur_emu  # will be prepared for next iteration
                emu_to_bootstrap = next_emu  # will be bootstraped soon

                # swap before critical actions
                cur_emu, next_emu = next_emu, cur_emu

                # patch global EMU
                emurepo.EMU = emu_to_bootstrap

                # bootstrap next emu
                self.bootstrap(emu_to_bootstrap)

                # run preparation in background
                # (after bootstrap to speed up)
                Thread(target=self.prepare, args=(emu_to_prepare, )).start()
            resume_pushes()
    def background_api():
        try:
            app.run(host='172.16.92.133', port=31337)
        except KeyboardInterrupt:
            print('STOPPING !!!!!1')
        except Exception:
            print('FAILED BLYA:', str(ex))

        with emurepo.owned_emu() as emu:
            emu.kill()
示例#4
0
    def _switcher():
        while True:
            wait_for_pushes = wait_first_push(team_count, log)
            log.info('GOT FIRST PUSH')
            resume_pushes = wait_for_pushes()
            log.info('GOT ALL PUSHES')
            with emurepo.owned_emu() as emu:
                emu.reset()
                sleep(3)
                on_bootstrap(emu)
            resume_pushes()

            iso_dt = datetime.now().isoformat()
            for idx in range(1, team_count + 1):
                p = run(['bash', './save_apk.sh', str(idx), iso_dt])
                log.info(f'Team#{idx} APK saved to {iso_dt}.apk')
示例#5
0
def start_switcher2(emu1, emu2, *, team_count, on_prepare, on_bootstrap, log):
    with emurepo.owned_emu():
        emurepo.EMU = emu1
        switcher = EmuSwitcher(
            emu1,
            emu2,
            team_count=team_count,
            on_prepare=on_prepare,
            on_bootstrap=on_bootstrap,
            log=log,
        )
        on_prepare(emu1)
        on_prepare(emu2)
        on_bootstrap(emu1)

        switcher.start()
    return switcher
def SrvWithEmu():
    import emurepo
    from api import app

    with emurepo.owned_emu():
        emu = Team1()
        emu.start()
        emurepo.EMU = emu

    def background_api():
        try:
            app.run(host='172.16.92.133', port=31337)
        except KeyboardInterrupt:
            print('STOPPING !!!!!1')
        except Exception:
            print('FAILED BLYA:', str(ex))

        with emurepo.owned_emu() as emu:
            emu.kill()

    Thread(target=background_api).start()

    return emurepo.owned_emu