| 33 | from module.exception import * |
| 34 | |
| 35 | class Script: |
| 36 | def __init__(self, config_name: str ='oas') -> None: |
| 37 | logger.hr('Start', level=0) |
| 38 | self.server = None |
| 39 | self.state_queue: Queue = None |
| 40 | self.gui_update_task: Callable = None # 回调函数, gui进程注册当每次config更新任务的时候更新gui的信息 |
| 41 | self.config_name = config_name |
| 42 | # Skip first restart |
| 43 | self.is_first_task = True |
| 44 | # Failure count of tasks |
| 45 | # Key: str, task name, value: int, failure count |
| 46 | self.failure_record = {} |
| 47 | # 运行loop的线程 |
| 48 | self.loop_thread: Thread = None |
| 49 | |
| 50 | @cached_property |
| 51 | def config(self) -> "Config": |
| 52 | try: |
| 53 | from module.config.config import Config |
| 54 | config = Config(config_name=self.config_name) |
| 55 | return config |
| 56 | except RequestHumanTakeover: |
| 57 | logger.critical('Request human takeover') |
| 58 | exit(1) |
| 59 | except Exception as e: |
| 60 | logger.exception(e) |
| 61 | exit(1) |
| 62 | |
| 63 | @cached_property |
| 64 | def device(self) -> "Device": |
| 65 | try: |
| 66 | from module.device.device import Device |
| 67 | device = Device(config=self.config) |
| 68 | return device |
| 69 | except RequestHumanTakeover: |
| 70 | logger.critical('Request human takeover') |
| 71 | exit(1) |
| 72 | except Exception as e: |
| 73 | logger.exception(e) |
| 74 | exit(1) |
| 75 | |
| 76 | @cached_property |
| 77 | def checker(self): |
| 78 | """ |
| 79 | 占位函数,在alas中是检查服务器是否正常的 |
| 80 | :return: |
| 81 | """ |
| 82 | return None |
| 83 | |
| 84 | def save_error_log(self): |
| 85 | """ |
| 86 | Save last 60 screenshots in ./log/error/<timestamp> |
| 87 | Save logs to ./log/error/<timestamp>/log.txt |
| 88 | """ |
| 89 | from module.base.utils import save_image |
| 90 | from module.handler.sensitive_info import (handle_sensitive_image, |
| 91 | handle_sensitive_logs) |
| 92 | if self.config.script.error.save_error: |