The apt_pkg extensions provides a more low-level way to work with apt. It can do everything apt can, and is written in C++. It has been in python-apt since the beginning.
Return a Cdrom object with the following methods:
Return a new PkgRecords object.
The parameter cache refers to an pkgCache object, as returned by GetCache().
Return an Acquire object. This is a class which allows you to fetch files, or archive contents. The parameter progress refers to an apt.progress.FetchProgress() object.
Acquire items have multiple methods:
Create a new PkgAcqFile() object and register it with acquire, so it will be fetched.
The parameter acquire refers to an Acquire() object as returned by GetAcquire(). The file will be added to the Acquire queue automatically.
The parameter uri refers to the location of the file, any protocol of apt is supported.
The parameter md5 refers to the md5sum of the file. This can be used for checking the file.
The parameter size can be used to specify the size of the package, which can then be used to calculate the progress and validate the download.
The parameter descr is a descripition of the download. It may be used to describe the item in the progress class. shortDescr is the short form of it.
You can use destDir to manipulate the directory where the file will be saved in. Instead of destDir, you can also specify the full path to the file using the parameter destFile. You can not combine both.
The apt_pkg module also provides several hash functions. If you develop applications with python-apt it is often easier to use these functions instead of the ones provides in Python’s hashlib module.
Note
This documentation is (in parts) created automatically, and still needs to be improved.
ParseCommandLine(Configuration,ListOfOptions,List-argv) -> List
This function is like getopt except it manipulates a configuration space. output is a list of non-option arguments (filenames, etc). ListOfOptions is a list of tuples of the form:
(‘c’,”long-opt or None”,”Configuration::Variable”,”optional type”)
Where type may be one of HasArg, IntLevel, Boolean, InvBoolean, ConfigFile, or ArbItem. The default is Boolean.
ParseDepends(s) -> list of tuples
The resulting tuples are (Pkg,Ver,Operation). Each anded dependency is a list of or’d dependencies Source depends are evaluated against the curernt arch and only those that Match are returned.
ParseDepends(s) -> list of tuples
The resulting tuples are (Pkg,Ver,Operation). Each anded dependency is a list of or’d dependencies Source depends are evaluated against the curernt arch and only those that Match are returned.
RewriteSection(Section,Order,RewriteList) -> String
The section rewriter allows a section to be taken in, have fields added, removed or changed and then put back out. During this process the fields within the section are sorted to corrispond to a proper order. Order is a list of field names with their proper capitialization. apt_pkg.RewritePackageOrder and apt_pkg.RewriteSourceOrder are two predefined orders. RewriteList is a list of tuples. Each tuple is of the form:
(Tag,NewValue[,RenamedTo])
Tag specifies the tag in the source section. NewValue is the new value of that tag and the optional RenamedTo field can cause the tag to be changed. If NewValue is None then the tag is removed Ex. (‘Source’,’apt’,’Package’) is used for .dsc files.
Return a string presenting the human-readable version of the integer size. When calculating the units (k,M,G,etc.) the size is divided by the factor 1000.
Example:
>>> apt_pkg.SizeToStr(10000)
'10.0k'
Parse the string input and return one of -1, 0, 1.
Value | Meaning |
---|---|
-1 | The string input is not recognized. |
0 | The string input evaluates to False. |
+1 | The string input evaluates to True. |
Example:
>>> apt_pkg.StringToBool("yes")
1
>>> apt_pkg.StringToBool("no")
0
>>> apt_pkg.StringToBool("not-recognized")
-1
Convert the RFC 1123 conforming string rfc_time to the unix time, and return the integer. This is the opposite of TimeRFC1123().
Example:
>> apt_pkg.StrToTime('Thu, 01 Jan 1970 00:00:00 GMT')
0
Format the unix time specified by the integer seconds, according to the requirements of RFC 1123.
Example:
>>> apt_pkg.TimeRFC1123(0)
'Thu, 01 Jan 1970 00:00:00 GMT'
Format a given duration in a human-readable manner. The parameter seconds refers to a number of seconds, given as an integer. The return value is a string with a unit like ‘s’ for seconds.
Example:
>>> apt_pkg.TimeToStr(3601)
'1h0min1s'
Take a string uri as parameter and return a filename which can be used to store the file, based on the URI.
Example:
>>> apt_pkg.URItoFileName('http://debian.org/index.html')
'debian.org_index.html'
Compare two versions, a and b, and return an integer value which has the same characteristic as the built-in cmp() function.
Value | Meaning |
---|---|
> 0 | The version a is greater than version b. |
= 0 | Both versions are equal. |
< 0 | The version a is less than version b. |