def BuildWithPyInstaller(self):
    """Use pyinstaller to build a client package."""
    self.CleanDirectory(
        config.CONFIG.Get("PyInstaller.distpath", context=self.context))

    logging.info("Copying pyinstaller support files")
    self.spec_file = os.path.join(self.build_dir, "grr.spec")

    with open(self.spec_file, "wb") as fd:
      fd.write(config.CONFIG.Get("PyInstaller.spec", context=self.context))

    with open(os.path.join(self.build_dir, "version.txt"), "wb") as fd:
      fd.write(config.CONFIG.Get("PyInstaller.version", context=self.context))

    shutil.copy(
        src=config.CONFIG.Get("PyInstaller.icon_path", context=self.context),
        dst=os.path.join(self.build_dir, u"grr.ico"))

    # We expect the onedir output at this location.
    self.output_dir = os.path.join(
        config.CONFIG.Get("PyInstaller.distpath", context=self.context),
        "grr-client")

    # Pyinstaller doesn't handle unicode strings.
    args = [
        "--distpath",
        str(config.CONFIG.Get("PyInstaller.distpath", context=self.context)),
        "--workpath",
        str(
            config.CONFIG.Get("PyInstaller.workpath_dir",
                              context=self.context)),
        str(self.spec_file)
    ]
    logging.info("Running pyinstaller: %s", args)
    PyInstallerMain.run(pyi_args=[utils.SmartStr(x) for x in args])

    # Clear out some crud that pyinstaller includes.
    for path in ["tcl", "tk", "pytz"]:
      dir_path = os.path.join(self.output_dir, path)
      try:
        shutil.rmtree(dir_path)
      except OSError:
        logging.error("Unable to remove directory: %s", dir_path)

      try:
        os.mkdir(dir_path)
      except OSError:
        logging.error("Unable to create directory: %s", dir_path)

      file_path = os.path.join(dir_path, path)
      try:
        # Create an empty file so the directories get put in the installers.
        with open(file_path, "wb"):
          pass
      except IOError:
        logging.error("Unable to create file: %s", file_path)

    version_ini = version.VersionPath()
    shutil.copy(version_ini, os.path.join(self.output_dir, "version.ini"))

    with open(os.path.join(self.output_dir, "build.yaml"), "wb") as fd:
      self.WriteBuildYaml(fd)
def BuildWithPyInstaller ( self ) : self . CleanDirectory ( config . CONFIG . Get ( "PyInstaller.distpath" , context = self . context ) ) logging . info ( "Copying pyinstaller support files" ) self . spec_file = os . path . join ( self . build_dir , "grr.spec" ) with open ( self . spec_file , "wb" ) as fd : fd . write ( config . CONFIG . Get ( "PyInstaller.spec" , context = self . context ) ) with open ( os . path . join ( self . build_dir , "version.txt" ) , "wb" ) as fd : fd . write ( config . CONFIG . Get ( "PyInstaller.version" , context = self . context ) ) shutil . copy ( src = config . CONFIG . Get ( "PyInstaller.icon_path" , context = self . context ) , dst = os . path . join ( self . build_dir , u"grr.ico" ) ) self . output_dir = os . path . join ( config . CONFIG . Get ( "PyInstaller.distpath" , context = self . context ) , "grr-client" ) args = [ "--distpath" , str ( config . CONFIG . Get ( "PyInstaller.distpath" , context = self . context ) ) , "--workpath" , str ( config . CONFIG . Get ( "PyInstaller.workpath_dir" , context = self . context ) ) , str ( self . spec_file ) ] logging . info ( "Running pyinstaller: %s" , args ) PyInstallerMain . run ( pyi_args = [ utils . SmartStr ( x ) for x in args ] ) for path in [ "tcl" , "tk" , "pytz" ] : dir_path = os . path . join ( self . output_dir , path ) try : shutil . rmtree ( dir_path ) except OSError : logging . error ( "Unable to remove directory: %s" , dir_path ) try : os . mkdir ( dir_path ) except OSError : logging . error ( "Unable to create directory: %s" , dir_path ) file_path = os . path . join ( dir_path , path ) try : with open ( file_path , "wb" ) : pass except IOError : logging . error ( "Unable to create file: %s" , file_path ) version_ini = version . VersionPath ( ) shutil . copy ( version_ini , os . path . join ( self . output_dir , "version.ini" ) ) with open ( os . path . join ( self . output_dir , "build.yaml" ) , "wb" ) as fd : self . WriteBuildYaml ( fd )
Use pyinstaller to build a client package.