Beispiel #1
0
    def init_tesseract_path(self):

        which_tesseract = \
            subprocess.Popen('which tesseract', stdout=subprocess.PIPE, shell=True).communicate()[0].rstrip()

        path_not_found = False
        current_os = Settings.get_os()

        if current_os == Platform.WINDOWS:
            win_default_tesseract_path = 'C:\\Program Files (x86)\\Tesseract-OCR'

            if '/c/' in str(which_tesseract):
                win_which_tesseract_path = which_tesseract.replace('/c/', 'C:\\').replace('/', '\\') + '.exe'
            else:
                win_which_tesseract_path = which_tesseract.replace('\\', '\\\\')

            if self.check_tesseract_path(win_default_tesseract_path):
                pytesseract.pytesseract.tesseract_cmd = win_default_tesseract_path + '\\tesseract'
            elif self.check_tesseract_path(win_which_tesseract_path):
                pytesseract.pytesseract.tesseract_cmd = win_which_tesseract_path
            else:
                path_not_found = True

        elif current_os == Platform.LINUX or current_os == Platform.MAC:
            if self.check_tesseract_path(which_tesseract):
                pytesseract.pytesseract.tesseract_cmd = which_tesseract
            else:
                path_not_found = True
        else:
            path_not_found = True

        if path_not_found:
            logger.critical('Unable to find Tesseract.')
            logger.critical('Please consult wiki for complete setup instructions.')
            self.finish(1)
Beispiel #2
0
 def check_keyboard_state(self):
     is_lock_on = False
     if Settings.get_os() != Platform.MAC:
         if Key.is_lock_on(Key.CAPS_LOCK):
             logger.error('Cannot run Iris because Key.CAPS_LOCK is on. Please turn it off to continue.')
             is_lock_on = True
         if Key.is_lock_on(Key.NUM_LOCK):
             logger.error('Cannot run Iris because Key.NUM_LOCK is on. Please turn it off to continue.')
             is_lock_on = True
         if Key.is_lock_on(Key.SCROLL_LOCK):
             logger.error('Cannot run Iris because Key.SCROLL_LOCK is on. Please turn it off to continue.')
             is_lock_on = True
     else:
         try:
             cmd = subprocess.Popen('xset q', shell=True, stdout=subprocess.PIPE)
         except subprocess.CalledProcessError as e:
             logger.error('Command failed: %s' % repr(e.cmd))
             raise Exception('Unable to run command')
         else:
             keys = ['Caps', 'Num', 'Scroll']
             locked = None
             for line in cmd.stdout:
                 for key in keys:
                     if key in line:
                         value = ' '.join(line.split())
                         if key in value[0:len(value) / 3]:
                             button = value[0:len(value) / 3]
                             if "off" in button:
                                 is_lock_on = False
                             else:
                                 is_lock_on = True
                                 locked = key
                                 break
                         elif key in value[len(value) / 3:len(value) / 3 + len(value) / 3]:
                             button = value[len(value) / 3:len(value) / 3 + len(value) / 3]
                             if "off" in button:
                                 is_lock_on = False
                             else:
                                 is_lock_on = True
                                 locked = key
                                 break
                         else:
                             button = value[len(value) / 3 * 2:len(value)]
                             if "off" in button:
                                 is_lock_on = False
                             else:
                                 is_lock_on = True
                                 locked = key
                                 break
                 if is_lock_on:
                     logger.error('Cannot run Iris because Key.%s_LOCK is toggled.' % locked.upper())
                     logger.error('Please turn it off to continue.')
                     break
             IrisCore.shutdown_process('Xquartz')
     if is_lock_on:
         self.finish(code=1)
Beispiel #3
0
 def initialize_platform(self):
     self.args = parse_args()
     self.module_dir = IrisCore.get_module_dir()
     self.platform = get_platform()
     self.os = Settings.get_os()
     self.create_working_directory()
     self.create_run_directory()
     initialize_logger(LOG_FILENAME, self.args.level)
     IrisCore.create_profile_cache()
     Iris.process_list = []
     self.local_web_root = os.path.join(self.module_dir, 'iris', 'local_web')
     self.base_local_web_url = 'http://127.0.0.1:%s' % self.args.port
     self.create_test_json()
     self.create_arg_json()
     self.test_list = []
     self.test_packages = []
