Skip to content

Commit

Permalink
feature/clear-apk-file-when-start (#46)
Browse files Browse the repository at this point in the history
* reset apk file dir when start Lyrebird

* remove useless import
  • Loading branch information
yumiguan authored Jun 11, 2020
1 parent c35c4ea commit 4614e75
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lyrebird_android/android_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lyrebird
import threading
import subprocess
from pathlib import Path
from . import config
from lyrebird.log import get_logger

Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion lyrebird_android/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}')
Expand Down
19 changes: 13 additions & 6 deletions lyrebird_android/device_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4614e75

Please sign in to comment.