Exemple #1
0
def process_command_line_options(options):
    if 'help' in options:
        print('Skyward Sword Randomizer Version '+VERSION)
        print('Available command line options:\n')
        longest_option = max(len(option_name) for option_name in OPTIONS.keys())
        for option_name, option in OPTIONS.items():
            print(' --'+option_name.ljust(longest_option) + ' ' + option['help'])
        # permalink
        print()
        print(' --' + 'permalink'.ljust(longest_option) + ' ' + 'Specify a permlink, which includes the settings. This is set first, other options may override these settings')
        # bulk options
        print()
        print(' --' + 'bulk'.ljust(longest_option) + ' ' + 'Runs the randomizer in bulk mode, to generate lots of spoiler logs. Implies --dry-run')
        print(' --' + 'low'.ljust(longest_option) + ' ' + '(bulk mode only) specify the lower end of seeds to generate (inclusive, default: 1)')
        print(' --' + 'high'.ljust(longest_option) + ' ' + '(bulk mode only) specify the higher end of seeds to generate (inclusive, default: 100)')
        print(' --' + 'threads'.ljust(longest_option) + ' ' + '(bulk mode only) specify the number of threads to use (default: 1)')
        return None
    elif 'version' in options:
        print(VERSION)
        return None
    else:
        cleaned_options = Options()
        if 'permalink' in options:
            cleaned_options.update_from_permalink(options.pop('permalink'))
        problems = cleaned_options.update_from_cmd_args(options)
        if problems:
            print('ERROR: invalid options:')
            for problem in problems:
                print(problem)
        return cleaned_options
Exemple #2
0
def _RunOnce(device, database_filename, url, prefetch_delay_ms,
             output_filename, wpr_archive, network_condition):
    _Setup(device, database_filename)

    disable_prefetch = prefetch_delay_ms == -1
    # Startup tracing to ease debugging.
    chrome_args = (customtabs_benchmark.CHROME_ARGS +
                   ['--trace-startup', '--trace-startup-duration=20'])

    chrome_controller = controller.RemoteChromeController(device)
    device.ForceStop(OPTIONS.ChromePackage().package)
    chrome_controller.AddChromeArguments(chrome_args)

    with device_setup.RemoteWprHost(
            device,
            wpr_archive,
            record=False,
            network_condition_name=network_condition) as wpr:
        logging.info('WPR arguments: ' + ' '.join(wpr.chrome_args))
        chrome_args += wpr.chrome_args
        prefetch_mode = 'disabled' if disable_prefetch else 'speculative_prefetch'
        result = customtabs_benchmark.RunOnce(
            device,
            url,
            warmup=True,
            speculation_mode=prefetch_mode,
            delay_to_may_launch_url=2000,
            delay_to_launch_url=prefetch_delay_ms,
            cold=False,
            chrome_args=chrome_args,
            reset_chrome_state=False)
    data_point = customtabs_benchmark.ParseResult(result)

    with open(output_filename, 'a') as f:
        f.write(','.join(str(x) for x in data_point) + '\n')
Exemple #3
0
    def KillChromeProcesses():
        """Kills all the running instances of Chrome.

    Returns: (int) The number of processes that were killed.
    """
        killed_count = 0
        chrome_path = OPTIONS.LocalBinary('chrome')
        for process in psutil.process_iter():
            try:
                process_bin_path = None
                # In old versions of psutil, process.exe is a member, in newer ones it's
                # a method.
                if type(process.exe) == str:
                    process_bin_path = process.exe
                else:
                    process_bin_path = process.exe()
                if os.path.abspath(process_bin_path) == os.path.abspath(
                        chrome_path):
                    process.terminate()
                    killed_count += 1
                    try:
                        process.wait(timeout=10)
                    except psutil.TimeoutExpired:
                        process.kill()
            except psutil.AccessDenied:
                pass
            except psutil.NoSuchProcess:
                pass
        return killed_count