Beispiel #4
0
    def control_center(self):
        # If user provides custom command-line arguments, we will skip the control center.
        if len(sys.argv) > 1 and not self.args.control:
            return True
        else:
            # Copy web assets to working directory.
            dir_util.copy_tree(
                os.path.join(self.module_dir, 'iris', 'cc_files'),
                self.args.workdir)
            # Copy profile for Firefox.
            profile_path = os.path.join(self.args.workdir, 'cc_profile')
            if os.path.exists(profile_path):
                shutil.rmtree(profile_path)
            Profile._get_staged_profile(Profile.LIKE_NEW, profile_path)

            # Open local installation of Firefox.
            paths = []
            is_installed = False
            fx_path = ''
            if Settings.get_os() == Platform.MAC:
                paths.append(
                    '/Applications/Firefox.app/Contents/MacOS/firefox')
                paths.append(
                    '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox'
                )
                paths.append(
                    '/Applications/Firefox Nightly.app/Contents/MacOS/firefox')
            elif Settings.get_os() == Platform.WINDOWS:
                paths.append(
                    'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
                paths.append(
                    'C:\\Program Files (x86)\\Firefox Developer Edition\\firefox.exe'
                )
                paths.append('C:\\Program Files (x86)\\Nightly\\firefox.exe')
                paths.append('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
                paths.append(
                    'C:\\Program Files\\Firefox Developer Edition\\firefox.exe'
                )
                paths.append('C:\\Program Files\\Nightly\\firefox.exe')
            else:
                paths.append('/usr/bin/firefox')
                paths.append('/usr/lib/firefox/firefox')

            for path in paths:
                if os.path.exists(path):
                    fx_path = path
                    is_installed = True
                    break
            if not is_installed:
                logger.error(
                    'Can\'t find local Firefox installation, aborting Iris run.'
                )
                self.finish(1)

            fx_runner = launch_firefox(fx_path,
                                       profile=profile_path,
                                       url=self.base_local_web_url)
            fx_runner.start()
            server = LocalWebServer(self.args.workdir, self.args.port)

            # Iris waits for the user to make a choice in the control center. Once they
            # make a decision, Firefox will quit.
            quit_firefox()

            # Check the result of the user's decision. If they have chosen to run tests,
            # we will continue. Otherwise, abort the current run.
            if server.result == 'cancel':
                # We will quit Iris gracefully and clean up.
                logger.info('Canceling Iris run.')
                return False
            else:
                # We will parse this returned value and turn it into runtime data.
                logger.debug('Received data from control center: %s' %
                             server.result)

                # Update app args with new values
                self.args.locale = server.result['locale']
                self.args.firefox = server.result['firefox']
                self.args.override = server.result['override']
                self.args.port = int(server.result['port'])
                self.args.email = server.result['email']
                self.args.highlight = server.result['highlight']
                self.args.mouse = float(server.result['mouse'])
                self.args.report = server.result['report']
                self.args.save = server.result['save']

                # For other parts of Iris that get their arguments from parse_args,
                # we have to update the values there as well.
                get_global_args().locale = self.args.locale
                get_global_args().firefox = self.args.firefox
                get_global_args().override = self.args.override
                get_global_args().port = self.args.port
                get_global_args().email = self.args.email
                get_global_args().highlight = server.result['highlight']
                get_global_args().mouse = self.args.mouse
                get_global_args().report = self.args.report
                get_global_args().save = self.args.save

                # Update this URL, used by test cases.
                self.base_local_web_url = 'http://127.0.0.1:%s' % self.args.port

                # Parse tests.
                tests = sorted(server.result['tests'])
                if len(tests):
                    for package in tests:
                        self.test_packages.append(package)
                        for test in server.result['tests'][package]:
                            self.test_list.append(test['name'])
                else:
                    logger.info('No tests selected, canceling Iris run.')
                    return False
                return True