def MakeDeployableBinary(self, template_path, output_path=None):
    """This will add the config to the client template and create a .deb."""
    if output_path is None:
      output_path = config_lib.CONFIG.Get("ClientBuilder.output_path",
                                          context=self.context)

    buildpackage_binary = "/usr/bin/dpkg-buildpackage"
    if not os.path.exists(buildpackage_binary):
      logging.error("dpkg-buildpackage not found, unable to repack client.")
      return

    with utils.TempDirectory() as tmp_dir:
      template_dir = os.path.join(tmp_dir, "dist")
      utils.EnsureDirExists(template_dir)

      zf = zipfile.ZipFile(template_path)
      for name in zf.namelist():
        if os.path.basename(name) == "build.yaml":
          self.MergeBuildConfig(data=zf.read(name))
          continue

        dirname = os.path.dirname(name)
        utils.EnsureDirExists(os.path.join(template_dir, dirname))
        with open(os.path.join(template_dir, name), "wb") as fd:
          fd.write(zf.read(name))

      # Generate the dpkg files.
      self.GenerateDPKGFiles(tmp_dir)

      # Create a client config.
      client_context = ["Client Context"] + self.context
      client_config_content = self.GetClientConfig(client_context)

      # We need to strip leading /'s or .join will ignore everything that comes
      # before it.
      target_dir = config_lib.CONFIG.Get("ClientBuilder.target_dir",
                                         context=self.context).lstrip("/")
      agent_dir = os.path.join(
          template_dir, "debian",
          config_lib.CONFIG.Get("ClientBuilder.package_name",
                                context=self.context),
          target_dir)

      with open(os.path.join(agent_dir, config_lib.CONFIG.Get(
          "ClientBuilder.config_filename", context=self.context)), "wb") as fd:
        fd.write(client_config_content)

      # Set the daemon to executable.
      os.chmod(os.path.join(agent_dir, config_lib.CONFIG.Get(
          "Client.binary_name", context=self.context)), 0755)

      arch = config_lib.CONFIG.Get("Client.arch", context=self.context)

      try:
        old_working_dir = os.getcwd()
      except OSError:
        old_working_dir = os.environ.get("HOME", "/tmp")

      try:
        os.chdir(template_dir)
        command = [buildpackage_binary, "-uc", "-d", "-b", "-a%s" % arch]

        try:
          subprocess.check_output(command, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
          if e.output not in "Failed to sign":
            logging.error("Error calling %s.", command)
            logging.error(e.output)
            raise

        filename_base = config_lib.CONFIG.Get(
            "ClientBuilder.debian_package_base", context=self.context)
        output_base = config_lib.CONFIG.Get("ClientBuilder.output_basename",
                                            context=self.context)
        utils.EnsureDirExists(os.path.dirname(output_path))

        for extension in [".changes", config_lib.CONFIG.Get(
            "ClientBuilder.output_extension", context=self.context)]:
          input_name = "%s%s" % (filename_base, extension)
          output_name = "%s%s" % (output_base, extension)

          shutil.move(os.path.join(tmp_dir, input_name),
                      os.path.join(os.path.dirname(output_path), output_name))

        logging.info("Created package %s", output_path)
        return output_path
      finally:
        try:
          os.chdir(old_working_dir)
        except OSError:
          pass
dataset/ETHPy150Open google/grr/grr/lib/build.py/LinuxClientDeployer.MakeDeployableBinary/swapped operands of `not in`