Exemple #1
0
def InstallGagdet(name, gadget, failed, all_adapters):
    try:
        v = {}
        v.update(gadget.get('all', {}))
        v.update(gadget.get(OS, {}))

        if 'download' in gadget:
            if 'file_name' not in v:
                raise RuntimeError("Unsupported OS {} for gadget {}".format(
                    OS, name))

            destination = os.path.join(gadget_dir, 'download', name,
                                       v['version'])

            url = string.Template(gadget['download']['url']).substitute(v)

            file_path = installer.DownloadFileTo(
                url,
                destination,
                file_name=gadget['download'].get('target'),
                checksum=v.get('checksum'),
                check_certificate=not args.no_check_certificate)

            root = os.path.join(destination, 'root')
            installer.ExtractZipTo(file_path,
                                   root,
                                   format=gadget['download'].get(
                                       'format', 'zip'))
        elif 'repo' in gadget:
            url = string.Template(gadget['repo']['url']).substitute(v)
            ref = string.Template(gadget['repo']['ref']).substitute(v)

            destination = os.path.join(gadget_dir, 'download', name)
            installer.CloneRepoTo(url, ref, destination)
            root = destination

        if 'do' in gadget:
            gadget['do'](name, root, v)
        else:
            InstallGeneric(name, root, v)

        # Allow per-OS adapter overrides. v already did that for us...
        all_adapters.update(v.get('adapters', {}))
        # Add any other "all" adapters
        all_adapters.update(gadget.get('adapters', {}))

        print("Done installing {}".format(name))
    except Exception as e:
        traceback.print_exc()
        failed.append(name)
        print("FAILED installing {}: {}".format(name, e))
    print(
      f"WARNING: Gadget not downloadable (probably a git clone?) {gadget_name}",
      file=sys.stderr )

  destination = '.'

  last_url = ''
  for OS in 'linux', 'macos', 'windows':
    for PLATFORM in 'x86_64', 'x86', 'arm64':
      spec = {}
      spec.update( gadget.get( 'all', {} ) )
      spec.update( gadget.get( OS, {} ) )
      spec.update( gadget.get( OS + '_' + PLATFORM, {} ) )

      url = string.Template( gadget[ 'download' ][ 'url' ] ).substitute( spec )
      if url == last_url:
        # Probably not different for this arch
        continue

      file_path = installer.DownloadFileTo(
        url,
        destination,
        file_name = gadget[ 'download' ].get( 'target' ),
        checksum = spec.get( 'checksum' ) )

      checksum = installer.GetChecksumSHA254( file_path )
      results.append( f"{ gadget_name } { OS }_{ PLATFORM }: { checksum }" )

for result in results:
  print( result )