Refactor: Move del_cached_property to module.base.decorator

This commit is contained in:
LmeSzinc 2022-09-24 04:04:07 +08:00
parent 8e3f5ef51f
commit 4dd2a5a8b5
9 changed files with 29 additions and 37 deletions

View File

@ -7,7 +7,7 @@ from datetime import datetime, timedelta
import inflection
from cached_property import cached_property
from module.base.resource import del_cached_property
from module.base.decorator import del_cached_property
from module.config.config import AzurLaneConfig, TaskEnd
from module.config.utils import deep_get, deep_set
from module.exception import *

View File

@ -94,6 +94,20 @@ class cached_property:
return value
def del_cached_property(obj, name):
"""
Delete a cached property safely.
Args:
obj:
name (str):
"""
try:
del obj.__dict__[name]
except KeyError:
pass
def function_drop(rate=0.5, default=None):
"""
Drop function calls to simulate random emulator stuck, for testing purpose.

View File

@ -1,19 +1,7 @@
import re
import module.config.server as server
from module.base.decorator import cached_property
def del_cached_property(obj, name):
"""
Delete a cached property safely.
Args:
obj:
name (str):
"""
if name in obj.__dict__:
del obj.__dict__[name]
from module.base.decorator import cached_property, del_cached_property
def get_assets_from_file(file, regex):

View File

@ -1,8 +1,7 @@
import collections
from module.base.base import ModuleBase
from module.base.decorator import Config, cached_property
from module.base.resource import del_cached_property
from module.base.decorator import Config, cached_property, del_cached_property
from module.base.timer import Timer
from module.base.utils import *
from module.exception import CampaignNameError

View File

@ -11,13 +11,13 @@ import uiautomator2 as u2
from adbutils import AdbClient, AdbDevice, AdbTimeout, ForwardItem, ReverseItem
from adbutils.errors import AdbError
from module.base.decorator import Config, cached_property
from module.base.decorator import Config, cached_property, del_cached_property
from module.base.utils import ensure_time
from module.config.server import set_server
from module.device.connection_attr import ConnectionAttr
from module.device.method.utils import (RETRY_DELAY, RETRY_TRIES, remove_shell_warning,
handle_adb_error, PackageNotInstalled,
recv_all, del_cached_property, possible_reasons,
recv_all, possible_reasons,
random_port, get_serial_pair)
from module.exception import RequestHumanTakeover, EmulatorNotRunningError
from module.logger import logger
@ -225,7 +225,12 @@ class Connection(ConnectionAttr):
return host, port, host, self.config.REVERSE_SERVER_PORT
# For emulators, listen on current host
if self.is_emulator or self.is_over_http:
host = socket.gethostbyname(socket.gethostname())
try:
host = socket.gethostbyname(socket.gethostname())
except socket.gaierror as e:
logger.error(e)
logger.error(f'Unknown host name: {socket.gethostname()}')
host = '127.0.0.1'
if platform.system() == 'Linux' and host == '127.0.1.1':
host = '127.0.0.1'
logger.info(f'Connecting to local emulator, using host {host}')

View File

@ -10,12 +10,11 @@ import websockets
from adbutils.errors import AdbError
from uiautomator2 import _Service
from module.base.decorator import cached_property, Config
from module.base.decorator import Config, cached_property, del_cached_property
from module.base.timer import Timer
from module.base.utils import *
from module.device.connection import Connection
from module.device.method.utils import (RETRY_DELAY, RETRY_TRIES,
del_cached_property, handle_adb_error)
from module.device.method.utils import RETRY_DELAY, RETRY_TRIES, handle_adb_error
from module.exception import RequestHumanTakeover, ScriptError
from module.logger import logger

View File

@ -138,18 +138,6 @@ def handle_adb_error(e):
return False
def del_cached_property(obj, name):
"""
Delete a cached property safely.
Args:
obj:
name (str):
"""
if name in obj.__dict__:
del obj.__dict__[name]
def get_serial_pair(serial):
"""
Args:

View File

@ -1,4 +1,4 @@
from module.base.resource import del_cached_property
from module.base.decorator import del_cached_property
from module.base.timer import Timer
from module.base.utils import get_color, red_overlay_transparency
from module.exception import CampaignEnd

View File

@ -1,6 +1,5 @@
from module.base.button import ButtonGrid
from module.base.decorator import cached_property
from module.base.resource import del_cached_property
from module.base.decorator import cached_property, del_cached_property
from module.base.timer import Timer
from module.logger import logger
from module.map_detection.utils import Points