Back to index

apport  2.3
packaging.py
Go to the documentation of this file.
00001 '''Abstraction of packaging operations.'''
00002 
00003 # Copyright (C) 2007 - 2011 Canonical Ltd.
00004 # Author: Martin Pitt <martin.pitt@ubuntu.com>
00005 #
00006 # This program is free software; you can redistribute it and/or modify it
00007 # under the terms of the GNU General Public License as published by the
00008 # Free Software Foundation; either version 2 of the License, or (at your
00009 # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
00010 # the full text of the license.
00011 
00012 
00013 class PackageInfo:
00014     def get_version(self, package):
00015         '''Return the installed version of a package.
00016 
00017         Throw ValueError if package does not exist.
00018         '''
00019         raise NotImplementedError('this method must be implemented by a concrete subclass')
00020 
00021     def get_available_version(self, package):
00022         '''Return the latest available version of a package.
00023 
00024         Throw ValueError if package does not exist.
00025         '''
00026         raise NotImplementedError('this method must be implemented by a concrete subclass')
00027 
00028     def get_dependencies(self, package):
00029         '''Return a list of packages a package depends on.'''
00030 
00031         raise NotImplementedError('this method must be implemented by a concrete subclass')
00032 
00033     def get_source(self, package):
00034         '''Return the source package name for a package.
00035 
00036         Throw ValueError if package does not exist.
00037         '''
00038         raise NotImplementedError('this method must be implemented by a concrete subclass')
00039 
00040     def get_package_origin(self, package):
00041         '''Return package origin.
00042 
00043         Return the repository name from which a package was installed, or None
00044         if it cannot be determined.
00045 
00046         Throw ValueError if package is not installed.
00047         '''
00048         raise NotImplementedError('this method must be implemented by a concrete subclass')
00049 
00050     def is_distro_package(self, package):
00051         '''Check package origin.
00052 
00053         Return True if the package is a genuine distro package, or False if it
00054         comes from a third-party source.
00055 
00056         Throw ValueError if package does not exist.
00057         '''
00058         raise NotImplementedError('this method must be implemented by a concrete subclass')
00059 
00060     def get_architecture(self, package):
00061         '''Return the architecture of a package.
00062 
00063         This might differ on multiarch architectures (e. g.  an i386 Firefox
00064         package on a x86_64 system)
00065         '''
00066         raise NotImplementedError('this method must be implemented by a concrete subclass')
00067 
00068     def get_files(self, package):
00069         '''Return list of files shipped by a package.
00070 
00071         Throw ValueError if package does not exist.
00072         '''
00073         raise NotImplementedError('this method must be implemented by a concrete subclass')
00074 
00075     def get_modified_files(self, package):
00076         '''Return list of all modified files of a package.'''
00077 
00078         raise NotImplementedError('this method must be implemented by a concrete subclass')
00079 
00080     def get_modified_conffiles(self, package):
00081         '''Return modified configuration files of a package.
00082 
00083         Return a file name -> file contents map of all configuration files of
00084         package. Please note that apport.hookutils.attach_conffiles() is the
00085         official user-facing API for this, which will ask for confirmation and
00086         allows filtering.
00087         '''
00088         return {}
00089 
00090     def get_file_package(self, file, uninstalled=False, map_cachedir=None):
00091         '''Return the package a file belongs to.
00092 
00093         Return None if the file is not shipped by any package.
00094 
00095         If uninstalled is True, this will also find files of uninstalled
00096         packages; this is very expensive, though, and needs network access and
00097         lots of CPU and I/O resources. In this case, map_cachedir can be set to
00098         an existing directory which will be used to permanently store the
00099         downloaded maps. If it is not set, a temporary directory will be used.
00100         '''
00101         raise NotImplementedError('this method must be implemented by a concrete subclass')
00102 
00103     def get_system_architecture(self):
00104         '''Return the architecture of the system.
00105 
00106         This should use the notation of the particular distribution.
00107         '''
00108         raise NotImplementedError('this method must be implemented by a concrete subclass')
00109 
00110     def get_library_paths(self):
00111         '''Return a list of default library search paths.
00112 
00113         The entries should be separated with a colon ':', like for
00114         $LD_LIBRARY_PATH. This needs to take any multiarch directories into
00115         account.
00116         '''
00117         # dummy default implementation
00118         return '/lib:/usr/lib'
00119 
00120     def set_mirror(self, url):
00121         '''Explicitly set a distribution mirror URL.
00122 
00123         This might be called for operations that need to fetch distribution
00124         files/packages from the network.
00125 
00126         By default, the mirror will be read from the system configuration
00127         files.
00128         '''
00129         raise NotImplementedError('this method must be implemented by a concrete subclass')
00130 
00131     def get_source_tree(self, srcpackage, dir, version=None):
00132         '''Download a source package and unpack it into dir..
00133 
00134         dir should exist and be empty.
00135 
00136         This also has to care about applying patches etc., so that dir will
00137         eventually contain the actually compiled source.
00138 
00139         If version is given, this particular version will be retrieved.
00140         Otherwise this will fetch the latest available version.
00141 
00142         Return the directory that contains the actual source root directory
00143         (which might be a subdirectory of dir). Return None if the source is
00144         not available.
00145         '''
00146         raise NotImplementedError('this method must be implemented by a concrete subclass')
00147 
00148     def compare_versions(self, ver1, ver2):
00149         '''Compare two package versions.
00150 
00151         Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.
00152         '''
00153         raise NotImplementedError('this method must be implemented by a concrete subclass')
00154 
00155     def enabled(self):
00156         '''Return whether Apport should generate crash reports.
00157 
00158         Signal crashes are controlled by /proc/sys/kernel/core_pattern, but
00159         some init script needs to set that value based on a configuration file.
00160         This also determines whether Apport generates reports for Python,
00161         package, or kernel crashes.
00162 
00163         Implementations should parse the configuration file which controls
00164         Apport (such as /etc/default/apport in Debian/Ubuntu).
00165         '''
00166         raise NotImplementedError('this method must be implemented by a concrete subclass')
00167 
00168     def get_kernel_package(self):
00169         '''Return the actual Linux kernel package name.
00170 
00171         This is used when the user reports a bug against the "linux" package.
00172         '''
00173         raise NotImplementedError('this method must be implemented by a concrete subclass')
00174 
00175     def install_packages(self, rootdir, configdir, release, packages,
00176                          verbose=False, cache_dir=None, permanent_rootdir=False):
00177         '''Install packages into a sandbox (for apport-retrace).
00178 
00179         In order to work without any special permissions and without touching
00180         the running system, this should only download and unpack packages into
00181         the given root directory, not install them into the system.
00182 
00183         configdir points to a directory with by-release configuration files for
00184         the packaging system; this is completely dependent on the backend
00185         implementation, the only assumption is that this looks into
00186         configdir/release/, so that you can use retracing for multiple
00187         DistroReleases. As a special case, if configdir is None, it uses the
00188         current system configuration, and "release" is ignored.
00189 
00190         release is the value of the report's 'DistroRelease' field.
00191 
00192         packages is a list of ('packagename', 'version') tuples. If the version
00193         is None, it should install the most current available version.
00194 
00195         If cache_dir is given, then the downloaded packages will be stored
00196         there, to speed up subsequent retraces.
00197 
00198         If permanent_rootdir is True, then the sandbox created from the
00199         downloaded packages will be reused, to speed up subsequent retraces.
00200 
00201         Return a string with outdated packages, or None if all packages were
00202         installed.
00203 
00204         If something is wrong with the environment (invalid configuration,
00205         package servers down, etc.), this should raise a SystemError with a
00206         meaningful error message.
00207         '''
00208         raise NotImplementedError('this method must be implemented by a concrete subclass')
00209 
00210     def package_name_glob(self, glob):
00211         '''Return known package names which match given glob.'''
00212 
00213         raise NotImplementedError('this method must be implemented by a concrete subclass')
00214 
00215     def get_uninstalled_package(self):
00216         '''Return a valid package name which is not installed.
00217 
00218         This is only used in the test suite. The default implementation should
00219         work, but might be slow for your backend, so you might want to
00220         reimplement this.
00221         '''
00222         for p in self.package_name_glob('*'):
00223             if not self.is_distro_package(p):
00224                 continue
00225             try:
00226                 self.get_version(p)
00227                 continue
00228             except ValueError:
00229                 return p