1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 19:01:15 +01:00

Merge pull request #229 from ep1cman/dependencies

pylint fixes
This commit is contained in:
setrofim 2016-08-25 14:25:42 +01:00 committed by GitHub
commit 64860a2d1a
3 changed files with 23 additions and 22 deletions

View File

@ -14,7 +14,6 @@
#
import sys
import logging
import argparse
from requests import ConnectionError, RequestException
@ -25,6 +24,7 @@ from wlauto.core.extension import Extension
REMOTE_ASSETS_URL = 'https://github.com/ARM-software/wa-assets/raw/master/dependencies'
class GetAssetsCommand(Command):
name = 'get-assets'
description = '''
@ -40,14 +40,14 @@ class GetAssetsCommand(Command):
def initialize(self, context):
self.parser.add_argument('-f', '--force', action='store_true',
help='Always fetch the assets, even if matching versions exist in local cache.')
self.parser.add_argument('--url', metavar='URL', type=self.not_empty, default=self.assets_url,
self.parser.add_argument('--url', metavar='URL', type=not_empty, default=self.assets_url,
help='''The location from which to download the files. If not provided,
config setting ``remote_assets_url`` will be used if available, else
uses the default REMOTE_ASSETS_URL parameter in the script.''')
group = self.parser.add_mutually_exclusive_group(required=True)
group.add_argument('-a', '--all', action='store_true',
help='Download assets for all extensions found in the index. Cannot be used with -e.')
group.add_argument('-e', dest='exts', metavar='EXT', nargs='+', type=self.not_empty,
group.add_argument('-e', dest='exts', metavar='EXT', nargs='+', type=not_empty,
help='One or more extensions whose assets to download. Cannot be used with --all.')
def execute(self, args):
@ -100,12 +100,6 @@ class GetAssetsCommand(Command):
for asset in all_assets[ext_name]:
getter.get(File(owner, asset)) # Download the files
def not_empty(self, val):
if val:
return val
else:
raise argparse.ArgumentTypeError('Extension name cannot be blank')
def exit_with_error(self, message, code=1):
self.logger.error(message)
sys.exit(code)
@ -117,5 +111,12 @@ class NamedExtension(Extension):
self.name = name
def not_empty(val):
if val:
return val
else:
raise argparse.ArgumentTypeError('Extension name cannot be blank')
def _instantiate(cls, *args, **kwargs):
return cls(*args, **kwargs)

View File

@ -22,12 +22,11 @@ from wlauto.core.extension import Parameter
from wlauto.core.workload import Workload
from wlauto.core.resource import NO_ONE
from wlauto.common.android.resources import ApkFile
from wlauto.common.resources import ExtensionAsset, Executable
from wlauto.common.resources import ExtensionAsset, Executable, File
from wlauto.exceptions import WorkloadError, ResourceError, ConfigError, DeviceError
from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS, UNSUPPORTED_PACKAGES
from wlauto.utils.types import boolean
from wlauto.utils.revent import ReventParser
from wlauto import File
import wlauto.utils.statedetect as state_detector
import wlauto.common.android.resources
@ -346,6 +345,8 @@ class ReventWorkload(Workload):
self.revent_run_file = None
self.on_device_setup_revent = None
self.on_device_run_revent = None
self.statedefs_dir = None
self.check_states = None
def initialize(self, context):
self.revent_setup_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'setup'))
@ -419,6 +420,7 @@ class ReventWorkload(Workload):
msg = "State definitions or template files missing or invalid ({}). Skipping state detection."
self.logger.warning(msg.format(e.message))
class AndroidUiAutoBenchmark(UiAutomatorWorkload, AndroidBenchmark):
supported_platforms = ['android']
@ -525,7 +527,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
ApkWorkload.init_resources(self, context)
ReventWorkload.init_resources(self, context)
if self.check_states:
self._check_statedetection_files(self, context)
self._check_statedetection_files(context)
def setup(self, context):
ApkWorkload.setup(self, context)
@ -535,7 +537,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
# state detection check if it's enabled in the config
if self.check_states:
self.check_state(self, context, "setup_complete")
self.check_state(context, "setup_complete")
def do_post_install(self, context):
ApkWorkload.do_post_install(self, context)
@ -558,7 +560,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
def teardown(self, context):
# state detection check if it's enabled in the config
if self.check_states:
self.check_state(self, context, "run_complete")
self.check_state(context, "run_complete")
if not self.saved_state_file:
ApkWorkload.teardown(self, context)

View File

@ -42,8 +42,7 @@ except ImportError:
class StateDefinitionError(RuntimeError):
def __init__(self, arg):
self.args = arg
pass
def auto_canny(image, sigma=0.33):
@ -59,9 +58,9 @@ def auto_canny(image, sigma=0.33):
return edged
def match_state(screenshot_file, defpath, state_definitions):
def match_state(screenshot_file, defpath, state_definitions): # pylint: disable=too-many-locals
# check dependencies
if np == None or cv2 == None or imutils == None:
if np is None or cv2 is None or imutils is None:
raise RuntimeError("State detection requires numpy, opencv (cv2) and imutils.")
# check if file exists, then load screenshot into opencv and create edge map
@ -78,15 +77,14 @@ def match_state(screenshot_file, defpath, state_definitions):
# check all template PNGs exist
for template_png in template_list:
if not os.path.isfile(os.path.join(defpath, 'templates', template_png+'.png')):
if not os.path.isfile(os.path.join(defpath, 'templates', template_png + '.png')):
raise StateDefinitionError("Missing template PNG file: " + template_png + ".png")
# try to match each PNG
matched_templates = []
for template_png in template_list:
template = cv2.imread(os.path.join(defpath, 'templates', template_png+'.png'), 0)
template = cv2.imread(os.path.join(defpath, 'templates', template_png + '.png'), 0)
template_edge = auto_canny(template)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_edge, template_edge, cv2.TM_CCOEFF_NORMED)
threshold = 0.5
@ -117,7 +115,7 @@ def verify_state(screenshot_file, state_defs_path, workload_phase):
# load and parse state definition file
statedefs_file = os.path.join(state_defs_path, 'definition.yaml')
if not os.path.isfile(statedefs_file):
raise StateDefinitionError("Missing state definitions yaml file: "+statedefs_file)
raise StateDefinitionError("Missing state definitions yaml file: " + statedefs_file)
with open(statedefs_file) as fh:
state_definitions = yaml.load(fh)