# The Librepo Library

## Classes

Librepo includes several classes:

- Handle (librepo.Handle)
  - `Handle`
    - `Handle.httpauthmethods`
    - `Handle.proxyauthmethods`
    - `Handle.ftpuseepsv`
    - `Handle.preservetime`
    - `Handle.download()`
    - `Handle.getinfo()`
    - `Handle.new_packagetarget()`
    - `Handle.perform()`
    - `Handle.setopt()`
- Result (librepo.Result)
  - `Result`
    - `Result.rpmmd_repo`
    - `Result.yum_repo`
    - `Result.rpmmd_repomd`
    - `Result.yum_repomd`
    - `Result.rpmmd_timestamp`
    - `Result.yum_timestamp`
    - `Result.getinfo()`
- PackageTarget (librepo.PackageTarget)
  - `PackageTarget`

## Exceptions

Librepo module has only one own exception.

class LibrepoException

Value of this exception is tuple with three elements: `(return code, error message, general error message)`

- Return code is a value from: Error codes.

- String with a descriptive description of the error.

- General error message based on rc (feel free to ignore this message)

## Constants

### Version contants

librepo.VERSION_MAJOR
librepo.VERSION_MINOR
librepo.VERSION_PATCH
librepo.VERSION

  Constants with version numbers and whole version string.

### `Handle` options

> 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.

librepo.LRO_UPDATE

  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).

librepo.LRO_URLS

  List or None. Set repository urls (repository url and baseurl are interchangeable terms in this context).

librepo.LRO_MIRRORLIST

  String or None. DEPRECATED Set mirrorlist url (url could point to a metalink mirrorlist or to a simple mirrorlist where each line without `'#'` is considered as mirror url).

librepo.LRO_MIRRORLISTURL

  String or None. Mirrorlist URL.

librepo.LRO_METALINKURL

  String or None. Metalink URL.

librepo.LRO_LOCAL

  Boolean. If set to True, no local copy of repository is created and repository is just localized in its current location. When True, url of repository MUST be a local address (e.g. ‘/home/user/repo’ or ‘file:///home/user/repo’).

librepo.LRO_HTTPAUTH

  Boolean. If True, all supported methods of HTTP authentication are enabled.

librepo.LRO_USERPWD

  String or None. Set username and password for HTTP authentication. Param must be in format ‘username:password’. The user and password strings are not URL decoded, so there is no way to send in a username containing a colon using this option. The option is DEPRECATED! Use LRO_USERNAME and LRO_PASSWORD.

librepo.LRO_USERNAME

  String or None. Set username for HTTP authentication.

librepo.LRO_PASSWORD

  String or None. Set password for HTTP authentication.

librepo.LRO_PROXY

  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.

librepo.LRO_PROXYPORT

  Integer or None. Set proxy port number to connect unless it is specified in the proxy address string. None sets default value 1080.

librepo.LRO_PROXYTYPE

  Long. Set type of proxy - could be one of Proxy type constants

librepo.LRO_PROXYAUTH

  Boolean. If True, all supported proxy authentication methods are enabled. If False, only basic authentication method is enabled.

librepo.LRO_PROXYUSERPWD

  String or None. Set username and password for proxy authentication in format ‘username:password’. Both the username and the password are URL decoded before use, so if the username contains, for example, a colon, it should be encoded as %3A.

librepo.LRO_PROGRESSCB

  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).

librepo.LRO_PROGRESSDATA

  Any object. Set user data for the progress callback.

librepo.LRO_MAXSPEED

  Long or None. Set maximal allowed speed per download in bytes per second. 0 = unlimited speed - the default value.

librepo.LRO_DESTDIR

  String or None. Set destination directory for downloaded data (metadata or packages).

librepo.LRO_REPOTYPE

  Integer. One of Repo type constants. See more `repotype()` Set type of repository.

librepo.LRO_CONNECTTIMEOUT

  Integer or None. Set maximal timeout in sec for connection phase. Default value is 30. None as *val sets the default value.

