mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-23 00:52:22 +00:00
Add: 增加了出错时保存log和截图的功能
- 更改了Log的目录名称
This commit is contained in:
parent
b94baf8831
commit
49ddd8d85f
28
alas.py
28
alas.py
@ -1,5 +1,9 @@
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.logger import logger, pyw_name
|
||||
from module.logger import logger, pyw_name, log_file
|
||||
|
||||
|
||||
class AzurLaneAutoScript:
|
||||
@ -9,6 +13,28 @@ class AzurLaneAutoScript:
|
||||
ini_name = ini_name.lower()
|
||||
self.config = AzurLaneConfig(ini_name)
|
||||
|
||||
def run(self, command):
|
||||
try:
|
||||
self.__getattribute__(command.lower())()
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
if self.config.ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE:
|
||||
folder = f'./log/error/{int(time.time() * 1000)}'
|
||||
logger.info(f'Saving error: {folder}')
|
||||
os.mkdir(folder)
|
||||
for index, image in enumerate(logger.screenshot_deque):
|
||||
image.save(f'{folder}/{index}.png')
|
||||
with open(log_file, 'r') as f:
|
||||
start = 0
|
||||
for index, line in enumerate(f.readlines()):
|
||||
if re.search('\+-{15,}\+', line):
|
||||
start = index
|
||||
with open(log_file, 'r') as f:
|
||||
text = f.readlines()[start - 2:]
|
||||
with open(f'{folder}/log.txt', 'w') as f:
|
||||
f.writelines(text)
|
||||
|
||||
def setting(self):
|
||||
for key, value in self.config.config['Setting'].items():
|
||||
print(f'{key} = {value}')
|
||||
|
@ -78,6 +78,7 @@ urgent_ship = 155
|
||||
command = emulator
|
||||
serial = 127.0.0.1:62001
|
||||
package_name = com.bilibili.azurlane
|
||||
enable_error_log_and_screenshot_save = yes
|
||||
enable_perspective_error_image_save = no
|
||||
use_adb_screenshot = yes
|
||||
use_adb_control = no
|
||||
|
@ -210,6 +210,7 @@ def main(ini_name=''):
|
||||
emulator.add_argument('--包名', default=default('--包名'), help='如果不是Biliibli国服, 或者使用了非官方客户端, 需修改')
|
||||
|
||||
debug = emulator_parser.add_argument_group('调试设置', '')
|
||||
debug.add_argument('--出错时保存log和截图', default=default('--出错时保存log和截图'), choices=['是', '否'])
|
||||
debug.add_argument('--保存透视识别出错的图像', default=default('--保存透视识别出错的图像'), choices=['是', '否'])
|
||||
|
||||
adb = emulator_parser.add_argument_group('ADB设置', '')
|
||||
@ -309,7 +310,4 @@ def main(ini_name=''):
|
||||
|
||||
# Call AzurLaneAutoScript
|
||||
alas = AzurLaneAutoScript(ini_name=ini_name)
|
||||
try:
|
||||
alas.__getattribute__(command.lower())()
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
alas.run(command=command)
|
||||
|
@ -169,7 +169,10 @@ class AzurLaneConfig:
|
||||
"""
|
||||
error_log
|
||||
"""
|
||||
PERSPECTIVE_ERROR_LOG_FOLDER = './log/perspective_error'
|
||||
ERROR_LOG_FOLDER = './log/error'
|
||||
ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE = True
|
||||
ENABLE_PERSPECTIVE_ERROR_IMAGE_SAVE = False
|
||||
|
||||
"""
|
||||
module.map.fleet
|
||||
@ -238,7 +241,7 @@ class AzurLaneConfig:
|
||||
),
|
||||
MID_DIFF_RANGE
|
||||
)
|
||||
ENABLE_PERSPECTIVE_ERROR_IMAGE_SAVE = False
|
||||
|
||||
"""
|
||||
module.daemon
|
||||
"""
|
||||
@ -291,7 +294,8 @@ class AzurLaneConfig:
|
||||
|
||||
def create_folder(self):
|
||||
self.SCREEN_SHOT_SAVE_FOLDER = self.SCREEN_SHOT_SAVE_FOLDER_BASE + '/' + self.CAMPAIGN_NAME
|
||||
for folder in [self.SCREEN_SHOT_SAVE_FOLDER_BASE, self.ASSETS_FOLDER, self.SCREEN_SHOT_SAVE_FOLDER, self.ERROR_LOG_FOLDER]:
|
||||
for folder in [self.SCREEN_SHOT_SAVE_FOLDER_BASE, self.ASSETS_FOLDER, self.SCREEN_SHOT_SAVE_FOLDER,
|
||||
self.PERSPECTIVE_ERROR_LOG_FOLDER, self.ERROR_LOG_FOLDER]:
|
||||
if not os.path.exists(folder):
|
||||
os.mkdir(folder)
|
||||
|
||||
@ -333,6 +337,7 @@ class AzurLaneConfig:
|
||||
option = config['Emulator']
|
||||
self.SERIAL = option['serial']
|
||||
self.PACKAGE_NAME = option['package_name'].strip()
|
||||
self.ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE = to_bool(option['enable_error_log_and_screenshot_save'])
|
||||
self.ENABLE_PERSPECTIVE_ERROR_IMAGE_SAVE = to_bool(option['enable_perspective_error_image_save'])
|
||||
self.USE_ADB_SCREENSHOT = to_bool(option['use_adb_screenshot'])
|
||||
self.USE_ADB_CONTROL = to_bool(option['use_adb_control'])
|
||||
|
@ -105,6 +105,7 @@ dic_chi_to_eng = {
|
||||
'观舰类紧急委托': 'urgent_ship',
|
||||
'设备': 'serial',
|
||||
'包名': 'package_name',
|
||||
'出错时保存log和截图': 'enable_error_log_and_screenshot_save',
|
||||
'保存透视识别出错的图像': 'enable_perspective_error_image_save',
|
||||
'使用ADB截图': 'use_adb_screenshot',
|
||||
'使用ADB点击': 'use_adb_control',
|
||||
|
@ -6,6 +6,7 @@ from PIL import Image
|
||||
from retrying import retry
|
||||
|
||||
from module.device.connection import Connection
|
||||
from module.logger import logger
|
||||
|
||||
|
||||
class Screenshot(Connection):
|
||||
@ -61,6 +62,7 @@ class Screenshot(Connection):
|
||||
self.image = self._screenshot_uiautomator2()
|
||||
|
||||
self.image.load()
|
||||
logger.screenshot_deque.append(self.image)
|
||||
return self.image
|
||||
|
||||
def save_screenshot(self, genre='items'):
|
||||
|
@ -2,6 +2,7 @@ import logging
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
pyw_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
||||
if f'{pyw_name}.pyw' not in os.listdir('./'):
|
||||
@ -48,5 +49,6 @@ def attr(name, text):
|
||||
|
||||
logger.hr = hr
|
||||
logger.attr = attr
|
||||
logger.screenshot_deque = deque(maxlen=30)
|
||||
|
||||
logger.hr('Start', level=0)
|
||||
|
@ -406,5 +406,5 @@ class Perspective:
|
||||
return False
|
||||
|
||||
file = '%s.%s' % (int(time.time() * 1000), 'png')
|
||||
file = os.path.join(self.config.ERROR_LOG_FOLDER, file)
|
||||
file = os.path.join(self.config.PERSPECTIVE_ERROR_LOG_FOLDER, file)
|
||||
self.image.save(file)
|
||||
|
Loading…
Reference in New Issue
Block a user