Exemplo n.º 1
0
def LoadPackageInfo(sysroot, all_packages, generateMissing, packages):
    """Do the work when we're not called as a hook."""
    logging.info('Processing sysroot %s', sysroot)

    detect_packages = not packages
    if detect_packages:
        # If no packages were specified, we look up the full list.
        packages = licenses_lib.ListInstalledPackages(sysroot, all_packages)

    assert packages, f'{sysroot}: could not find any packages'

    logging.debug('Initial Package list to work through:\n%s',
                  '\n'.join(sorted(packages)))
    licensing = licenses_lib.Licensing(sysroot, packages, generateMissing)

    licensing.LoadPackageInfo()
    logging.debug(
        'Package list to skip:\n%s',
        '\n'.join([p for p in sorted(packages) if licensing.packages[p].skip]))
    logging.debug(
        'Package list left to work through:\n%s', '\n'.join(
            [p for p in sorted(packages) if not licensing.packages[p].skip]))
    licensing.ProcessPackageLicenses()
    if detect_packages:
        # If we detected 'all' packages, we have to add in these extras.
        for fullnamewithrev, homepages, names, files in EXTRA_PACKAGES:
            license_texts = [
                osutils.ReadFile(os.path.join(EXTRA_LICENSES_DIR, f))
                for f in files
            ]
            licensing.AddExtraPkg(fullnamewithrev, homepages, names,
                                  license_texts)

    return licensing
Exemplo n.º 2
0
  def AddLicensingFile(self, dlc_dir):
    """Add the licensing file for this DLC.

    Args:
      dlc_dir: (str) The path to the mounted point during image creation.
    """
    if not self.ebuild_params.fullnamerev:
      return

    sysroot = cros_build_lib.GetSysroot(self.board)
    licensing = licenses_lib.Licensing(sysroot,
                                       [self.ebuild_params.fullnamerev], True)
    licensing.LoadPackageInfo()
    licensing.ProcessPackageLicenses()
    license_path = os.path.join(dlc_dir, LICENSE)
    # The first (and only) item contains the values for |self.fullnamerev|.
    _, license_txt = next(iter(licensing.GenerateLicenseText().items()))
    osutils.WriteFile(license_path, license_txt)
Exemplo n.º 3
0
def LoadPackageInfo(board, all_packages, generateMissing, packages):
    """Do the work when we're not called as a hook."""
    logging.info('Using board %s.', board)

    builddir = os.path.join(cros_build_lib.GetSysroot(board=board), 'tmp',
                            'portage')

    if not os.path.exists(builddir):
        raise AssertionError(
            'FATAL: %s missing.\n'
            'Did you give the right board and build that tree?' % builddir)

    detect_packages = not packages
    if detect_packages:
        # If no packages were specified, we look up the full list.
        packages = licenses_lib.ListInstalledPackages(board, all_packages)

    if not packages:
        raise AssertionError('FATAL: Could not get any packages for board %s' %
                             board)

    logging.debug('Initial Package list to work through:\n%s',
                  '\n'.join(sorted(packages)))
    licensing = licenses_lib.Licensing(board, packages, generateMissing)

    licensing.LoadPackageInfo()
    logging.debug(
        'Package list to skip:\n%s',
        '\n'.join([p for p in sorted(packages) if licensing.packages[p].skip]))
    logging.debug(
        'Package list left to work through:\n%s', '\n'.join(
            [p for p in sorted(packages) if not licensing.packages[p].skip]))
    licensing.ProcessPackageLicenses()
    if detect_packages:
        # If we detected 'all' packages, we have to add in these extras.
        for fullnamewithrev, homepages, names, files in EXTRA_PACKAGES:
            license_texts = [
                osutils.ReadFile(os.path.join(EXTRA_LICENSES_DIR, f))
                for f in files
            ]
            licensing.AddExtraPkg(fullnamewithrev, homepages, names,
                                  license_texts)

    return licensing