File: verify_local_yum_metadata.py

package info (click to toggle)
librepo 1.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,028 kB
  • sloc: ansic: 18,802; python: 3,822; xml: 581; sh: 142; makefile: 64
file content (43 lines) | stat: -rwxr-xr-x 1,190 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3

"""
Example: Verify checksum of local metadata

Use case:
We have some incomplete metadata localy.
They are incomplete because they doesn't
contain all files specified in repomd.xml.
They contains only primary.xml and filelists.xml.
We want to check checksum of this metadata.
"""

import sys
import librepo

METADATA_PATH = "downloaded_metadata"

if __name__ == "__main__":
    h = librepo.Handle()
    r = librepo.Result()
    # Repository with repodata in the rpm-md format
    h.setopt(librepo.LRO_REPOTYPE, librepo.LR_YUMREPO)
    # Path to the metadata
    h.setopt(librepo.LRO_URLS, [METADATA_PATH])
    # Do not duplicate (copy) the metadata
    h.setopt(librepo.LRO_LOCAL, True)
    # Check checksum of metadata
    h.setopt(librepo.LRO_CHECKSUM, True)
    # Ignore missing metadata files
    h.setopt(librepo.LRO_IGNOREMISSING, True)

    try:
        h.perform(r)
    except librepo.LibrepoException as e:
        rc, msg, general_msg = e
        if rc == librepo.LRE_BADCHECKSUM:
            print("Corrupted metadata! ({})".format(msg))
        else:
            print("Other error: {}".format(msg))
        sys.exit(1)

    print("Metadata are fine!")