[Python] 纯文本查看 复制代码class Dnconsole:
# 请根据自己电脑配置
console = 'D:\\Changzhi\\dnplayer2\\dnconsole.exe '
ld = 'D:\\Changzhi\\dnplayer2\\ld.exe '
share_path = 'F:/share/Pictures'
#获取模拟器列表
@staticmethod
def get_list():
cmd = os.popen(Dnconsole.console + 'list2')
text = cmd.read()
cmd.close()
info = text.split('\n')
result = list()
for line in info:
if len(line) > 1:
dnplayer = line.split(',')
result.append(DnPlayer(dnplayer))
return result
#获取正在运行的模拟器列表
@staticmethod
def list_running() -> list:
result = list()
all = Dnconsole.get_list()
for dn in all:
if dn.is_running() is True:
result.append(dn)
return result
#检测指定序号的模拟器是否正在运行
@staticmethod
def is_running(index: int) -> bool:
all = Dnconsole.get_list()
if index >= len(all):
raise IndexError('%d is not exist' % index)
return all[index].is_running()
#执行shell命令
@staticmethod
def dnld(index: int, command: str, silence: bool = True):
cmd = Dnconsole.ld + '-s %d %s' % (index, command)
if silence:
os.system(cmd)
return ''
process = os.popen(cmd)
result = process.read()
process.close()
return result
#执行adb命令,不建议使用,容易失控
@staticmethod
def adb(index: int, command: str, silence: bool = False) -> str:
cmd = Dnconsole.console + 'adb --index %d --command "%s"' % (index, command)
if silence:
os.system(cmd)
return ''
process = os.popen(cmd)
result = process.read()
process.close()
return result
#安装apk 指定模拟器必须已经启动
@staticmethod
def install(index: int, path: str):
shutil.copy(pat