Exemple #4
0
def main():
    logging.basicConfig(level=logging.INFO)
    devil_chromium.Initialize()

    parser = _CreateArgumentParser()
    args = parser.parse_args()
    OPTIONS.SetParsedArgs(args)

    if os.path.exists(args.output_filename):
        logging.error('Output file %s already exists.' % args.output_filename)
        sys.exit(1)

    device = prefetch_predictor_common.FindDevice(args.device)
    if device is None:
        logging.error('Could not find device: %s.', args.device)
        sys.exit(1)

    delays = [int(x) for x in args.prefetch_delays_ms.split(',')]

    with open(args.output_filename, 'w') as f:
        f.write(','.join(customtabs_benchmark.RESULT_FIELDS) + '\n')

    while True:
        delay = delays[random.randint(0, len(delays) - 1)]
        _RunOnce(device, args.database, args.url, delay, args.output_filename,
                 args.wpr_archive, args.network_condition)
        if args.once:
            return
Exemple #5
0
def _Setup(device, database_filename):
    """Sets up a device and returns an instance of RemoteChromeController."""
    chrome_controller = prefetch_predictor_common.Setup(device, [''])
    chrome_package = OPTIONS.ChromePackage()
    device.ForceStop(chrome_package.package)
    chrome_controller.ResetBrowserState()
    device_database_filename = prefetch_predictor_common.DatabaseDevicePath()
    owner = group = None

    # Make sure that the speculative prefetch predictor is enabled to ensure
    # that the disk database is re-created.
    command_line_path = '/data/local/tmp/chrome-command-line'
    with device_setup.FlagReplacer(device, command_line_path,
                                   ['--disable-fre', _EXTERNAL_PREFETCH_FLAG]):
        # Launch Chrome for the first time to recreate the local state.
        launch_intent = intent.Intent(action='android.intent.action.MAIN',
                                      package=chrome_package.package,
                                      activity=chrome_package.activity)
        device.StartActivity(launch_intent, blocking=True)
        time.sleep(5)
        device.ForceStop(chrome_package.package)
        assert device.FileExists(device_database_filename)
        stats = device.StatPath(device_database_filename)
        owner = stats['st_owner']
        group = stats['st_group']
    # Now push the database. Needs to be done after the first launch, otherwise
    # the profile directory is owned by root. Also change the owner of the
    # database, since adb push sets it to root.
    database_content = open(database_filename, 'r').read()
    device.WriteFile(device_database_filename,
                     database_content,
                     force_push=True)
    command = 'chown %s:%s \'%s\'' % (owner, group, device_database_filename)
    device.RunShellCommand(command, as_root=True)
Exemple #6
0
    def update_ui_for_settings(self):
        self.ui.output_folder.setText(str(self.options['output-folder']))
        self.ui.seed.setText(str(self.options["seed"]))
        current_settings = self.options.copy()
        for option_key, option in OPTIONS.items():
            if option["name"] != "Banned Types" and option["name"] != "Seed":
                ui_name = option.get('ui', None)
                if not ui_name:
                    continue
                widget = getattr(self.ui, ui_name)
                if isinstance(widget, QAbstractButton):
                    widget.setChecked(current_settings[option_key])
                elif isinstance(widget, QComboBox):
                    widget.setCurrentIndex(option['choices'].index(
                        current_settings[option_key]))
                elif isinstance(widget, QListView):
                    pass
                elif isinstance(widget, QSpinBox):
                    widget.setValue(current_settings[option_key])
                    getattr(self.ui,
                            f"label_for_{ui_name}").installEventFilter(self)

        for check_type in ALL_TYPES:
            widget = getattr(self.ui,
                             "progression_" + check_type.replace(" ", "_"))
            widget.setChecked(
                not check_type in current_settings['banned-types'])
        self.ui.permalink.setText(current_settings.get_permalink())
Exemple #7
0
def _Setup(device):
    """Sets up a device and returns an instance of RemoteChromeController."""
    chrome_controller = controller.RemoteChromeController(device)
    device.ForceStop(OPTIONS.ChromePackage().package)
    chrome_controller.AddChromeArguments(
        ['--speculative-resource-prefetching=learning'])
    chrome_controller.ResetBrowserState()
    return chrome_controller
