示例#1
0
    def __init__(self, base_dir, exec_path, cwd=None, env=None):
        base_dir = os.path.expanduser(base_dir)
        exec_path = os.path.join(base_dir, exec_path)
        cwd = cwd and os.path.join(base_dir, cwd)

        if "Versions/Base*/" in exec_path:
            versions_dir = os.path.join(base_dir, "Versions")
            if not os.path.isdir(versions_dir):
                raise lib.SC2LaunchError(
                    "Expected to find StarCraft II installed at '%s'. Either install "
                    "it there or set the SC2PATH environment variable." %
                    base_dir)
            latest = max(
                int(v[4:]) for v in os.listdir(versions_dir)
                if v.startswith("Base"))
            if latest < 55958:
                raise lib.SC2LaunchError(
                    "Your SC2 binary is too old. Upgrade to 3.16.1 or newer.")
            exec_path = exec_path.replace("*", str(latest))

        super(LocalBase,
              self).__init__(replay_dir=os.path.join(base_dir, "Replays"),
                             data_dir=base_dir,
                             tmp_dir=None,
                             exec_path=exec_path,
                             cwd=cwd,
                             env=env)
示例#2
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 lib.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 lib.SC2LaunchError("Invalid run_config. Valid configs are: %s" % (
        ", ".join(sorted(configs.keys()))))
示例#3
0
  def exec_path(self, game_version=None):
    """Get the exec_path for this platform. Possibly find the latest build."""
    build_version = get_version(game_version)[0] if game_version else None

    if not build_version:
      versions_dir = os.path.join(self.data_dir, "Versions")
      if not os.path.isdir(versions_dir):
        raise lib.SC2LaunchError(
            "Expected to find StarCraft II installed at '%s'. Either install "
            "it there or set the SC2PATH environment variable." % self.data_dir)
      build_version = max(int(v[4:]) for v in os.listdir(versions_dir)
                          if v.startswith("Base"))
      if build_version < 55958:
        raise lib.SC2LaunchError(
            "Your SC2 binary is too old. Upgrade to 3.16.1 or newer.")
    return os.path.join(
        self.data_dir, "Versions/Base%s" % build_version, self._exec_name)
示例#4
0
def get(sc2_run_config=None):
    """Get the current platform OS config (else as specified)"""
    configs = {
        c.name(): c
        for c in lib.RunConfig.all_subclasses() if c.priority()
    }

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

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

    try:
        return configs[sc2_run_config]()
    except KeyError:
        raise lib.SC2LaunchError("Invalid run_config. Valid configs are: %s" %
                                 (", ".join(sorted(configs.keys()))))