Exemplo n.º 1
0
  def start(self, version=None, **kwargs):
    """Launch the game."""
    if not os.path.isdir(self.data_dir):
      raise sc_process.SC2LaunchError(
          "Expected to find StarCraft II installed at '%s'. If it's not "
          "installed, do that and run it once so auto-detection works. If "
          "auto-detection failed repeatedly, then set the SC2PATH environment "
          "variable with the correct location." % self.data_dir)

    version = version or FLAGS.sc2_version
    if isinstance(version, lib.Version) and not version.data_version:
      # This is for old replays that don't have the embedded data_version.
      version = _get_version(version.game_version)
    elif isinstance(version, str):
      version = _get_version(version)
    elif not version:
      versions_dir = os.path.join(self.data_dir, "Versions")
      build_version = max(int(v[4:]) for v in os.listdir(versions_dir)
                          if v.startswith("Base"))
      version = lib.Version(None, build_version, None, None)
    if version.build_version < VERSIONS["3.16.1"].build_version:
      raise sc_process.SC2LaunchError(
          "SC2 Binaries older than 3.16.1 don't support the api.")
    exec_path = os.path.join(
        self.data_dir, "Versions/Base%s" % version.build_version,
        self._exec_name)

    if not os.path.exists(exec_path):
      raise sc_process.SC2LaunchError("No SC2 binary found at: %s" % exec_path)

    return sc_process.StarcraftProcess(
        self, exec_path=exec_path, data_version=version.data_version, **kwargs)
Exemplo n.º 2
0
    def start(self, version=None, want_rgb=True, **kwargs):
        """Launch the game."""
        del want_rgb  # Unused
        if not os.path.isdir(self.data_dir):
            raise sc_process.SC2LaunchError(
                "Expected to find StarCraft II installed at '%s'. If it's not "
                "installed, do that and run it once so auto-detection works. If "
                "auto-detection failed repeatedly, then set the SC2PATH environment "
                "variable with the correct location." % self.data_dir)

        version = version or FLAGS.sc2_version
        if isinstance(version, lib.Version) and not version.data_version:
            # This is for old replays that don't have the embedded data_version.
            version = self._get_version(version.game_version)
        elif isinstance(version, six.string_types):
            version = self._get_version(version)
        elif not version:
            version = self._get_version("latest")
        if version.build_version < lib.VERSIONS["3.16.1"].build_version:
            raise sc_process.SC2LaunchError(
                "SC2 Binaries older than 3.16.1 don't support the api.")
        if FLAGS.sc2_dev_build:
            version = version._replace(build_version=0)
        exec_path = os.path.join(self.data_dir,
                                 "Versions/Base%05d" % version.build_version,
                                 self._exec_name)

        if not os.path.exists(exec_path):
            raise sc_process.SC2LaunchError("No SC2 binary found at: %s" %
                                            exec_path)

        return sc_process.StarcraftProcess(self,
                                           exec_path=exec_path,
                                           version=version,
                                           **kwargs)
Exemplo n.º 3
0
def get():
  """Get the config chosen by the flags."""
  configs = {c.name(): c
             for c in lib.RunConfig.all_subclasses() if c.priority()}

  if not configs:
    raise sc_process.SC2LaunchError("No valid run_configs found.")

  if FLAGS.sc2_run_config is None:  # Find the highest priority as default.
    return max(configs.values(), key=lambda c: c.priority())()

  try:
    return configs[FLAGS.sc2_run_config]()
  except KeyError:
    raise sc_process.SC2LaunchError(
        "Invalid run_config. Valid configs are: %s" % (
            ", ".join(sorted(configs.keys()))))
Exemplo n.º 4
0
  def start(self, want_rgb=True, **kwargs):
    """Launch the game."""
    del want_rgb  # Unused
    if not os.path.isdir(self.data_dir):
      raise sc_process.SC2LaunchError(
          "Expected to find StarCraft II installed at '%s'. If it's not "
          "installed, do that and run it once so auto-detection works. If "
          "auto-detection failed repeatedly, then set the SC2PATH environment "
          "variable with the correct location." % self.data_dir)
    exec_path = os.path.join(
        self.data_dir, "Versions/Base%05d" % self.version.build_version,
        self._exec_name)

    if not os.path.exists(exec_path):
      raise sc_process.SC2LaunchError("No SC2 binary found at: %s" % exec_path)

    return sc_process.StarcraftProcess(
        self, exec_path=exec_path, version=self.version, **kwargs)
Exemplo n.º 5
0
 def exec_path(self, baseVersion=None):
   """Get the exec_path for this platform. Possibly find the latest build."""
   if not os.path.isdir(self.data_dir):
       raise sc_process.SC2LaunchError("Install Starcraft II at %s or set the SC2PATH environment variable"%(self.data_dir))
   if baseVersion==None: # then select most recent version's baseVersion
       mostRecent = versions.handle.mostRecent
       if mostRecent:  return mostRecent["base-version"]
       raise sc_process.SC2LaunchError(
           "When requesting a versioned executable path without specifying base-version, expected "
           "to find StarCraft II versions installed at %s."%(self.versionsDir))
   elif isinstance(baseVersion, versions.Version):
       baseVersion = baseVersion.baseVersion
   elif str(baseVersion).count(".") > 0:
       baseVersion = versions.Version(baseVersion).baseVersion
   #else: # otherwise expect that the baseVersion specified is correct
   baseVersExec = os.path.join(self.versionsDir, "Base%s"%baseVersion, self._exec_name)
   if os.path.isfile(baseVersExec):
       return baseVersExec # if baseVersion in Versions subdir is valid, it is the correct executable
   raise sc_process.SC2LaunchError("Specified baseVersion %s does not exist at %s.%s    available: %s"%(\
       baseVersion, baseVersExec, os.linesep, " ".join(
           str(val) for val in sorted(self.versionMap().keys())) ))
Exemplo n.º 6
0
 def __init__(self, base_dir, exec_name, version, cwd=None, env=None):
   base_dir = os.path.expanduser(base_dir)
   version = version or FLAGS.sc2_version or "latest"
   cwd = cwd and os.path.join(base_dir, cwd)
   # super(LocalBase, self).__init__(
   #     replay_dir=os.path.join(base_dir, "Replays"),
   #     data_dir=base_dir, tmp_dir=None, version=version, cwd=cwd, env=env)
   super().__init__(
       replay_dir=os.path.join(base_dir, "Replays"),
       data_dir=base_dir, tmp_dir=None, version=version, cwd=cwd, env=env)
   if FLAGS.sc2_dev_build:
     self.version = self.version._replace(build_version=0)
   elif self.version.build_version < lib.VERSIONS["3.16.1"].build_version:
     raise sc_process.SC2LaunchError(
         "SC2 Binaries older than 3.16.1 don't support the api.")
   self._exec_name = exec_name
Exemplo n.º 7
0
 def get_versions(self):
   versions_dir = os.path.join(self.data_dir, "Versions")
   version_prefix = "Base"
   versions_found = sorted(int(v[len(version_prefix):])
                           for v in os.listdir(versions_dir)
                           if v.startswith(version_prefix))
   if not versions_found:
     raise sc_process.SC2LaunchError(
         "No SC2 Versions found in %s" % versions_dir)
   known_versions = [v for v in lib.VERSIONS.values()
                     if v.build_version in versions_found]
   # Add one more with the max version. That one doesn't need a data version
   # since SC2 will find it in the .build.info file. This allows running
   # versions newer than what are known by pysc2, and so is the default.
   known_versions.append(
       lib.Version("latest", max(versions_found), None, None))
   return lib.version_dict(known_versions)