librepo.LRO_IGNOREMISSING

  Boolean. If you want to localize (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.

librepo.LRO_INTERRUPTIBLE

  Boolean. Librepo sets up its own SIGTERM handler. If the SIGTERM signal is catched, the current download is interrupted.

librepo.LRO_USERAGENT

  String. String for User-Agent: header in the http request sent to the remote server.

librepo.LRO_FETCHMIRRORS

  Boolean. With this option enabled, only mirrorlist download and parsing will be performed during `librepo.Handle.perform()`.

librepo.LRO_MAXMIRRORTRIES

  Integer or None. If download fails, try at most the specified number of mirrors. 0 (None) means try all available mirrors.

librepo.LRO_MAXPARALLELDOWNLOADS

  Integer or None. Maximum number of parallel downloads. `None` sets default value.

librepo.LRO_MAXDOWNLOADSPERMIRROR

  Integer or None. Maximum number of parallel downloads per mirror. `None` sets default value.

librepo.LRO_VARSUB

  [(String, String), …] or None. Set list of substitutions for variables in ulrs (e.g.: “http://foo/$version/”). `[("releasever", "f18"), ("basearch", "i386")]`

librepo.LRO_FASTESTMIRROR

  Boolean. If True, internal mirrorlist is sorted by the determined connection speed, after it is constructed.

librepo.LRO_FASTESTMIRRORCACHE

  String or None. Path to the cache file. If cache file it doesn’t exists it will be created.

librepo.LRO_FASTESTMIRRORMAXAGE

  Integer or None. Max age of cache record. Older records will not be used.

librepo.LRO_FASTESTMIRRORCB

  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.

librepo.LRO_FASTESTMIRRORDATA

  Any object. User data for fastest mirror status callback.

librepo.LRO_LOWSPEEDTIME

  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: 30 (sec)

librepo.LRO_LOWSPEEDLIMIT

  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)

librepo.LRO_GPGCHECK

  Boolean. Set True to enable gpg check (if available) of downloaded repo.

librepo.LRO_CHECKSUM

  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!

librepo.LRO_YUMDLIST

  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.

librepo.LRO_YUMSLIST

  [(String, String), …] or None. Set list of substitutions for repomd records. ``[(“group_gz”, “group”)]`

librepo.LRO_RPMMDDLIST

  See LRO_YUMDLIST

librepo.LRO_YUMBLIST

  List of strings. Set skiplist of yum metadata files. This files will not be downloaded.

librepo.LRO_RPMMDBLIST

  See LRO_YUMBLIST

librepo.LRO_HMFCB

  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.

librepo.LRO_SSLVERIFYPEER

  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.

librepo.LRO_SSLVERIFYSTATUS

  Boolean. This option determines whether librepo verifies the status of the server cert using the ‘Certificate Status Request’ TLS extension (aka. OCSP stapling). Note that if this option is enabled but the server does not support the TLS extension, the verification will fail. */

librepo.LRO_SSLVERIFYHOST

  Boolean. This option determines whether librepo verifies that the server cert is for the server it is known as.

librepo.LRO_SSLCLIENTCERT

  String or None. Path to the PEM format SSL client certificate to use when talking to the server.

librepo.LRO_SSLCLIENTKEY

  String or None. Path to the PEM format SSL client key to use when talking to the server.

librepo.LRO_SSLCACERT

  String or None. Path to a file containing the list of PEM format trusted CA certificates.

librepo.LRO_PROXY_SSLVERIFYPEER

  Boolean. This option determines whether librepo verifies the authenticity of the proxy certificate. This trust is based on a chain of digital signatures, rooted in certification authority (CA) certificates.

librepo.LRO_PROXY_SSLVERIFYHOST

  Boolean. This option determines whether librepo verifies the name of the proxy certificate against the host.

librepo.LRO_PROXY_SSLCLIENTCERT

  String or None. Path to the PEM format SSL client certificate to use when talking to the proxy.

librepo.LRO_PROXY_SSLCLIENTKEY

  String or None. Path to the PEM format SSL client key to use when talking to the proxy.

librepo.LRO_PROXY_SSLCACERT

  String or None. Path to a file containing the list of PEM format trusted CA certificates. Used for proxy.

librepo.LRO_IPRESOLVE

  Integer or None Sets kind of IP addresses to use when resolving host names. Could be one of: Supported IP resolving

librepo.LRO_ALLOWEDMIRRORFAILURES

  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.

librepo.LRO_ADAPTIVEMIRRORSORTING

  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.

librepo.LRO_GNUPGHOMEDIR

  String or None set own GNUPG configuration directory (a dir with keyring).

librepo.LRO_FASTESTMIRRORTIMEOUT

  Float of None Max length of fastest mirror measurement in seconds. Default value is 2.0sec.

librepo.LRO_HTTPHEADER

  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!

librepo.LRO_OFFLINE

  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.

librepo.LRO_HTTPAUTHMETHODS

  Long (bitmask) Bitmask which tell Librepo which auth methods to use. See: Auth methods

librepo.LRO_PROXYAUTHMETHODS

  Long (bitmask) Bitmask which tell Librepo which auth methods to use for proxy authentication. See: Auth methods

librepo.LRO_FTPUSEEPSV

  Boolean Enable/Disable EPSV (Extended Passive mode) for FTP.

librepo.LRO_PRESERVETIME

  Boolean If enabled, librepo will try to keep timestamps of the downloaded files in sync with that on the remote side.

### `Handle` info options

> LRI (aka LibRepo Information) constants are used to get information from `Handle` via `getinfo()` method.

librepo.LRI_UPDATE

librepo.LRI_URLS

librepo.LRI_MIRRORLIST

librepo.LRI_MIRRORLISTURL

librepo.LRI_METALINKURL

librepo.LRI_LOCAL

librepo.LRI_PROGRESSCB

librepo.LRI_PROGRESSDATA

librepo.LRI_DESTDIR

librepo.LRI_REPOTYPE

librepo.LRI_USERAGENT

librepo.LRI_YUMDLIST

librepo.LRI_YUMSLIST

librepo.LRI_RPMMDDLIST

librepo.LRI_YUMBLIST

librepo.LRI_RPMMDBLIST

librepo.LRI_FETCHMIRRORS

librepo.LRI_MAXMIRRORTRIES

librepo.LRI_VARSUB

librepo.LRI_MIRRORS

librepo.LRI_METALINK

librepo.LRI_FASTESTMIRROR

librepo.LRI_FASTESTMIRRORCACHE

librepo.LRI_FASTESTMIRRORMAXAGE

librepo.LRI_HMFCB

librepo.LRI_SSLVERIFYPEER

librepo.LRI_SSLVERIFYSTATUS

librepo.LRI_SSLVERIFYHOST

librepo.LRI_SSLCLIENTCERT

librepo.LRI_SSLCLIENTKEY

librepo.LRI_SSLCACERT

librepo.LRI_PROXY_SSLVERIFYPEER

librepo.LRI_PROXY_SSLVERIFYHOST

librepo.LRI_PROXY_SSLCLIENTCERT

librepo.LRI_PROXY_SSLCLIENTKEY

librepo.LRI_PROXY_SSLCACERT

librepo.LRI_IPRESOLVE

librepo.LRI_ALLOWEDMIRRORFAILURES

librepo.LRI_ADAPTIVEMIRRORSORTING

librepo.LRI_GNUPGHOMEDIR

librepo.LRI_FASTESTMIRRORTIMEOUT

librepo.LRI_HTTPHEADER

librepo.LRI_OFFLINE

librepo.LRI_HTTPAUTHMETHODS

librepo.LRI_PROXYAUTHMETHODS

librepo.LRI_FTPUSEEPSV

### Proxy type constants

librepo.PROXY_HTTP(LR_PROXY_HTTP)

librepo.PROXY_HTTP_1_0(LR_PROXY_HTTP_1_0)

librepo.PROXY_SOCKS4(LR_PROXY_SOCKS4)

librepo.PROXY_SOCKS5(LR_PROXY_SOCKS5)

librepo.PROXY_SOCKS4A(LR_PROXY_SOCKS4A)

librepo.PROXY_SOCKS5_HOSTNAME(LR_PROXY_SOCKS5_HOSTNAME)

### Supported IP resolving

librepo.IPRESOLVE_WHATEVER

  Default value, resolves addresses to all IP versions that your system allows.

librepo.IPRESOLVE_V4

  Resolve to IPv4 addresses.

librepo.IPRESOLVE_V6

  Resolve to IPv6 addresses.

### Repo type constants

librepo.RPMMDREPO(LR_RPMMDREPO)

  Classical repository in repo-md format with `repodata/` directory.

librepo.YUMREPO(LR_YUMREPO)

  See RPMMDREPO

librepo.SUSEREPO(LR_SUSEREPO)

  YaST2 repository (http://en.opensuse.org/openSUSE:Standards_YaST2_Repository_Metadata_content).

  Note

  This option is not supported yet!

librepo.DEBREPO(LR_DEBREPO)

  Debian repository

  Note

  This option is not supported yet!

### Predefined yumdlist lists

librepo.RPMMD_FULL(YUM_FULL, LR_YUM_FULL)

  Download all repodata files

librepo.RPMMD_REPOMDONLY(YUM_REPOMDONLY, LR_YUM_REPOMDONLY)

  Download only repomd.xml file

librepo.RPMMD_BASEXML(YUM_BASEXML, LR_YUM_BASEXML)

  Download only primary.xml, filelists.xml and other.xml

librepo.RPMMD_BASEDB(YUM_BASEDB, LR_YUM_BASEDB)

  Download only primary, filelists and other databases.

librepo.RPMMD_HAWKEY(YUM_HAWKEY, LR_YUM_HAWKEY)

  Download only files used by Hawkey (https://github.com/akozumpl/hawkey/). (primary, filelists, prestodelta)

### Auth methods

Supported auth methods for `LRO_HTTPAUTHMETHODS` and `LRO_PROXYAUTHMETHODS` options.

librepo.LR_AUTH_NONE

  No auth method enabled.

librepo.LR_AUTH_BASIC

  HTTP Basic authentication (Default).

librepo.LR_AUTH_DIGEST

  HTTP Digest authentication.

librepo.LR_AUTH_NEGOTIATE

  HTTP Negotiate (SPNEGO) authentication.

librepo.LR_AUTH_NTLM

  HTTP NTLM authentication.

librepo.LR_AUTH_DIGEST_IE

  HTTP Digest authentication with an IE flavor.

librepo.LR_AUTH_NTLM_WB

  NTLM delegating to winbind helper.

librepo.LR_AUTH_ONLY

  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.

librepo.LR_AUTH_ANY

  All suitable methods.

### Fastest mirror stages

Values used by fastest mirror callback (`LRO_FASTESTMIRRORCB`):

librepo.FMSTAGE_INIT

  0. Fastest mirror detection just started. data is None.

librepo.FMSTAGE_CACHELOADING

  1. Cache file is specified. data is path to the cache file.

librepo.FMSTAGE_CACHELOADINGSTATUS

  2. Cache loading finished. If successful, data is None, otherwise data is string with error message.

librepo.FMSTAGE_DETECTION

  (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.FMSTAGE_FINISHING

  4. Detection is done, sorting mirrors, updating cache, etc. data is None.

librepo.FMSTAGE_STATUS

  5. The very last invocation of fastest mirror callback. If fastest mirror detection was successful data, otherwise data contain string with error message.

### Error codes

LibRepo Error codes.

librepo.LRE_OK

  0. Everything is ok.

librepo.LRE_BADFUNCARG

  1. Bad function argument(s).

librepo.LRE_BADOPTARG

  2. Bad argument for the option in `setopt()`.

librepo.LRE_UNKNOWNOPT

  3. Unknown option.

librepo.LRE_CURLSETOPT

  4. cURL doesn’t know an option used by librepo. Probably too old cURL version is used.

librepo.LRE_ALREADYUSEDRESULT

  5. `Result` object is not “clean” (it has been already used).

librepo.LRE_INCOMPLETERESULT

  6. `Result` object doesn’t contain all what is needed.

librepo.LRE_CURLDUP

  7. Cannot duplicate cURL handle. No free memory?

librepo.LRE_CURL

  8. A cURL error.

librepo.LRE_CURLM

  9. A multi cURL handle error.

librepo.LRE_BADSTATUS

  10. Error HTTP or FTP status code.

librepo.LRE_TEMPORARYERR

  11. An error that should be temporary (e.g. HTTP status codes 500, 502-504, ..)

librepo.LRE_NOTLOCAL

  12. URL is not a local address.

  > E.g. in case when `LRO_UPDATE` option is `True` and URL is a remote address.

librepo.LRE_CANNOTCREATEDIR

  13. Cannot create directory for downloaded data. Bad permission?

librepo.LRE_IO

  14. Input/Output error.

librepo.LRE_MLBAD

  15. Bad mirrorlist or metalink file. E.g. metalink doesn’t contain

  > reference to target file (repomd.xml), mirrorlist is empty, ..

librepo.LRE_MLXML

  16. Cannot parse metalink xml. Non-valid metalink file?

  > E.g. (metalink doesn’t contain needed file, mirrorlist doesn’t contain urls, ..)

librepo.LRE_BADCHECKSUM

  17. Bad checksum.

librepo.LRE_REPOMDXML

  18. Cannot parse repomd.xml file. Non-valid repomd.xml file?

librepo.LRE_NOURL

  19. No usable URL found. E.g. bad links or no links in metalink.

librepo.LRE_CANNOTCREATETMP

  20. Cannot create temporary directory.

librepo.LRE_UNKNOWNCHECKSUM

  21. Unknown type of checksum is needed for verification of one

  > or more files.

librepo.LRE_BADURL

  22. Bad URL specified.

librepo.LRE_GPGNOTSUPPORTED

  23. OpenPGP protocol is not supported.

librepo.LRE_GPGERROR

  24. GPG error.

librepo.LRE_BADGPG

  25. Bad GPG signature.

librepo.LRE_INCOMPLETEREPO

  26. Repository metadata are not complete.

librepo.LRE_INTERRUPTED

  27. Download was interrupted by SIGTERM signal.

librepo.LRE_SIGACTION

  28. Sigaction system call failed.

librepo.LRE_ALREADYDOWNLOADED

  29. The file is already downloaded and its checksum matches.

librepo.LRE_UNFINISHED

  30. Download wasn’t (or cannot be) finished.

librepo.LRE_SELECT

  31. select() call failed.

librepo.LRE_OPENSSL

  32. OpenSSL library related error.

librepo.LRE_MEMORY

  33. Cannot allocate more memory.

librepo.LRE_XMLPARSER

  34. XML parser error.

librepo.LRE_CBINTERRUPTED

  35. Interrupted by user cb.

librepo.LRE_UNKNOWNERROR

  An unknown error.

### `Result` options

LibRepo Result options for use in `getinfo()` method.

librepo.LRR_YUM_REPO(deprecated - use LRR_RPMMD_REPO instead)

  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',
      }

librepo.LRR_RPMMD_REPO

  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'}
      }

librepo.LRR_YUM_REPOMD(deprecated - use LRR_RPMMD_REPOMD instead)

  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},
      }

librepo.LRR_RPMMD_REPOMD

  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},
      }

librepo.LRR_RPMMD_TIMESTAMP(LRR_YUM_TIMESTAMP)

  Returns the highest timestamp from all records in the repomd. See: http://yum.baseurl.org/gitweb?p=yum.git;a=commitdiff;h=59d3d67f

### Transfer statuses for endcb of `PackageTarget`

librepo.TRANSFER_SUCCESSFUL

librepo.TRANSFER_ALREADYEXISTS

librepo.TRANSFER_ERROR

### Callbacks prototypes

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.

### Progress callback - progresscb

`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

### End callback - endcb

`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

### Mirror Failure Callback - mirrorfailurecb

`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

### Fastestmirror callback - fastestmirrorcb

`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.

### Handle Mirror Failure Callback - hmfcb

`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

### 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`.

librepo.CB_OK

  Everything is OK

librepo.CB_ABORT

  Abort just the current transfer. Note: If failfast option for the downloading is enabled, the whole downloading will be aborted.

librepo.CB_ERROR

  Abort the whole downloading (all transfers). (Note: This code is automatically internally returned when an exception is raised in the callback.)

### Checksum (hash) type constants

librepo.MD5(CHECKSUM_MD5)

librepo.SHA1(CHECKSUM_SHA1)

librepo.SHA224(CHECKSUM_SHA224)

librepo.SHA256(CHECKSUM_SHA256)

librepo.SHA384(CHECKSUM_SHA384)

librepo.SHA512(CHECKSUM_SHA512)

## Functions

librepo.checksum_str_to_type(name)

  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)

