File: read_metalink_of_downloaded_repo.py

package info (click to toggle)
librepo 1.12.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,976 kB
  • sloc: ansic: 17,443; python: 3,721; xml: 581; sh: 113; makefile: 64
file content (40 lines) | stat: -rwxr-xr-x 1,050 bytes parent folder | download
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
#!/usr/bin/python

"""
librepo - example of usage
"""

import os
import sys
import librepo
import pprint

DESTDIR = "downloaded_metadata"

if __name__ == "__main__":
    h = librepo.Handle()
    r = librepo.Result()

    # Correct repotype is important. Without repotype
    # metalink parser doesn't know suffix which should
    # be stripped off from the mirrors urls.
    h.setopt(librepo.LRO_REPOTYPE, librepo.LR_YUMREPO)

    # Set local mirrorlist file as mirrorlist
    if os.path.isfile(os.path.join(DESTDIR, "mirrorlist")):
        h.mirrorlist = os.path.join(DESTDIR, "mirrorlist")
    elif os.path.isfile(os.path.join(DESTDIR, "metalink.xml")):
        h.mirrorlist = os.path.join(DESTDIR, "metalink.xml")
    else:
        print "No mirrorlist of downloaded repodata available"
        sys.exit(0)

    # Download only the mirrorlist during perform() call.
    h.setopt(librepo.LRO_FETCHMIRRORS, True)

    h.perform(r)

    print "Urls in mirrorlist:"
    print h.mirrors
    print "Metalink file content:"
    pprint.pprint(h.metalink)