Exemple #8
0
 def __init__(self, screen):
     self.level = 1
     self.pos = OPTIONS.get('start_positions')
     self.screen = screen
     self.player_height = 12
     self.color = COLORS.get('green')
     self.speed = 1
     self.snake_size_block = [self.pos]
     self.rect = pygame.Rect(self.pos, (10, 10))
 def ResetBrowserState(self):
     """Override for chrome state reseting."""
     logging.info('Reset chrome\'s profile')
     package_info = OPTIONS.ChromePackage()
     # We assume all the browser is in the Default user profile directory.
     cmd = [
         'rm', '-rf',
         '/data/data/{}/app_chrome/Default'.format(package_info.package)
     ]
     self._device.adb.Shell(subprocess.list2cmdline(cmd))
Exemple #10
0
 def ResetBrowserState(self):
   """Override resetting Chrome local state."""
   logging.info('Resetting Chrome local state')
   package = OPTIONS.ChromePackage().package
   # Remove the Chrome Profile and the various disk caches. Other parts
   # theoretically should not affect loading performance. Also remove the tab
   # state to prevent it from growing infinitely. [:D]
   for directory in ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache',
                     'app_tabs']:
     cmd = ['rm', '-rf', '/data/data/{}/{}'.format(package, directory)]
     self._device.adb.Shell(subprocess.list2cmdline(cmd))
 def Open(self):
     """Overridden connection creation."""
     if self._wpr_attributes:
         assert self._wpr_attributes.chrome_env_override == {}, \
             'Remote controller doesn\'t support chrome environment variables.'
     package_info = OPTIONS.ChromePackage()
     command_line_path = '/data/local/chrome-command-line'
     self._device.ForceStop(package_info.package)
     chrome_args = self._GetChromeArguments()
     logging.info(
         'Launching %s with flags: %s' %
         (package_info.package, subprocess.list2cmdline(chrome_args)))
     with device_setup.FlagReplacer(self._device, command_line_path,
                                    self._GetChromeArguments()):
         start_intent = intent.Intent(package=package_info.package,
                                      activity=package_info.activity,
                                      data='about:blank')
         self._device.adb.Logcat(clear=True, dump=True)
         self._device.StartActivity(start_intent, blocking=True)
         try:
             for attempt_id in xrange(self.DEVTOOLS_CONNECTION_ATTEMPTS):
                 logging.info('Devtools connection attempt %d' % attempt_id)
                 with device_setup.ForwardPort(
                         self._device, 'tcp:%d' % OPTIONS.devtools_port,
                         'localabstract:chrome_devtools_remote'):
                     try:
                         connection = devtools_monitor.DevToolsConnection(
                             OPTIONS.devtools_hostname,
                             OPTIONS.devtools_port)
                         self._StartConnection(connection)
                     except socket.error as e:
                         if e.errno != errno.ECONNRESET:
                             raise
                         time.sleep(
                             self.
                             DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS)
                         continue
                     yield connection
                     if self._slow_death:
                         self._device.adb.Shell(
                             'am start com.google.android.launcher')
                         time.sleep(self.TIME_TO_IDLE_SECONDS)
                     break
             else:
                 raise ChromeControllerInternalError(
                     'Failed to connect to Chrome devtools after {} '
                     'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS))
         except:
             logcat = ''.join(
                 [l + '\n' for l in self._device.adb.Logcat(dump=True)])
             raise ChromeControllerError(log=logcat)
         finally:
             self._device.ForceStop(package_info.package)
Exemple #12
0
def _Go(chrome_controller, urls_filename, output_filename, repeats):
    urls = []
    with open(urls_filename) as f:
        urls = [line.strip() for line in f.readlines()]

    with chrome_controller.Open() as connection:
        for repeat in range(repeats):
            logging.info('Repeat #%d', repeat)
            for url in urls:
                logging.info('\tLoading %s', url)
                page_track.PageTrack(connection)  # Registers the listeners.
                connection.MonitorUrl(url,
                                      timeout_seconds=_PAGE_LOAD_TIMEOUT,
                                      stop_delay_multiplier=1.5)

    device = chrome_controller.GetDevice()
    device.ForceStop(OPTIONS.ChromePackage().package)
    database_filename = (
        '/data/user/0/%s/app_chrome/Default/Network Action Predictor' %
        OPTIONS.ChromePackage().package)
    device.PullFile(database_filename, output_filename)
Exemple #13
0
def process_command_line_options(options):
    if 'help' in options:
        print('Skyward Sword Randomizer Version ' + VERSION)
        print('Available command line options:\n')
        longest_option = max(
            len(option_name) for option_name in OPTIONS.keys())
        for option_name, option in OPTIONS.items():
            print(' --' + option_name.ljust(longest_option) + ' ' +
                  option['help'])
        return None
    elif 'version' in options:
        print(VERSION)
        return None
    else:
        cleaned_options = Options()
        problems = cleaned_options.update_from_cmd_args(options)
        if problems:
            print('ERROR: invalid options:')
            for problem in problems:
                print(problem)
        return cleaned_options
Exemple #14
0
def main():
    logging.basicConfig(level=logging.INFO)
    parser = _CreateArgumentParser()
    args = parser.parse_args()
    OPTIONS.SetParsedArgs(args)
    devil_chromium.Initialize()
    device = _FindDevice(args.device)
    if device is None:
        logging.error('Could not find device: %s.', args.device)
        sys.exit(1)
    chrome_controller = _Setup(device)
    _Go(chrome_controller, args.urls_filename, args.output_filename,
        int(args.url_repeat))
def main():
    logging.basicConfig(level=logging.INFO)
    devil_chromium.Initialize()

    parser = _CreateArgumentParser()
    args = parser.parse_args()
    OPTIONS.SetParsedArgs(args)
    device = prefetch_predictor_common.FindDevice(args.device)
    if device is None:
        logging.error('Could not find device: %s.', args.device)
        sys.exit(1)

    _Setup(device, args.database)
    _Go(device, args.url, int(args.prefetch_delay_ms))
def _CreateArgumentParser():
    """Creates and returns the argument parser."""
    parser = argparse.ArgumentParser(
        ('Loads a URL with the resource_prefetch_predictor and prints loading '
         'metrics.'),
        parents=[OPTIONS.GetParentParser()])
    parser.add_argument('--device', help='Device ID')
    parser.add_argument('--database',
                        help=('File containing the predictor database, as '
                              'obtained from generate_database.py.'))
    parser.add_argument('--url', help='URL to load.')
    parser.add_argument('--prefetch_delay_ms',
                        help='Prefetch delay in ms. -1 to disable prefetch.')
    return parser
def _CreateArgumentParser():
  """Creates and returns the argument parser."""
  parser = argparse.ArgumentParser(
      ('Loads a set of web pages several times on a device, and extracts the '
       'predictor database.'), parents=[OPTIONS.GetParentParser()])
  parser.add_argument('--device', help='Device ID')
  parser.add_argument('--urls_filename', help='File containing a list of URLs '
                      '(one per line). URLs can be repeated.')
  parser.add_argument('--output_filename',
                      help='File to store the database in.')
  parser.add_argument('--url_repeat',
                      help=('Number of times each URL in the input '
                            'file is loaded.'),
                      default=3)
  return parser
def Setup(device, additional_flags=None):
  """Sets up a |device| and returns an instance of RemoteChromeController.

  Args:
    device: (Device) As returned by FindDevice().
    additional_flags: ([str] or None) Chrome flags to add.
  """
  if not device.HasRoot():
    device.EnableRoot()
  chrome_controller = controller.RemoteChromeController(device)
  device.ForceStop(OPTIONS.ChromePackage().package)
  if additional_flags is not None:
    chrome_controller.AddChromeArguments(additional_flags)
  chrome_controller.ResetBrowserState()
  return chrome_controller
Exemple #19
0
def main():
  devil_chromium.Initialize()
  logging.basicConfig(level=logging.INFO)

  parser = _CreateArgumentParser()
  args = parser.parse_args()
  OPTIONS.SetParsedArgs(args)

  device = prefetch_predictor_common.FindDevice(args.device)
  if device is None:
    logging.error('Could not find device: %s.', args.device)
    sys.exit(1)

  chrome_controller = prefetch_predictor_common.Setup(device, _LEARNING_FLAGS)
  _GenerateDatabase(chrome_controller, args.urls_filename,
                    args.output_filename, int(args.url_repeat))
  _GenerateWprArchive(device, args.test_url, args.wpr_archive)
def main():
  devil_chromium.Initialize()
  logging.basicConfig(level=logging.INFO)

  parser = _CreateArgumentParser()
  args = parser.parse_args()
  OPTIONS.SetParsedArgs(args)

  device = prefetch_predictor_common.FindDevice(args.device)
  if device is None:
    logging.error('Could not find device: %s.', args.device)
    sys.exit(1)

  chrome_controller = prefetch_predictor_common.Setup(
      device, ['--speculative-resource-prefetching=learning'])
  _Go(chrome_controller, args.urls_filename, args.output_filename,
      int(args.url_repeat))
def _Go(chrome_controller, urls_filename, output_filename, repeats):
  urls = []
  with open(urls_filename) as f:
    urls = [line.strip() for line in f.readlines()]

  with chrome_controller.Open() as connection:
    for repeat in range(repeats):
      logging.info('Repeat #%d', repeat)
      for url in urls:
        logging.info('\tLoading %s', url)
        page_track.PageTrack(connection)  # Registers the listeners.
        connection.MonitorUrl(url, timeout_seconds=_PAGE_LOAD_TIMEOUT,
                              stop_delay_multiplier=1.5)
        time.sleep(2)  # Reduces flakiness.

  device = chrome_controller.GetDevice()
  device.ForceStop(OPTIONS.ChromePackage().package)
  device.PullFile(prefetch_predictor_common.DatabaseDevicePath(),
                  output_filename)
Exemple #22
0
    def update_settings(self):
        self.output_folder = self.ui.output_folder.text()
        try:
            self.options.set_option("seed", int(self.ui.seed.text()))
        except ValueError:
            if self.ui.seed.text() == "":
                self.options.set_option("seed", -1)
            else:
                # TODO: give an error dialog or some sort of error message that the seed is invalid
                pass

        for option_command, option in OPTIONS.items():
            if option["name"] != "Banned Types" and option["name"] != "Seed":
                ui_name = option.get('ui', None)
                if not ui_name:
                    continue
                self.options.set_option(option_command, self.get_option_value(ui_name))

        self.options.set_option("banned-types", self.get_banned_types())
        self.ui.permalink.setText(self.options.get_permalink())
def _CreateArgumentParser():
  """Creates and returns the argument parser."""
  parser = argparse.ArgumentParser(
      ('Loads a URL with the resource_prefetch_predictor and prints loading '
       'metrics.'), parents=[OPTIONS.GetParentParser()])
  parser.add_argument('--device', help='Device ID')
  parser.add_argument('--database',
                      help=('File containing the predictor database, as '
                            'obtained from generate_database.py.'))
  parser.add_argument('--url', help='URL to load.')
  parser.add_argument('--prefetch_delays_ms',
                      help='List of prefetch delays in ms. -1 to disable '
                      'prefetch. Runs will randomly select one delay in the '
                      'list.')
  parser.add_argument('--output_filename',
                      help='CSV file to append the result to.')
  parser.add_argument('--network_condition',
                      help='Network condition for emulation.')
  parser.add_argument('--wpr_archive', help='WPR archive path.')
  parser.add_argument('--once', help='Only run once.', action='store_true')
  return parser
Exemple #24
0
    def __init__(self, options: Options):
        super().__init__()

        self.wit_manager = WitManager(Path('.').resolve())
        self.randothread = None
        self.error_msg = None
        self.progress_dialog = None
        self.randomize_after_iso_extract = False

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.setWindowTitle("Skyward Sword Randomizer v" + VERSION)

        self.options = options

        self.option_map = {}
        for option_key, option in OPTIONS.items():
            if option["name"] != "Banned Types" and option["name"] != "Seed":
                ui_name = option.get('ui', None)
                self.option_map[ui_name] = option
                if not ui_name:
                    continue
                widget = getattr(self.ui, ui_name)
                widget.installEventFilter(self)
                if isinstance(widget, QAbstractButton):
                    widget.setChecked(self.options[option_key])
                    widget.clicked.connect(self.update_settings)
                elif isinstance(widget, QComboBox):
                    for option_val in option['choices']:
                        widget.addItem(str(option_val))
                    widget.setCurrentIndex(option['choices'].index(
                        self.options[option_key]))
                    widget.currentIndexChanged.connect(self.update_settings)
                elif isinstance(widget, QListView):
                    pass
                elif isinstance(widget, QSpinBox):
                    if 'min' in option:
                        widget.setMinimum(option['min'])
                    if 'max' in option:
                        widget.setMaximum(option['max'])
                    widget.setValue(self.options[option_key])
                    widget.valueChanged.connect(self.update_settings)

        self.location_descriptions = {
            "skyloft":
            "Enables progression items to appear on Skyloft",
            "sky":
            "Enables progression items to appear in The Sky",
            "thunderhead":
            "Enables progression items to appear in The Thunderhead",
            "faron":
            "Enables progression items to appear in the Faron Province",
            "eldin":
            "Enables progression items to appear in the Eldin Province",
            "lanayru":
            "Enables progression items to appear in the Lanayru Province",
            "dungeon":
            "Enables progression items to appear in dungeons",
            "mini_dungeon":
            "Enables progression items to appear inside Mini Dungeons (i.e. the nodes in "
            "Lanayru Desert)",
            "free_gift":
            "Enables progression items to appear as free gifts from NPCs (i.e. the shield from "
            "Professor Owlan)",
            "freestanding":
            "Enables progression items to appear as freestanding items in the world "
            "(does not include the freestanding gratitude crystals)",
            "miscellaneous":
            "Enables progression items to appear in miscellaneous locations that don't fit into "
            "any other category (i.e. overworld chests) ",
            "silent_realm":
            "Enables progression items to appear as rewards for completing Silent Realm trials",
            "digging":
            "Enables progression items to appear in digging spots in the world (does not include Mogma "
            "Mitts checks, such as the one in Volcano Summit or in Fire Sanctuary)",
            "bombable":
            "Enables progression items to appear behind bombable walls or other bombable structures",
            "combat":
            "Enables progression items to appear as rewards for combat or completing a quest involving "
            "combat (i.e. Digging Mitts fight, Kikwi rescue). Does not impact combat within dungeons",
            "song":
            "Enables progression items to appear in place of learning songs (from Isle of Song, Ballad of the "
            "Goddess in Sealed Temple, Song of the Hero from Levias)",
            "spiral_charge":
            "Enables progression items to appear in the chests in the sky requiring Spiral Charge to"
            " access",
            "minigame":
            "Enables progression items to appear as rewards from winning minigames",
            "crystal":
            "Enables progression items to appear as loose crystals (currently not randomized and must "
            "always be enabled)",
            "short":
            "Enables progression items to appear as rewards for completing short quests (i.e. rescuing"
            " Orielle)",
            "long":
            "Enables progression items to appear as rewards for completing long quests (i.e. Peatrice)",
            "fetch":
            "Enables progression items to appear as rewards for returning items to NPCs ",
            "crystal_quest":
            "Enables progression items to appear as rewards for completing Gratitude Crystal quests",
            "scrapper":
            "Enables progression items to appear as rewards for Scrapper Quests",
            "peatrice":
            "Enables a progression item to appear as the reward for completing the Peatrice side quest",
            "goddess":
            "Enables progression items to appear as items in Goddess Chests",
            "faron_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes in "
            "Faron Woods and Deep Woods",
            "eldin_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes in "
            "the main part of Eldin Volcano and Mogma Turf",
            "lanayru_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes "
            "in the main part of Lanayru Desert, Temple of Time and Lanayru Mines",
            "floria_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes "
            "in Lake Floria",
            "summit_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes "
            "in Volcano Summit",
            "sand_sea_goddess":
            "Enables progression items to appear in the Goddess Chests linked to the Goddess Cubes "
            "in Sand Sea",
        }
        for check_type in ALL_TYPES:
            widget = getattr(self.ui,
                             "progression_" + check_type.replace(" ", "_"))
            widget.setChecked(not check_type in self.options['banned-types'])
            if check_type == 'crystal':
                widget.setEnabled(False)
            widget.clicked.connect(self.update_settings)
            widget.installEventFilter(self)

        self.ui.ouput_folder_browse_button.clicked.connect(
            self.browse_for_output_dir)
        self.ui.randomize_button.clicked.connect(self.randomize)
        self.ui.permalink.textChanged.connect(self.permalink_updated)
        self.ui.seed.textChanged.connect(self.update_settings)
        self.ui.progression_goddess.clicked.connect(self.goddess_cubes_toggled)
        self.update_ui_for_settings()
        self.set_option_description(None)

        if 'NOGIT' in VERSION:
            self.error_msg = QErrorMessage()
            self.error_msg.showMessage(
                'Running from source without git is not supported!')

        elif not self.wit_manager.actual_extract_already_exists():
            self.ask_for_clean_iso()
 def setUp(self):
   OPTIONS.ParseArgs([])
   self._server_address = None
   self._wpr_http_port = None
   self._tmp_directory = tempfile.mkdtemp(prefix='tmp_test_')
Exemple #26
0
 def ResetBrowserState(self):
     """Override resetting Chrome local state."""
     logging.info('Resetting Chrome local state')
     chrome_setup.ResetChromeLocalState(self._device,
                                        OPTIONS.ChromePackage().package)
Exemple #27
0
 def walk_left(self):
     self.pos = self.pos - OPTIONS.get('walk') * self.speed
     self.snake_size_block.append(self.pos)
     self.update()
Exemple #28
0
    def Open(self):
        """Overridden connection creation."""
        # Kill all existing Chrome instances.
        killed_count = LocalChromeController.KillChromeProcesses()
        if killed_count > 0:
            logging.warning('Killed existing Chrome instance.')

        chrome_cmd = [OPTIONS.LocalBinary('chrome')]
        chrome_cmd.extend(self._GetChromeArguments())
        # Force use of simple cache.
        chrome_cmd.append('--use-simple-cache-backend=on')
        chrome_cmd.append('--user-data-dir=%s' % self._profile_dir)
        # Navigates to about:blank for couples of reasons:
        #   - To find the correct target descriptor at devtool connection;
        #   - To avoid cache and WPR pollution by the NTP.
        chrome_cmd.append('about:blank')

        tmp_log = \
            tempfile.NamedTemporaryFile(prefix="chrome_controller_", suffix='.log')
        chrome_process = None
        try:
            chrome_env_override = self._chrome_env_override.copy()
            if self._wpr_attributes:
                chrome_env_override.update(
                    self._wpr_attributes.chrome_env_override)

            chrome_env = os.environ.copy()
            chrome_env.update(chrome_env_override)

            # Launch Chrome.
            logging.info(
                common_util.GetCommandLineForLogging(chrome_cmd,
                                                     chrome_env_override))
            chrome_process = subprocess.Popen(chrome_cmd,
                                              stdout=tmp_log.file,
                                              stderr=tmp_log.file,
                                              env=chrome_env)
            # Attempt to connect to Chrome's devtools
            for attempt_id in xrange(self.DEVTOOLS_CONNECTION_ATTEMPTS):
                logging.info('Devtools connection attempt %d' % attempt_id)
                process_result = chrome_process.poll()
                if process_result is not None:
                    raise ChromeControllerInternalError(
                        'Unexpected Chrome exit: {}'.format(process_result))
                try:
                    connection = devtools_monitor.DevToolsConnection(
                        OPTIONS.devtools_hostname, OPTIONS.devtools_port)
                    break
                except socket.error as e:
                    if e.errno != errno.ECONNREFUSED:
                        raise
                    time.sleep(
                        self.DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS)
            else:
                raise ChromeControllerInternalError(
                    'Failed to connect to Chrome devtools after {} '
                    'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS))
            # Start and yield the devtool connection.
            self._StartConnection(connection)
            yield connection
            if self._slow_death:
                connection.Close()
                chrome_process.wait()
                chrome_process = None
        except ChromeControllerError._PASSTHROUGH_WHITE_LIST:
            raise
        except Exception:
            raise ChromeControllerError(log=open(tmp_log.name).read())
        finally:
            if OPTIONS.local_noisy:
                sys.stderr.write(open(tmp_log.name).read())
            del tmp_log
            if chrome_process:
                try:
                    chrome_process.kill()
                except OSError:
                    pass  # Chrome is already dead.
Exemple #29
0
 def down(self):
     self.pos = self.pos + OPTIONS.get('up') * self.speed
     self.snake_size_block.append(self.pos)
     self.update()
Exemple #30
0
 def Open(self):
     """Overridden connection creation."""
     if self._wpr_attributes:
         assert self._wpr_attributes.chrome_env_override == {}, \
             'Remote controller doesn\'t support chrome environment variables.'
     package_info = OPTIONS.ChromePackage()
     command_line_path = '/data/local/chrome-command-line'
     self._device.ForceStop(package_info.package)
     chrome_args = self._GetChromeArguments()
     logging.info(
         'Launching %s with flags: %s' %
         (package_info.package, subprocess.list2cmdline(chrome_args)))
     with device_setup.FlagReplacer(self._device, command_line_path,
                                    self._GetChromeArguments()):
         self._DismissCrashDialogIfNeeded()
         start_intent = intent.Intent(package=package_info.package,
                                      activity=package_info.activity,
                                      data='about:blank')
         self._device.adb.Logcat(clear=True, dump=True)
         self._device.StartActivity(start_intent, blocking=True)
         try:
             for attempt_id in xrange(self.DEVTOOLS_CONNECTION_ATTEMPTS):
                 logging.info('Devtools connection attempt %d' % attempt_id)
                 # Adb forwarding does not provide a way to print the port number if
                 # it is allocated atomically by the OS by passing port=0, but we need
                 # dynamically allocated listening port here to handle parallel run on
                 # different devices.
                 host_side_port = _AllocateTcpListeningPort()
                 logging.info(
                     'Allocated host sided listening port for devtools '
                     'connection: %d', host_side_port)
                 try:
                     with device_setup.ForwardPort(
                             self._device, 'tcp:%d' % host_side_port,
                             'localabstract:chrome_devtools_remote'):
                         try:
                             connection = devtools_monitor.DevToolsConnection(
                                 OPTIONS.devtools_hostname, host_side_port)
                             self._StartConnection(connection)
                         except socket.error as e:
                             if e.errno != errno.ECONNRESET:
                                 raise
                             time.sleep(
                                 self.
                                 DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS
                             )
                             continue
                         yield connection
                         if self._slow_death:
                             self._device.adb.Shell(
                                 'am start com.google.android.launcher')
                             time.sleep(self.TIME_TO_IDLE_SECONDS)
                         break
                 except device_errors.AdbCommandFailedError as error:
                     _KNOWN_ADB_FORWARDER_FAILURES = [
                         'cannot bind to socket: Address already in use',
                         'cannot rebind existing socket: Resource temporarily unavailable'
                     ]
                     for message in _KNOWN_ADB_FORWARDER_FAILURES:
                         if message in error.message:
                             break
                     else:
                         raise
                     continue
             else:
                 raise ChromeControllerInternalError(
                     'Failed to connect to Chrome devtools after {} '
                     'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS))
         except ChromeControllerError._PASSTHROUGH_WHITE_LIST:
             raise
         except Exception:
             logcat = ''.join(
                 [l + '\n' for l in self._device.adb.Logcat(dump=True)])
             raise ChromeControllerError(log=logcat)
         finally:
             self._device.ForceStop(package_info.package)
             self._DismissCrashDialogIfNeeded()