def set_root(self, is_root): run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} enable_su %d' % is_root, cwd=f'{self.memu.memu_dir}/MEmu') self.stop() self.start()
def restart(self): logger.debug(f'Запускаем nox') attempts = 10 for ii in range(attempts): try: run_command( f'{self.nox.nox_console_exe} reboot -name:{self.code}', cwd=f'{self.nox.nox_dir}/bin') sleep(20) break except Exception as e: logger.debug(str(e)) sleep(10) if ii == attempts - 1: raise Exception('error nox restart') sleep(10)
def create_device(self): # for line in traceback.format_stack(): # print(line.strip()) vms_output = run_command(f'{self.memu_console_exe} create', cwd=f'{self.memu_dir}/MEmu') sleep(20) return True
def get_prop(self, parameters): output = run_command( f'{self.nox.nox_console_exe} getprop -name:{self.code} -value:sys.boot_completed', cwd=f'{self.nox.nox_dir}/bin') fi = output.find(parameters) if fi == -1: return '' return output[fi:output.find('\r\r', fi)]
def get_devices(self): # vms_output = run_command(f'{self.nox_manager_exe} list vms') # out = run_command(f'cmd.exe cd /D {self.nox_dir}/bin') vms_output = run_command(f'{self.nox_console_exe} list', cwd=f'{self.nox_dir}/bin') devices = [] devices.append(NoxDevice('NoxPlayer', 0, self)) return devices
def adb(self, parameters, timeout=30): try: self._adb_address except: self._adb_address = None output = run_command( f'{self.memu.adb_exe} -s {self._adb_address} {parameters}', cwd=f'{self.memu.memu_dir}/MEmu', timeout=timeout) return output
def adb( self, cmd, timeout=30 ): # NoxConsole.exe adb <-name:nox_name | -index:nox_index> -command: output = run_command( f'{self.nox.nox_console_exe} adb -name:{self.code} -command:"{cmd}"', cwd=f'{self.nox.nox_dir}/bin', timeout=timeout) # output = run_command(f'{self.nox.adb_exe} -s {self._adb_address} {parameters}') return output
def get_vm_properties(self): values = {} out = run_command( f'{self.nox.nox_manager_exe} guestproperty enumerate {self.id}') for line in out.splitlines(): name, value = line.split('value:') name = name.split(':')[1] name = name.strip('\r\n\t :,') value = value.split(',')[0] value = value.strip('\r\n\t ') values[name] = value return values
def get_devices(self): # for line in traceback.format_stack(): # print(line.strip()) vms_output = run_command(f'{self.memu_manager_exe} list vms', cwd=f'{self.memu_dir}/MEmuHyperv') devices = [] for line in vms_output.splitlines(): if '{' in line: name, id = line.split('{') name = name.strip('\r\n\t "') id = id.split('}')[0] devices.append(MemuDevice(name, id, self)) logger.debug(f'Нашли memu устройство {name} {id}') return devices
def start(self): logger.debug(f'Запускаем nox') run_command(f'{self.nox.nox_console_exe} launch -name:{self.code}', cwd=f'{self.nox.nox_dir}/bin') sleep(20)
def _get_vm_info(self, id): return run_command(f'{self.memu_manager_exe} showvminfo {id}', cwd=f'{self.memu_dir}/MEmuHyperv')
def recreate1(self, delete_old=True): try: if delete_old: logger.debug(f'Пересоздаем {self.name}') self.stop() for ii in range(10): # удаление проходит всегда с ошибкой (видимо это нормально) try: run_command( f'{self.memu.memu_manager_exe} unregistervm "{self.code}" --delete', cwd=f'{self.memu.memu_dir}/MEmuHyperv') except Exception as e: if str(e).find('...100%') == -1: if ii > 8: break sleep(1) else: break run_command(f'{self.memu.memu_console_exe} create', cwd=f'{self.memu.memu_dir}/MEmu') while not os.path.isfile(self.memu.memu_dir + '/MEmu/MemuHyperv VMs/' + self.code + '/' + self.code + '.memu'): sleep(5) sleep(5) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} enable_su 1', cwd=f'{self.memu.memu_dir}/MEmu') sleep(1) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} is_customed_resolution 1', cwd=f'{self.memu.memu_dir}/MEmu') sleep(1) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} resolution_width 850', cwd=f'{self.memu.memu_dir}/MEmu') sleep(1) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} resolution_height 500', cwd=f'{self.memu.memu_dir}/MEmu') sleep(1) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} vbox_dpi 133', cwd=f'{self.memu.memu_dir}/MEmu') sleep(1) sleep(1) run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} lang en', cwd=f'{self.memu.memu_dir}/MEmu') mac = generate_mac() run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.code} hmac "%s"' % mac, cwd=f'{self.memu.memu_dir}/MEmu') # out = self.adb('''shell "getprop"''') self.start() sleep(12) except Exception as e: logger.debug(str(e))
def _set_vm_property(self, key, value): out = run_command( f'{self.memu.memu_manager_exe} guestproperty set {self.id} {key} {value}', cwd=f'{self.memu.memu_dir}/MEmuHyperv') a = 1
def stop(self): # logger.debug(f'Останавливаем {self.name}') logger.debug(f'Останавливаем nox') run_command(f'{self.nox.nox_console_exe} quit -name:{self.code}', cwd=f'{self.nox.nox_dir}/bin') sleep(2)
def stop(self): logger.debug(f'Останавливаем {self.name}') run_command(f'{self.memu.memu_console_exe} ShutdownVM {self.code}', cwd=f'{self.memu.memu_dir}/MEmu') sleep(5)
def start(self): logger.debug(f'Запускаем {self.name}') run_command(f'{self.memu.memu_console_exe} {self.code}', cwd=f'{self.memu.memu_dir}/MEmu') sleep(5)
def _set_vm_property(self, key, value): out = run_command( f'{self.nox.nox_console_exe} setprop -name:{self.code} -key:{key} -value:{value}', cwd=f'{self.nox.nox_dir}/bin') a = 1
def _get_vm_info(self, id): return run_command(f'{self.nox_manager_exe} showvminfo {id}')