def get_image_debug_path(): """Returns the root directory where a test's debug images are located.""" parent, test = PathManager.parse_module_path() path = os.path.join(parse_args().workdir, 'runs', PathManager.get_run_id(), parent, test, 'debug_images') return path
def delete_run_directory(): """Removes run directory.""" master_run_directory = os.path.join(parse_args().workdir, 'runs') run_directory = os.path.join(master_run_directory, PathManager.get_run_id()) if os.path.exists(run_directory): shutil.rmtree(run_directory, ignore_errors=True)
def create_working_directory(): """Creates working directory.""" work_dir = parse_args().workdir if not os.path.exists(work_dir): logger.debug('Creating working directory %s' % work_dir) os.makedirs(work_dir) if not os.path.exists(os.path.join(work_dir, 'data')): os.makedirs(os.path.join(work_dir, 'data')) if parse_args().clear: master_run_directory = os.path.join(work_dir, 'runs') if os.path.exists(master_run_directory): shutil.rmtree(master_run_directory, ignore_errors=True) run_file = os.path.join(work_dir, 'data', 'all_runs.json') if os.path.exists(run_file): os.remove(run_file) cache_builds_directory = os.path.join(work_dir, 'cache') if os.path.exists(cache_builds_directory): shutil.rmtree(cache_builds_directory, ignore_errors=True)
def create_run_directory(): """Creates run directory.""" PathManager.create_working_directory() master_run_directory = os.path.join(parse_args().workdir, 'runs') if not os.path.exists(master_run_directory): os.mkdir(master_run_directory) run_directory = os.path.join(master_run_directory, PathManager.get_run_id()) if not os.path.exists(run_directory): os.mkdir(run_directory)
def _load_all_patterns(application: str) -> list: """Function returns a list with all the project's Patterns.""" if parse_args().resize: _convert_hi_res_images() result_list = [] for root, dirs, files in os.walk(PathManager.get_module_dir()): for file_name in files: if file_name.endswith('.png'): if application in root and (PathManager.get_images_path() in root or 'common' in root): pattern_name, pattern_scale = _parse_name(file_name) pattern_path = os.path.join(root, file_name) pattern = { 'name': pattern_name, 'path': pattern_path, 'scale': pattern_scale } result_list.append(pattern) return result_list
def __init__(self, image_name: str, from_path: str = None, application: str = parse_args().application): if from_path is None: path = _get_image_path(inspect.stack()[1][1], image_name, application) else: path = from_path name, scale = _parse_name(os.path.split(path)[1]) image = cv2.imread(path) self.image_name = name self.image_path = path self.scale_factor = scale self.similarity = Settings.min_similarity self._target_offset = None self._size = _get_pattern_size(image, scale) self.rgb_array = _get_array_from_image(image) self.color_image = _get_image_from_array(scale, self.rgb_array) self.gray_image = _get_gray_image(self.color_image) self.gray_array = _get_array_from_image(self.gray_image)
class _Settings: """Class that holds general Iris settings. wait_scan_rate - The number of times actual pattern search operations are performed per second. (default - 3) type_delay - The number of seconds between each keyboard press. (default - 0) move_mouse_delay - duration of mouse movement from current location to target location. (default - 0.5 or value selected from Control Center) click_delay - The number of seconds a click event is executed after the mouse moves to the target location. (default - 0) min_similarity - The default minimum similarity of find operations. While using a Region.find() operation. Iris searches the region using a default minimum similarity of 0.8. auto_wait_timeout - The maximum waiting time for all subsequent find operations. (default - 3) delay_before_mouse_down - Delay before the mouse is put in a held down state. delay_before_drag - Delay before the drag operation takes place. delay_before_drop - Delay before the drop operation takes place. slow_motion_delay - Controls the duration of the visual effect (seconds). observe_scan_rate - The number of times actual search operations are performed per second while waiting for a pattern to appear or vanish. observe_min_changed_pixels - The minimum size in pixels of a change to trigger a change event. highlight_duration - The duration of the highlight effect. highlight_color - The rectangle/circle border color for the highlight effect. highlight_thickness - The rectangle/circle border thickness for the highlight effect. """ DEFAULT_MIN_SIMILARITY = 0.8 DEFAULT_SLOW_MOTION_DELAY = 2 DEFAULT_OBSERVE_MIN_CHANGED_PIXELS = 50 DEFAULT_TYPE_DELAY = 0 DEFAULT_MOVE_MOUSE_DELAY = parse_args().mouse DEFAULT_CLICK_DELAY = 0 DEFAULT_WAIT_SCAN_RATE = 3 DEFAULT_OBSERVE_SCAN_RATE = 3 DEFAULT_AUTO_WAIT_TIMEOUT = 3 DEFAULT_DELAY_BEFORE_MOUSE_DOWN = 0.3 DEFAULT_DELAY_BEFORE_DRAG = 0.3 DEFAULT_DELAY_BEFORE_DROP = 0.3 DEFAULT_HIGHLIGHT_DURATION = 2 DEFAULT_HIGHLIGHT_COLOR = Color.RED DEFAULT_HIGHLIGHT_THICKNESS = 2 def __init__(self, wait_scan_rate=DEFAULT_WAIT_SCAN_RATE, type_delay=DEFAULT_TYPE_DELAY, move_mouse_delay=DEFAULT_MOVE_MOUSE_DELAY, click_delay=DEFAULT_CLICK_DELAY, min_similarity=DEFAULT_MIN_SIMILARITY, auto_wait_timeout=DEFAULT_AUTO_WAIT_TIMEOUT, delay_before_mouse_down=DEFAULT_DELAY_BEFORE_MOUSE_DOWN, delay_before_drag=DEFAULT_DELAY_BEFORE_DRAG, delay_before_drop=DEFAULT_DELAY_BEFORE_DROP, slow_motion_delay=DEFAULT_SLOW_MOTION_DELAY, observe_scan_rate=DEFAULT_OBSERVE_SCAN_RATE, observe_min_changed_pixels=DEFAULT_OBSERVE_MIN_CHANGED_PIXELS, highlight_duration=DEFAULT_HIGHLIGHT_DURATION, highlight_color=DEFAULT_HIGHLIGHT_COLOR, highlight_thickness=DEFAULT_HIGHLIGHT_THICKNESS): self.wait_scan_rate = wait_scan_rate self._type_delay = type_delay self.move_mouse_delay = move_mouse_delay self._click_delay = click_delay self._min_similarity = min_similarity self.auto_wait_timeout = auto_wait_timeout self.delay_before_mouse_down = delay_before_mouse_down self.delay_before_drag = delay_before_drag self.delay_before_drop = delay_before_drop self.slow_motion_delay = slow_motion_delay self.observe_scan_rate = observe_scan_rate self.observe_min_changed_pixels = observe_min_changed_pixels self.highlight_duration = highlight_duration self.highlight_color = highlight_color self.highlight_thickness = highlight_thickness @property def type_delay(self): return self._type_delay @type_delay.setter def type_delay(self, value): if value > 1: self._type_delay = 1 else: self._type_delay = value @property def click_delay(self): return self._click_delay @click_delay.setter def click_delay(self, value): if value > 1: self._click_delay = 1 else: self._click_delay = value @property def min_similarity(self): return self._min_similarity @min_similarity.setter def min_similarity(self, value): if value > 1: self._min_similarity = 1 else: self._min_similarity = value
def _get_image_path(caller, image: str, application: str) -> str: """Enforce proper location for all Pattern creation. :param caller: Path of calling Python module. :param image: String filename of image. :return: Full path to image on disk. We will look at all possible paths relative to the calling file, with this priority: - current platform locale folder - common locale folder - current platform root - common root Each directory is scanned for four possible file names, depending on resolution. If the above fails, we will look up the file name in the list of project-wide images, and return whatever we find, with a warning message. If we find nothing, we will raise an exception. """ module = os.path.split(caller)[1] module_directory = os.path.split(caller)[0] parent_directory = os.path.basename(module_directory) file_name = image.split('.')[0] names = [ image, '*****@*****.**' % file_name, '*****@*****.**' % file_name, '*****@*****.**' % file_name ] if OSHelper.get_os_version() == 'win7': os_version = 'win7' else: os_version = OSHelper.get_os().value paths = [] current_locale = parse_args().locale platform_directory = os.path.join(module_directory, 'images', os_version) platform_locale_directory = os.path.join(platform_directory, current_locale) for name in names: paths.append(os.path.join(platform_locale_directory, name)) common_directory = os.path.join(module_directory, 'images', 'common') common_locale_directory = os.path.join(common_directory, current_locale) for name in names: paths.append(os.path.join(common_locale_directory, name)) for name in names: paths.append(os.path.join(platform_directory, name)) for name in names: paths.append(os.path.join(common_directory, name)) found = False image_path = None for path in paths: if os.path.exists(path): found = True image_path = path break if found: logger.debug('Module %s requests image %s' % (module, image)) logger.debug('Found %s' % image_path) return image_path else: result_list = [ x for x in _load_all_patterns(application) if x['name'] == image ] if len(result_list) > 0: res = result_list[0] logger.warning( 'Failed to find image %s in default locations for module %s.' % (image, module)) logger.warning('Using this one instead: %s' % res['path']) logger.warning( 'Please move image to correct location relative to caller.') location_1 = os.path.join(parent_directory, 'images', 'common') location_2 = os.path.join(parent_directory, PathManager.get_images_path()) logger.warning('Suggested locations: %s, %s' % (location_1, location_2)) return res['path'] else: logger.error('Pattern creation for %s failed for caller %s.' % (image, caller)) logger.error( 'Image not found. Either it is in the wrong platform folder, or it does not exist.' ) logger.debug('Paths searched:') logger.debug('\n'.join(paths)) raise FindError('Pattern not found.')
def get_current_run_dir(): """Returns the directory inside the working directory of the active run.""" PathManager.create_run_directory() return os.path.join(parse_args().workdir, 'runs', PathManager.get_run_id())
def get_working_dir(): """Returns the path to the root of the directory where local data is stored.""" PathManager.create_working_directory() return parse_args().workdir