def check_target(target: str = None): """Checks if provided target exists.""" # Currently not in use, but maintaining for possible future use. if target is None: logger.warning('No target provided.') local_target_path = os.path.join(PathManager.get_module_dir(), 'targets') package_target_path = os.path.join(PathManager.get_module_dir(), 'mattapi', 'targets') if os.path.exists(os.path.join(local_target_path, target)): return True if os.path.exists(os.path.join(package_target_path, target)): return True target_list = [] local_path_exists = os.path.exists(local_target_path) package_path_exists = os.path.exists(package_target_path) if local_path_exists: target_list += scan_dir(local_target_path) if package_path_exists: target_list += scan_dir(package_target_path) if not local_path_exists and not package_path_exists: path_warning(local_target_path) else: logger.critical('Target %s doesn\'t exist.') logger.critical('Did you mean to choose one of these instead?') for target in target_list: logger.critical('\t%s' % target) return False
def init_control_center(): cc_assets_path = os.path.join( os.path.realpath(os.path.split(__file__)[0] + '/..'), 'control_center', 'assets') logger.debug('Copying Control Center assets from %s to %s' % (cc_assets_path, get_core_args().workdir)) copy_tree(cc_assets_path, get_core_args().workdir) if os.path.exists(os.path.join(PathManager.get_module_dir(), 'targets')): logger.debug('Looking for CC files in module directory.') targets_dir = os.path.join(PathManager.get_module_dir(), 'targets') else: logger.debug('Looking for CC files in package directory.') targets_dir = os.path.join(Settings.PACKAGE_ROOT, 'mattapi', 'targets') exclude_dirs = {'__pycache__'} for path, dirs, files in PathManager.sorted_walk(targets_dir): [dirs.remove(d) for d in list(dirs) if d in exclude_dirs] for target in dirs: src = os.path.join(targets_dir, target, 'icon.png') dest = os.path.join(get_core_args().workdir, 'images', '%s.png' % target) try: shutil.copyfile(src, dest) except FileNotFoundError: logger.warning('Could not find icon file for target: %s' % target) break create_target_json()
def _get_staged_profile(profile_name, path): """ Internal-only method used to extract a given profile. :param profile_name: :param path: :return: """ staged_profiles = os.path.join(PathManager.get_module_dir(), 'targets', 'firefox', 'firefox_app', 'profiles') sz_bin = find_executable('7z') logger.debug('Using 7zip executable at "%s"' % sz_bin) zipped_profile = os.path.join(staged_profiles, '%s.zip' % profile_name.value) cmd = [ sz_bin, 'x', '-y', '-bd', '-o%s' % staged_profiles, zipped_profile ] logger.debug('Unzipping profile with command "%s"' % ' '.join(cmd)) try: output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: logger.error('7zip failed: %s' % repr(e.output)) raise Exception('Unable to unzip profile.') logger.debug('7zip succeeded: %s' % repr(output)) from_directory = os.path.join(staged_profiles, profile_name.value) to_directory = path logger.debug('Creating new profile: %s' % to_directory) dir_util.copy_tree(from_directory, to_directory) try: shutil.rmtree(from_directory) except WindowsError: logger.debug( 'Error, can\'t remove orphaned directory, leaving in place.') resource_fork_folder = os.path.join(staged_profiles, '__MACOSX') if os.path.exists(resource_fork_folder): try: shutil.rmtree(resource_fork_folder) except WindowsError: logger.debug( 'Error, can\'t remove orphaned directory, leaving in place.' ) return to_directory
def __init__(self): BaseTarget.__init__(self) global target_args target_args = self.get_target_args() self.target_name = 'Firefox' self.process_list = [] self.cc_settings = [{ 'name': 'firefox', 'type': 'list', 'label': 'Firefox', 'value': ['local', 'latest', 'latest-esr', 'latest-beta', 'nightly'], 'default': 'beta' }, { 'name': 'locale', 'type': 'list', 'label': 'Locale', 'value': OSHelper.LOCALES, 'default': 'en-US' }, { 'name': 'mouse', 'type': 'list', 'label': 'Mouse speed', 'value': ['0.0', '0.5', '1.0', '2.0'], 'default': '0.5' }, { 'name': 'highlight', 'type': 'checkbox', 'label': 'Debug using highlighting' }, { 'name': 'override', 'type': 'checkbox', 'label': 'Run disabled tests' }, { 'name': 'email', 'type': 'checkbox', 'label': 'Email results' }, { 'name': 'report', 'type': 'checkbox', 'label': 'Create TestRail report' }] self.local_web_root = os.path.join(PathManager.get_module_dir(), 'targets', 'firefox', 'local_web')
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. import logging import os.path from configparser import ConfigParser from mattapi.util.path_manager import PathManager logger = logging.getLogger(__name__) config_file = os.path.join(PathManager.get_module_dir(), 'config.ini') config = ConfigParser() def get_config_section(section): """Returns all properties of a section as a dict or None if section does not exist.""" if os.path.isfile(config_file): try: config.read(config_file) if config.has_section(section): result = dict(config.items(section)) return result except EOFError: logger.warning('Config file error.') return None logger.warning('Config file not found.') return None