def check_link(auto_adb): adb_host_port = ConfigUtils.get('adb_host_port') print('检测设备连接状态 >>> %s ...' % adb_host_port) auto_adb.run('connect %s' % adb_host_port) device_list = get_devices(auto_adb) if len(device_list) == 0: print('未检测到设备,请检查ADB地址配置,或参考 https://github.com/FirstJavaMaster/AzurLaneScripts/blob/master/README.md') exit(1) target_device = None print('\n设备列表:') for device in device_list: print(device) if adb_host_port in device: target_device = device print() # 设备没找到 if target_device is None: print('设备列表中没找到目标连接(%s),请检查配置是否正确' % adb_host_port) exit(1) # 如果找到了设备,但是离线状态 if 'offline' in target_device: print('检测到设备离线!!!') print('由于不同模拟器ADB实现细节不同,请尝试以下办法(没有先后顺序):') print('· 重启模拟器') print('· 如果模拟器已经自带了ADB,则可以尝试将脚本中adb文件夹的文件拷贝至模拟器自带ADB目录。注意备份原文件') print('· 在adb目录下打开cmd,执行 adb kill-server 后再执行 adb start-server,然后执行 adb devices 查看是否解决') print('· 重启电脑') print('· 换个模拟器') exit(1) # 设备正常 print('设备已连接', end='\n\n')
def _reinstall_components(self, repo_names): self.run_command( ['pip3', 'uninstall', '--yes', '-q', 'googleapis-artman']) self.run_command([ 'pip3', 'install', '-q', '-e', self._guest.guest_root_subpath('artman') ]) self.run_command(['rm', '-rf', '/artman']) self.run_command(['rm', '-rf', '/googleapis']) self.run_command(['rm', '-rf', '/toolkit']) self._guest.guest_root_subpath('toolkit') artman_config = { 'local': { 'toolkit': self._guest.guest_root_subpath(repo_names['toolkit']) } } ConfigUtils.dump_config(artman_config, '/root/.artman/config.yaml')
def check_link(auto_adb): print('检测设备 ...') device_number = check_link_number(auto_adb) if device_number < 1: adb_host_port = ConfigUtils.get('adb_host_port') if adb_host_port is not None: auto_adb.run('connect %s' % adb_host_port) device_number = check_link_number(auto_adb) if device_number < 1: print('未检测到设备, 请参考 https://github.com/FirstJavaMaster/AzurLaneScripts/blob/master/README.md') exit(1) if device_number > 2: print('设备数量过多, 请参考 https://github.com/FirstJavaMaster/AzurLaneScripts/blob/master/README.md') exit(1) print('设备已连接', end='\n\n')
def run(): # 计数 num = 0 # 最大通关次数 max_stage_fight_times = int(ConfigUtils.get('max_stage_fight_times')) # 循环战斗 while True: # 选择关卡 开始战斗 target_stage_list = PathUtils.get_temp_rel_path_list('temp_images/target-stage') StageFight.fight_stage(target_stage_list) # 计数 num += 1 print('通关次数累计:%d' % num, end='\n\n') if max_stage_fight_times is not None and num >= max_stage_fight_times: print('已达最大通关次数 %d,结束运行' % max_stage_fight_times) exit()
def run(): # 计数 fight_recorder = FightRecorder() # 最大通关次数 max_stage_fight_times = int(ConfigUtils.get('max_stage_fight_times')) # 循环战斗 while True: # 选择关卡 开始战斗 target_stage_list = PathUtils.get_temp_rel_path_list('temp_images/target-stage') fight_result = StageFight.fight_stage(target_stage_list) # 计数 fight_recorder.append(fight_result) fight_recorder.print_recorder() # 连续失败两次就停止战斗 if fight_recorder.get_last_fail_count() >= 2: print('连续 2 次关卡战斗失败, 为了避免更多损失脚本自动退出') exit() if max_stage_fight_times is not None and fight_recorder.get_total_count() >= max_stage_fight_times: print('已达最大通关次数 %d,结束运行' % max_stage_fight_times) exit()
def check_port_full(): adb = AutoAdb() port_full = adb.check('temp_images/port/port-full.png') if not port_full: return False print('船坞已经满员了... ', end='') auto_retire = ConfigUtils.get('auto_retire', fallback=False) if auto_retire: print('开始自动退役... ') adb.wait('temp_images/port/port-full-retire.png').click() # 整理 adb.wait('temp_images/port/retire.png').click() # 一键退役 adb.wait('temp_images/port/retire-confirm.png').click() # 确定舰娘 adb.wait('temp_images/port/retire-confirm.png', max_wait_time=2).click() # 确定(可能出现的)精英舰娘 adb.wait('temp_images/port/retire-confirm-1.png').click() # (获得物资)点击继续 adb.wait('temp_images/port/retire-confirm.png').click() # 确定装备 adb.wait('temp_images/port/retire-confirm.png').click() # 确定物资 adb.wait('temp_images/port/retire-confirm-1.png').click() # (获得物资)点击继续 adb.wait('temp_images/port/cancel.png').click() # (获得物资)点击继续 print('退役完成, 程序继续执行') return True print('未启用自动退役配置, 程序退出') exit()
def run(self, raw_command): adb_host_port = ConfigUtils.get('adb_host_port') command = '%s -s %s %s' % (self.adb_path, adb_host_port, raw_command) res = os.popen(command) return res.buffer.read().decode('utf-8').strip()
def _archive_artifacts(self): self.run_command([ 'tar', '-pzcf', 'artifacts.tar.gz', '--remove-files', '-C', 'artifacts', '.' ], self._guest.guest_output_dir_path()) self.change_file_permissions( self._guest.guest_output_dir_subpath('artifacts.tar.gz')) # TODO: this is a hack, should be fixed in artman instead # (must be a way to configure output path) def _fix_generator_output(self): art_sub = ['artifacts', 'java'] lr_dir = 'gapic-google-cloud-longrunning-v1' lr_path = self._guest.guest_output_dir_subpath(art_sub + [lr_dir]) if os.path.exists(lr_path): new_lr_dir = 'gapic-google-longrunning-v1' cwd = self._guest.guest_output_dir_subpath(art_sub) self.run_command(['mv', lr_dir, new_lr_dir], cwd) if __name__ == '__main__': execution_config = ConfigUtils.read_config() if 'execution_id' not in execution_config: execution_config['execution_id'] = ConfigUtils.generate_id( 'java-src-stage-') step = SourcesGenerationGuest(execution_config) step.execute()
def _dump_output(self, output_yaml): output_yaml_path = self._guest.guest_output_dir_subpath( ConfigUtils.artifact_yaml_name()) ConfigUtils.dump_config(output_yaml, output_yaml_path) self.change_file_permissions(output_yaml_path)
# pr_head = "%s:%s" % (config['git_user_name'], config['git_branch']) pr_head = config['git_branch'] self.puts( 'Creating pull request, base: %s, head: %s' % (pr_base, pr_head)) pr = repo.create_pull( base=pr_base, body='This PR is automatically generated by Artmanflow tool', head=pr_head, title='Artman Workflow Java sources staging' ) if not pr: raise RuntimeError('Pull request creation failed.') self.puts('Pull request created successfully: %s' % pr.html_url) return pr.html_url def _dump_output(self, output_yaml): output_yaml_path = self._guest.guest_output_dir_subpath( ConfigUtils.artifact_yaml_name()) ConfigUtils.dump_config(output_yaml, output_yaml_path) self.change_file_permissions(output_yaml_path) if __name__ == '__main__': execution_config = ConfigUtils.read_config() step = JavaSourcesStagingGuest(execution_config) step.execute()