예제 #1
0
  def InstalledWorkonAtoms(self):
    """Returns the set of installed cros_workon packages."""
    installed_cp = set()
    for pkg in portage_util.PortageDB(self._sysroot).InstalledPackages():
      installed_cp.add('%s/%s' % (pkg.category, pkg.package))

    return set(a for a in self.ListAtoms(use_all=True) if a in installed_cp)
예제 #2
0
  def testListContents(self):
    """Test if the list of installed files is properly parsed."""
    pdb = portage_util.PortageDB(self.fake_chroot)
    pkg = pdb.GetInstalledPackage('with', 'files-1')
    self.assertTrue(pkg)
    lst = pkg.ListContents()

    # Check ListContents filters out the garbage we added to the list of files.
    fake_files = [f for f in self.fake_files if f[0] in ('sym', 'obj', 'dir')]
    self.assertEquals(len(fake_files), len(lst))

    # Check the paths are all relative.
    self.assertTrue(all(not f[1].startswith('/') for f in lst))

    # Check all the files are present. We only consider file type and path, and
    # convert the path to a relative path.
    fake_files = [(f[0], f[1].lstrip('/')) for f in fake_files]
    self.assertEquals(fake_files, lst)
예제 #3
0
    def ComputeEbuildDeps(self, sysroot):
        """Compute the dependencies between ebuilds and files.

    Iterates over the list of ebuilds in the database and annotates the files
    with the ebuilds they are in. For each ebuild installing a file in the root,
    also compute the direct dependencies. Stores the information internally.

    Args:
      sysroot: The path to the sysroot, for example "/build/link".
    """
        portage_db = portage_util.PortageDB(sysroot)
        if not os.path.exists(portage_db.db_path):
            logging.warning('PortageDB directory not found: %s',
                            portage_db.db_path)
            return

        for pkg in portage_db.InstalledPackages():
            pkg_files = []
            pkg_size = 0
            cpf = '%s/%s' % (pkg.category, pkg.pf)
            for typ, rel_path in pkg.ListContents():
                # We ignore other entries like for example "dir".
                if not typ in (pkg.OBJ, pkg.SYM):
                    continue
                # We ignore files installed in the SYSROOT that weren't copied to the
                # image.
                if not rel_path in self._files:
                    continue
                pkg_files.append(rel_path)
                file_data = self._files[rel_path]
                if 'ebuild' in file_data:
                    logging.warning('Duplicated entry for %s: %s and %s',
                                    rel_path, file_data['ebuild'], cpf)
                file_data['ebuild'] = cpf
                pkg_size += file_data['size']
            # Ignore packages that don't install any file.
            if not pkg_files:
                continue
            self._ebuilds[cpf] = {
                'size': pkg_size,
                'files': len(pkg_files),
                'atom': '%s/%s' % (pkg.category, pkg.package),
                'version': pkg.version,
            }
예제 #4
0
def get_all_package_objects(board):
    """Given a board, returns a dict of {package_name: [objects_in_package]}

  `objects_in_package` is specifically talking about objects of type `obj`
  which were installed by the given package. In other words, this will
  enumerate all regular files (e.g., excluding directories and symlinks)
  installed by a package.

  This dict comprises all packages currently installed on said board.
  """
    db = portage_util.PortageDB(root=os.path.join('/build', board))

    result = collections.defaultdict(set)
    for package in db.InstalledPackages():
        objects = ('/' + path for typ, path in package.ListContents()
                   if typ == package.OBJ)
        result['%s/%s' % (package.category, package.package)].update(objects)

    return {k: sorted(v) for k, v in result.items()}
예제 #5
0
def main(argv):
    """Find and report approximate size info for a particular built package."""
    commandline.RunInsideChroot()

    parser = _get_parser()
    opts = parser.parse_args(argv)
    opts.Freeze()

    db = portage_util.PortageDB(root=opts.root)

    if opts.packages:
        installed_packages = portage_util.GenerateInstalledPackages(
            db, opts.root, opts.packages)
    else:
        installed_packages = db.InstalledPackages()

    results = generate_package_size_report(db, opts.root, opts.image_type,
                                           opts.partition_name,
                                           installed_packages)
    print(json.dumps(results))