From 4614e75059aa724f6b490499ea1288b2a2009caa Mon Sep 17 00:00:00 2001 From: yumiguan <41277086+yumiguan@users.noreply.github.com> Date: Thu, 11 Jun 2020 15:08:26 +0800 Subject: [PATCH] feature/clear-apk-file-when-start (#46) * reset apk file dir when start Lyrebird * remove useless import --- lyrebird_android/android_helper.py | 2 ++ lyrebird_android/apis.py | 5 ++++- lyrebird_android/device_service.py | 19 +++++++++++++------ setup.py | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lyrebird_android/android_helper.py b/lyrebird_android/android_helper.py index 9999eb2..2fe5cd9 100644 --- a/lyrebird_android/android_helper.py +++ b/lyrebird_android/android_helper.py @@ -5,6 +5,7 @@ import lyrebird import threading import subprocess +from pathlib import Path from . import config from lyrebird.log import get_logger @@ -25,6 +26,7 @@ anr_dir = os.path.abspath(os.path.join(storage, 'anr')) crash_dir = os.path.abspath(os.path.join(storage, 'crash')) screenshot_dir = os.path.abspath(os.path.join(storage, 'screenshot')) +apk_dir = Path(storage)/'apk' if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) diff --git a/lyrebird_android/apis.py b/lyrebird_android/apis.py index 86c16ea..cde67a2 100644 --- a/lyrebird_android/apis.py +++ b/lyrebird_android/apis.py @@ -21,6 +21,7 @@ anr_dir = os.path.abspath(os.path.join(storage, 'anr')) screenshot_dir = os.path.abspath(os.path.join(storage, 'screenshot')) launch_config_path = Path(storage)/'launch_config' +apk_dir = Path(storage)/'apk' if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) @@ -318,7 +319,9 @@ def download_application(): app_url = request.json.get('appUrl') app_url_obj = urlparse(app_url) app_name = app_url_obj.path.split('/')[-1] - app_file = Path(tmp_dir)/app_name + + apk_dir.mkdir(parents=True, exist_ok=True) + app_file = apk_dir/app_name if not app_file.name.endswith('.apk'): return make_fail_response(f'Unexpected type: {app_file.stem}, url: {app_url}') diff --git a/lyrebird_android/device_service.py b/lyrebird_android/device_service.py index 73c9dd3..6f7fe59 100644 --- a/lyrebird_android/device_service.py +++ b/lyrebird_android/device_service.py @@ -1,6 +1,6 @@ -import os import shutil import lyrebird +from pathlib import Path from lyrebird import context, get_logger from . import android_helper from . import config @@ -25,7 +25,7 @@ def __init__(self): self.status = self.READY self.handle_interval = 1 self.devices = {} - self.reset_screenshot_dir() + self.reset_resources_dir() logger.debug('DeviceService OnCreate') def check_env(self): @@ -101,7 +101,14 @@ def publish_devices_package_info(online_devices, package_name): lyrebird.publish('android.device', devices_info_list, state=True) @staticmethod - def reset_screenshot_dir(): - if os.path.exists(android_helper.screenshot_dir): - shutil.rmtree(android_helper.screenshot_dir) - logger.debug('Android device log file reset') + def reset_resources_dir(): + reset_dir = [ + Path(android_helper.screenshot_dir), + Path(android_helper.apk_dir) + ] + + for path in reset_dir: + if path.exists(): + shutil.rmtree(path) + + logger.debug('Android device log file reset') diff --git a/setup.py b/setup.py index f9bdf22..3d075e2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='lyrebird-android', - version='0.5.6', + version='0.5.7', packages=['lyrebird_android'], url='https://github.com/meituan/lyrebird-android', author='HBQA',