Cache::Apt::Lookup

Langue: en

Version: 2010-02-27 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

Name

Cache::Apt::Lookup - Cache handler for apt-cross and related tools

Description

Extensively modified portion of NorthernCross using only the Config and Cache modules and exposing the package details using a dedicated struct.

Includes code from apt-rdepends to get the Depends info efficiently.

Example

  use Cache::Apt::Lookup;
  use Cache::Apt::Config;
  use Cache::Apt::Package;
  use Debian::DpkgCross;   # for check_arch
  use Data::Dumper;
 
  my $verbose = 0;    # usually read a command line option to set an integer
  my $arch = "arm";   # usually read a command line string parameter for this.
  my $suite = "unstable";  # or use &get_suite();
  &set_verbose ($verbose);
  &check_arch($arch) if (defined ($arch));
 
  &setup_config;
  &update_sources;
  my $config = &init_cache($verbose);
 
 
  Copyright (C) 2006, 2007  Neil Williams <codehelp@debian.org>
 
  Copyright (c) 2006, 2007  Alexander Shishkin <alexander.shishkin@siemens.com>
 
  Copyright (C) 2002-2005  Simon Law <sfllaw@debian.org>
 
  This package is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.
 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 

compare (A, B)

Direct link to the apt perl binding for version comparison.

Compare package version A with B, returning a negative value if A is an earlier version than B, zero if the same or a positive value if A is later.

init_host_cache($verbose)

Alternative function that initialises a copy of the host cache in the apt-cross directory to provide data on cross packages available for installation.

If $verbose >=4, the full Apt configuration is dumped to STDOUT before the call returns.

The cache lists are not removed when switching from one architecture to another.

Remember which cache has been initialised! Queries are made against whichever cache was initialised most recently.

init_cache($verbose)

Loads the currently configured cache into memory.

Accepts a verbosity level to support debugging modes.

If $verbose >=4, the full Apt configuration is dumped to STDOUT before the call returns.

clear_config

Completely clears the current config in preparation for a new set of &check_cache_arch, &set_suite and &init_cache;

srclookup($package_name)

Look up a package name in the source cache and return the raw apt-pkg-perl data or undef on error.

binlookup($package_name)

Look up a package name in the Packages cache and return the raw apt-pkg-perl data or undef on error.

deplookup($AptCrossPackage_struct)

Expects an AptCrossPackage and populates that variable with the dependency information for that package using the current cache configuration. Returns an array of AptCrossDependency instances suitable to be dropped into the AptCrossPackage::Depends variable.

get_cache_iter

Provides an iterator over all package names.

Example: (listing of all unique package names)

  my $iter = &lookup();
  my $pkg;
  my @package_names = ();
  my %hash = ();
  my $c = 0;
 
  do {
         $pkg = $iter->next;
         $hash{$pkg}++ if ($pkg);
  } while ($pkg);
 
  @package_names = sort (keys %hash);
  foreach my $p (@package_names)
  {
         print "$p ";
         $c++;
  }
 
  print "\nTotal of $c package names\n";
 
 

set_cachedir($dir)

Override the default apt_cross_dir with a specified directory that must already exist. This directory is also expected to contain any sources.list files that your script will later specify to Config.

get_aptcross_dir

Sets and returns the location of ~/.apt-cross or uses .apt-cross if no home could be found. Note that when running under sudo (e.g. in a chroot) $home will be the home directory of the SUDO_USER within the chroot.

If cachedir has been set and is usable, returns $cachedir.

get_cachedir

Replacement for get_aptcross_dir to distance the modules from the apt-cross package. get_aptcross_dir may be removed in future versions so use this function to get the location of the cache.

get_verbose

Return the current verbosity setting.

set_verbose($verbose)

Used by scripts to pass a command-line verbose level to the module to be used to create debugging output to the console.
  0 == quiet
  1 == normal
  2 == add some progress output or user-level messages.
  3 == add debug messages to level 2.
  4 == add detailed configuration dumps to level 3.
 
 

set_mirror($mirror)

Supports the apt-cross -m option by adding a specific mirror to the sources for the currently configured cache. An update will be needed to load the cache data from the mirror.

force_update

Removes the timestamp file for the current user-specific cache and forces an update of the apt cache. Supports the apt-cross -u command.

check_update

Non-intrusive way to ensure the user-specific cache for the current configuration is up to date without force. If the cache has been updated within the last 24hrs, no update is performed.

setup_config

Init function for the ~/.apt-cross directory that prepares a directory tree suitable for each suite and architecture combination. Copies your apt sources for use with the cross caches and manages the timestamp file to ensure the configured cache is up to date using update_sources.

update_sources

Actually performs the apt-get update for the currently configured cache. Called by setup_config, force_update and check_update.

cache_update

Update the user-specific apt-cross cache using the current configuration. Errors are directed to /dev/null because switching architectures and configurations can cause misleading and unnecessary error messages from apt.

prepare_sources_list

Collates your various apt sources into one array that can be used to provide sources for your cross caches.

get_provides

Retrieves the ProvidesList for the specified package.

The AptPkg bindings index the ProvidesList under what is provided, not what the specified package provides, so this routine iterates over the cache and creates a suitable index. Subsequent queries are made against the new hash.

e.g. When querying apt-cache, you may expect to see:
 $ apt-cache show cdebconf | grep Provides
 Provides: debconf-2.0

However, in the AptPkg bindings, this relationship is indexed under debconf-2.0, not under cdebconf. i.e.
 $cache->{``debconf-2.0''}{ProvidesList}[0]{Name} eq ``cdebconf'' actually returns true when Cache::Apt::Lookup expects:
 $cache->{``cdebconf''}{ProvidesList}[0]{Name} eq ``debconf-2.0'' to be true.

Returns a comma-separated list of packages that are provided by the specified package or undef.

update_multiarch

Calculates the Packages file for the requested suite and architecture and uses that to update the multiarch lists. Warns if the calculated file does not exist - in which case, use the "--suite" or "-S" options to apt-cross to explicitly state which suite to use. (This can happen if you use codenames in your /etc/apt/sources.list rather than suite names (sid instead of unstable). Apart from sid, the mapping from a codename to a suite name changes with each release and this module does not attempt to keep up with these changes.

Once found, the routine checks for /usr/share/apt-cross/update-multiarch.pl and passes the Packages file to it.