File: download_packages_with_fastestmirror.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 (60 lines) | stat: -rwxr-xr-x 1,645 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3

"""
librepo - download packages
"""

import os
import os.path
import time
import librepo

CACHE = "fastestmirror.cache"

LIBREPOPKG = "librepo-1.2.1-2.fc20.x86_64.rpm"
LAMEPKG = "lame-3.99.5-2.fc19.x86_64.rpm"

if __name__ == "__main__":

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

    # Remove packages if already exists
    def remove_pkg(filename):
        if os.path.exists(filename):
            os.remove(filename)
    remove_pkg(LIBREPOPKG)
    remove_pkg(LAMEPKG)

    # Prepare list of targets
    packages = []

    # Prepare first target
    h1 = librepo.Handle()
    h1.metalinkurl = "https://mirrors.fedoraproject.org/metalink?repo=fedora-20&arch=x86_64"
    h1.repotype = librepo.YUMREPO
    h1.fastestmirror = True
    h1.fastestmirrorcache = CACHE
    target = librepo.PackageTarget("Packages/l/"+LIBREPOPKG, handle=h1)
    packages.append(target)

    # Prepare second target
    h2 = librepo.Handle()
    h2.mirrorlisturl = "http://mirrors.rpmfusion.org/mirrorlist?repo=free-fedora-19&arch=x86_64"
    h2.repotype = librepo.YUMREPO
    h2.fastestmirror = True
    h2.fastestmirrorcache = CACHE
    target = librepo.PackageTarget(LAMEPKG, handle=h2)
    packages.append(target)

    t = time.time()
    librepo.download_packages(packages)
    print("Download duration: {0}s\n".format((time.time() - t)))

    for target in packages:
        print("### %s: %s" % (target.local_path, target.err or "OK"))
        print("Local path:        ", target.local_path)
        print("Error:             ", target.err)
        print()