Librepo includes several classes:
Librepo module has only one own exception.
Value of this exception is tuple with three elements: (return code, error message, general error message)
LRO_ (aka LibRepo Option) prefixed constants are used to set Handle options via setopt() method.
This options could be also set by Handle attributes with the same names but in lowercase and without LRO_ prefix.
Example:
# The command: h.setopt(librepo.LRO_URLS, ["http://ftp.linux.ncsu.edu/pub/fedora/linux/releases/17/Everything/i386/os/"]) # is equivalent to: h.urls = ["http://ftp.linux.ncsu.edu/pub/fedora/linux/releases/17/Everything/i386/os/"]Note
For detailed description of this options consult Handle page.
Boolean. Set to True if only want update localised or downloaded repository represented by Result object. Update mode is meant to download previously omitted repository file(s).
List or None. Set repository urls (repository url and baseurl are interchangeable terms in this context).
String or None. DEPRECATED Set mirrorlist url (url could point to a metalink mirrorlist or to a simple mirrorlist where each line wihtout '#' is considered as mirror url).
String or None. Mirrorlist URL.
String or None. Metalink URL.
Boolean. If set to True, no local copy of repository is created and repository is just localised in its current location. When True, url of repository MUST be a local address (e.g. ‘/home/user/repo’ or ‘file:///home/user/repo‘).
Boolean. If True, all supported methods of HTTP authentication are enabled.
String or None. Set username and password for HTTP authentication. Param must be in format ‘username:password’.
String or None. Set proxy server address. Port could be specified by different option or by the :[port] suffix of this address. Any protocol prefix (http://, ...) will be ignored.
Integer or None. Set proxy port number to connect unsless it is specified in the proxy address string. None sets default value 1080.
Long. Set type of proxy - could be one of Proxy type constants
Boolean. If True, all supported proxy authentication methods are enabled. If False, only basic authentication method is enabled.
String or None. Set username and password for proxy authentication in format ‘username:password’.
Function or None. (See: Progress callback - progresscb) Set progress callback. Callback must be in format: callback(userdata, total_to_download, downloaded). If total_to_download is 0, then total size is not known. Total size (total_to_download) could change (grow) among two callback calls (if some download failed and another mirror is tried).
Any object. Set user data for the progress callback.
Long or None. Set maximal allowed speed per download in bytes per second. 0 = unlimited speed - the default value.
String or None. Set destination directory for downloaded data (metadata or packages).
Integer. One of Repo type constants. See more repotype() Set type of repository.
Integer or None. Set maximal timeout in sec for connection phase. Default value is 120. None as *val sets the default value.
Boolean. If you want to localise (LRO_LOCAL is True) a incomplete local repository (eg. only primary and filelists are present but repomd.xml contains more files), you could use LRO_YUMDLIST and specify only file that are present, or use LRO_YUMBLIST and specify files that are not present or use this option.
Boolean. Librepo sets up its own SIGTERM handler. If the SIGTERM signal is catched, the current download is interrupted.
String. String for User-Agent: header in the http request sent to the remote server.
Boolean. With this option enabled, only mirrorlist download and parsing will be performed during librepo.Handle.perform().
Integer or None. If download fails, try at most the specified number of mirrors. 0 (None) means try all available mirrors.
Integer or None. Maximum number of parallel downloads. None sets default value.
Integer or None. Maximum number of parallel downloads per mirror. None sets default value.
[(String, String), ...] or None. Set list of substitutions for variables in ulrs (e.g.: “http://foo/$version/”). [("releasever", "f18"), ("basearch", "i386")]
Boolean. If True, internal mirrorlist is sorted by the determined connection speed, after it is constructed.
String or None. Path to the cache file. If cache file it doesn’t exists it will be created.
Integer or None. Max age of cache record. Older records will not be used.
Function or None. (See: Fastestmirror callback - fastestmirrorcb) Fastest mirror status callback. Its prototype looks like callback(userdata, stage, data) Where userdata are data passed by user via LRO_FASTESTMIRRORDATA. stage is value from Fastest mirror stages. data value depends on stage value. See the list of available stages.
Any object. User data for fastest mirror status callback.
Integer or None. The time in seconds that the transfer should be below the LRO_LOWSPEEDLIMIT for the library to consider it too slow and abort. Default: 120 (sec)
Integer or None. The transfer speed in bytes per second that the transfer should be below during LRO_LOWSPEEDTIME seconds for the library to consider it too slow and abort. Default: 1000 (byte/s)
Boolean. Set True to enable gpg check (if available) of downloaded repo.
Boolean. Set False/True to disable/enable checksum check.
Note
Checksum check is enabled by default.
Note
If checksum check is disabled, then even explicitly specified checksum related params e.g. in download() method are ignored and checksum is not checked!
List of strings. Some predefined list Predefined yumdlist lists. Set list of yum metadata files to download. e.g. ["primary", "filelists", "other", "primary_db", "prestodelta"] If val is None, all metadata files will be downloaded. If val is [] or [None] only repomd.xml will be downloaded.
See LRO_YUMDLIST
List of strings. Set blacklist of yum metadata files. This files will not be downloaded.
See LRO_YUMBLIST
Function or None (See: Handle Mirror Failure Callback - hmfcb) The Handle Mirror Failure Callback is called when a metadata download fails. It provides a detailed information about what exactly failed. Call of this callback doesn’t mean that whole downloading failed. If there are other mirrors on the list, these mirrors will be tried.
Boolean. This option determines whether librepo verifies the authenticity of the peer’s certificate. This trust is based on a chain of digital signatures, rooted in certification authority (CA) certificates.
Boolean. This option determines whether librepo verifies that the server cert is for the server it is known as.
String or None. Path to the PEM format SSL client certificate to use when talking to the server.
String or None. Path to the PEM format SSL client key to use when talking to the server.
String or None. Path to a file containing the list of PEM format trusted CA certificates.
Integer or None Sets kind of IP addresses to use when resolving host names. Could be one of: Supported IP resolving
Integer or None If all transfers from a mirror failed (no successful transfer from the mirror exists) and the number of failed downloads is higher or equal to this value the mirror will be skipped (ignored) for all next downloads.
Note: Number of failed transfers for a single mirror can outreach this number! For example, if you set this value to 1 but you allow 3 parallel downloads it is possible that all three downloads start from the mirror, before any of them can fail. Then, if all three transfers fail, the number of failures for the mirror will be 3, even if this option was set to 1.
Integer or None If enabled, internal list of mirrors for each handle is re-sorted after each finished transfer. The the sorting is based on mirror error rate etc.
String or None set own GNUPG configuration directory (a dir with keyring).
Float of None Max length of fastest mirror measurement in seconds. Default value is 2.0sec.
List of strings or None List of strings that represent http headers. Each header has format “header_name: content”. If you add a header with no content as in ‘Accept:’ (no data on the right side of the colon), the internally used header will get disabled. With this option you can add new headers, replace internal headers and remove internal headers. To add a header with no content (nothing to the right side of the colon), use the form ‘MyHeader;’ (note the ending semicolon). Note: Headers must not be CRLF-terminated!
Boolean Make the handle work only locally, all remote URLs are ignored. Remote mirrorlists/metalinks (if they are specified) are ignored. Fastest mirror check (if enabled) is skiped.
Long (bitmask) Bitmask which tell Librepo which auth metods to use. See: Auth methods
Long (bitmask) Bitmask which tell Librepo which auth metods to use for proxy authentication. See: Auth methods
Boolean Enable/Disable EPSV (Extended Passive mode) for FTP.
Default value, resolves addresses to all IP versions that your system allows.
Resolve to IPv4 addresses.
Resolve to IPv6 addresses.
Classical repository in repo-md format with repodata/ directory.
See RPMMDREPO
YaST2 repository (http://en.opensuse.org/openSUSE:Standards_YaST2_Repository_Metadata_content).
Note
This option is not supported yet!
Debian repository
Note
This option is not supported yet!
Download all repodata files
Download only repomd.xml file
Download only primary.xml, filelists.xml and other.xml
Download only primary, filelists and other databases.
Download only files used by Hawkey (https://github.com/akozumpl/hawkey/). (primary, filelists, prestodelta)
Supported auth methods for LRO_HTTPAUTHMETHODS and LRO_PROXYAUTHMETHODS options.
No auth method enabled.
HTTP Basic authentication (Default).
HTTP Digest authentication.
HTTP Negotiate (SPNEGO) authentication.
HTTP NTLM authentication.
HTTP Digest authentication with an IE flavor.
NTLM delegating to winbind helper.
This is a meta symbol. OR this value together with a single specific auth value to force libcurl to probe for un-restricted auth and if not, only that single auth algorithm is acceptable.
All suitable methods.
Values used by fastest mirror callback (LRO_FASTESTMIRRORCB):
(3) Detection in progress. data is number of mirrors that will be pinged. If all times were loaded from cache, this stage is skiped.
LibRepo Error codes.
E.g. in case when LRO_UPDATE option is True and URL is a remote address.
reference to target file (repomd.xml), mirrorlist is empty, ..
E.g. (metalink doesn’t contain needed file, mirrorlist doesn’t contain urls, ..)
or more files.
An unknown error.
LibRepo Result options for use in getinfo() method.
Returns a flat dictionary with local paths to downloaded/localised rpmmd repository and basic repository’s information.:
{'repomd': u'/tmp/librepotest-jPMmX5/repodata/repomd.xml',
'url': u'http://127.0.0.1:5000/yum/static/01/'
'destdir': u'/tmp/librepotest-jPMmX5',
'metalink': None,
'mirrorlist': None,
'signature': None,
'primary': u'/tmp/librepotest-jPMmX5/repodata/4543ad62e4d86337cd1949346f9aec976b847b58-primary.xml.gz',
'primary_db': u'/tmp/librepotest-jPMmX5/repodata/735cd6294df08bdf28e2ba113915ca05a151118e-primary.sqlite.bz2',
'filelists': u'/tmp/librepotest-jPMmX5/repodata/aeca08fccd3c1ab831e1df1a62711a44ba1922c9-filelists.xml.gz',
'filelists_db': u'/tmp/librepotest-jPMmX5/repodata/4034dcea76c94d3f7a9616779539a4ea8cac288f-filelists.sqlite.bz2',
'other': u'/tmp/librepotest-jPMmX5/repodata/a8977cdaa0b14321d9acfab81ce8a85e869eee32-other.xml.gz',
'other_db': u'/tmp/librepotest-jPMmX5/repodata/fd96942c919628895187778633001cff61e872b8-other.sqlite.bz2',
}
Returns a dict with local paths to downloaded/localised rpmmd repository and basic repository’s information.:
{'repomd': u'/tmp/librepotest-jPMmX5/repodata/repomd.xml',
'url': u'http://127.0.0.1:5000/yum/static/01/'
'destdir': u'/tmp/librepotest-jPMmX5',
'metalink': None,
'mirrorlist': None,
'signature': None,
'paths': {'primary': u'/tmp/librepotest-jPMmX5/repodata/4543ad62e4d86337cd1949346f9aec976b847b58-primary.xml.gz',
'primary_db': u'/tmp/librepotest-jPMmX5/repodata/735cd6294df08bdf28e2ba113915ca05a151118e-primary.sqlite.bz2',
'filelists': u'/tmp/librepotest-jPMmX5/repodata/aeca08fccd3c1ab831e1df1a62711a44ba1922c9-filelists.xml.gz',
'filelists_db': u'/tmp/librepotest-jPMmX5/repodata/4034dcea76c94d3f7a9616779539a4ea8cac288f-filelists.sqlite.bz2',
'other': u'/tmp/librepotest-jPMmX5/repodata/a8977cdaa0b14321d9acfab81ce8a85e869eee32-other.xml.gz',
'other_db': u'/tmp/librepotest-jPMmX5/repodata/fd96942c919628895187778633001cff61e872b8-other.sqlite.bz2'}
}
Returns a flat dict representing a repomd.xml file of downloaded rpmmd repository.:
{'revision': u'1347459931',
'repo_tags': [],
'content_tags': [],
'distro_tags': [],
'primary': {'checksum': u'4543ad62e4d86337cd1949346f9aec976b847b58',
'checksum_open': u'68457ceb8e20bda004d46e0a4dfa4a69ce71db48',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/4543ad62e4d86337cd1949346f9aec976b847b58-primary.xml.gz',
'size': 936L,
'size_open': 3385L,
'timestamp': 1347459930L},
'primary_db': {'checksum': u'735cd6294df08bdf28e2ba113915ca05a151118e',
'checksum_open': u'ba636386312e1b597fc4feb182d04c059b2a77d5',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/735cd6294df08bdf28e2ba113915ca05a151118e-primary.sqlite.bz2',
'size': 2603L,
'size_open': 23552L,
'timestamp': 1347459931L},
'filelists': {'checksum': u'aeca08fccd3c1ab831e1df1a62711a44ba1922c9',
'checksum_open': u'52d30ae3162ca863c63c345ffdb7f0e10c1414a5',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/aeca08fccd3c1ab831e1df1a62711a44ba1922c9-filelists.xml.gz',
'size': 43310L,
'size_open': 735088L,
'timestamp': 1347459930L},
'filelists_db': {'checksum': u'4034dcea76c94d3f7a9616779539a4ea8cac288f',
'checksum_open': u'949c6b7b605b2bc66852630c841a5003603ca5b2',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/4034dcea76c94d3f7a9616779539a4ea8cac288f-filelists.sqlite.bz2',
'size': 22575L,
'size_open': 201728L,
'timestamp': 1347459931L},
'other': {'checksum': u'a8977cdaa0b14321d9acfab81ce8a85e869eee32',
'checksum_open': u'4b5b8874fb233a626b03b3260a1aa08dce90e81a',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/a8977cdaa0b14321d9acfab81ce8a85e869eee32-other.xml.gz',
'size': 807L,
'size_open': 1910L,
'timestamp': 1347459930L},
'other_db': {'checksum': u'fd96942c919628895187778633001cff61e872b8',
'checksum_open': u'c5262f62b6b3360722b9b2fb5d0a9335d0a51112',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/fd96942c919628895187778633001cff61e872b8-other.sqlite.bz2',
'size': 1407L,
'size_open': 8192L,
'timestamp': 1347459931L},
}
Returns a dict representing a repomd.xml file of downloaded rpmmd repository.:
{'revision': u'1347459931',
'repo_tags': [],
'content_tags': [],
'distro_tags': [],
'records': {'primary': {'checksum': u'4543ad62e4d86337cd1949346f9aec976b847b58',
'checksum_open': u'68457ceb8e20bda004d46e0a4dfa4a69ce71db48',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/4543ad62e4d86337cd1949346f9aec976b847b58-primary.xml.gz',
'size': 936L,
'size_open': 3385L,
'timestamp': 1347459930L},
'primary_db': {'checksum': u'735cd6294df08bdf28e2ba113915ca05a151118e',
'checksum_open': u'ba636386312e1b597fc4feb182d04c059b2a77d5',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/735cd6294df08bdf28e2ba113915ca05a151118e-primary.sqlite.bz2',
'size': 2603L,
'size_open': 23552L,
'timestamp': 1347459931L}},
'filelists': {'checksum': u'aeca08fccd3c1ab831e1df1a62711a44ba1922c9',
'checksum_open': u'52d30ae3162ca863c63c345ffdb7f0e10c1414a5',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/aeca08fccd3c1ab831e1df1a62711a44ba1922c9-filelists.xml.gz',
'size': 43310L,
'size_open': 735088L,
'timestamp': 1347459930L},
'filelists_db': {'checksum': u'4034dcea76c94d3f7a9616779539a4ea8cac288f',
'checksum_open': u'949c6b7b605b2bc66852630c841a5003603ca5b2',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/4034dcea76c94d3f7a9616779539a4ea8cac288f-filelists.sqlite.bz2',
'size': 22575L,
'size_open': 201728L,
'timestamp': 1347459931L},
'other': {'checksum': u'a8977cdaa0b14321d9acfab81ce8a85e869eee32',
'checksum_open': u'4b5b8874fb233a626b03b3260a1aa08dce90e81a',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 0L,
'location_href': u'repodata/a8977cdaa0b14321d9acfab81ce8a85e869eee32-other.xml.gz',
'size': 807L,
'size_open': 1910L,
'timestamp': 1347459930L},
'other_db': {'checksum': u'fd96942c919628895187778633001cff61e872b8',
'checksum_open': u'c5262f62b6b3360722b9b2fb5d0a9335d0a51112',
'checksum_open_type': u'sha1',
'checksum_type': u'sha1',
'db_version': 10L,
'location_href': u'repodata/fd96942c919628895187778633001cff61e872b8-other.sqlite.bz2',
'size': 1407L,
'size_open': 8192L,
'timestamp': 1347459931L},
}
Returns the highest timestamp from all records in the repomd. See: http://yum.baseurl.org/gitweb?p=yum.git;a=commitdiff;h=59d3d67f
Some librepo’s functions and classes can take a callbacks in their arguments. This section contain the callbacks prototypes and explanation of their arguments.
By default all callbacks should return None (this is default behaviour of python function if it doesn’t have a specified return statement - it returns None).
But there are some callbacks that can return a specific values defined in Callbacks return values.
progresscb(userdata, totalsize, downloaded)
Callback frequently called during a download.
userdata: | User specified data or None |
---|---|
totalsize: | Total size (in bytes) of the target (float). |
downloaded: | Currently downloaded size (in bytes). |
returns: | This callback can return values from Callbacks return values |
endcb(userdata, status, msg)
Callback called when a transfer is done either successfully or unsuccessfully.
userdata: | User specified data or None |
---|---|
status: | Transfer statuses for endcb of PackageTarget |
msg: | String with error message or None |
returns: | This callback can return values from Callbacks return values |
mirrorfailurecb(userdata, msg, url)
Callback called when a transfer failed.
userdata: | User specified data or None |
---|---|
msg: | String with error message |
url: | String with mirror URL |
returns: | This callback can return values from Callbacks return values |
fastestmirrorcb(userdata, stage, data)
userdata: | User specified data or None |
---|---|
stage: | Fastest mirror stages |
data: | Content of data is different for different stages. See Fastest mirror stages |
returns: | This callback must return None each other value will be ignored. |
hmfcb(userdata, msg, url, metadata)
Callback called when a download of a metadata during perform() fails.
userdata: | User specified data or None |
---|---|
msg: | String with error message |
url: | String with mirror URL |
metadata: | String with metadata name (“primary”, “filelists”, ...) |
returns: | This callback can return values from Callbacks return values |
Each callback can safely return None (this is implicit return value when no return statement is defined).
return None is equivalent for return librepo.CB_OK.
Everything is OK
Abort just the current transfer. Note: If failfast option for the downloading is enabled, the whole downloading will be aborted.
Abort the whole downloading (all transfers). (Note: This code is automatically internally returned when an exception is raised in the callback.)
Convert string with name of hash function to numeric value that represents the hash in createrepo_c.
Parameters: | name – Checksum name (e.g. “sha256”, “sha512”, ...) |
---|---|
Returns: | Integer value (from Checksum (hash) type constants) |
Download list of packages. list is a list of PackageTarget objects. If the failfast is True, then whole downloading is stopped immediately when any of download fails (and exception is raised). If the failfast is False, then this function returns after all downloads finish (no matter if successfully or unsuccessfully) and exception is raised only if a nonrecoverable error related to the function itself is meet (Errors related to individual downloads are reported via corresponding PackageTarget objects)
Parameters: |
|
---|---|
Returns: | None |
Some tricky/unsafe stuff which can be useful during developing and debugging, but definitely shouldn’t be used in production.
Set a filename of a file where logs are going to be written.
Note: Only one file could be set at a time.
Note: If the LIBREPO_DEBUG environ variable is set and this function is used then the LIBREPO_DEBUG effect will be suppressed. (All debug output will be redirected to the specified file)
Parameters: | filename – Filename |
---|---|
Returns: | Id of the handler |
Remove handler.
Parameters: | handler_id – id |
---|
ONLY FOR DEVELOPMENT (DEBUGGING) PURPOSES!
(Deprecated, use log_set_file() instead)
When python debug log handler is used, the librepo is THREAD-UNSAFE!
If used, it overrides logging set by log_set_file() and vice versa.
Parameters: |
|
---|---|
Returns: | None |
Example:
def debug_function(msg, _):
print msg
librepo.set_debug_log_handler(debug_function)