librepo.download_packages(list, failfast=False)

  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:

    - list – List of `PackageTarget` objects.

    - failfast – If True, stop whole downloading immediately when any of downloads fails. If False, ignore failed download(s) and continue with other downloads.

  Returns:

    None

librepo.download_url(url, fd, handle=None)

  Download specified URL and write it content to opened file descriptor.

  Parameters:

    - url – Target URL

    - fd – Opened file descriptor (To get a file descriptor use for example os.open().

    - handle – `Handle` object or None

  Returns:

    None

librepo.yum_repomd_get_age(result_object)

  Get the highest timestamp of the repo’s repomd.xml.

  Parameters:

    result_object – Used (filled) `Result`

  Returns:

    The highest timestamp from repomd (Float) or 0.0 on error.

## Debugging

Some tricky/unsafe stuff which can be useful during developing and debugging, but definitely shouldn’t be used in production.

librepo.log_set_file(filename)

  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

librepo.log_remove_handler(handler_id)

  Remove handler.

  Parameters:

    handler_id – id

librepo.set_debug_log_handler(log_function, user_data=None)

  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:

    - log_function – Function that will handle the debug messages.

    - user_data – An data you want to be passed to the log_function during call.

  Returns:

    None

  Example:

      def debug_function(msg, _):
          print(msg)
      librepo.set_debug_log_handler(debug_function)