File: download_file.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 (36 lines) | stat: -rwxr-xr-x 906 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
#!/usr/bin/env python3

"""
librepo - download a file
"""

import os
import sys
import shutil

import librepo

URL = "http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f20&arch=x86_64"
DEST_FN_1 = "downloaded_mirrorlist_1.txt"
DEST_FN_2 = "downloaded_mirrorlist_2.txt"

def download_1():
    """Example of the simplest usage"""
    fd = os.open(DEST_FN_1, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0o0666)
    librepo.download_url(URL, fd)

def download_2():
    """Handle could be used if you need specify some network
    options like proxy server etc."""

    # NOTE: LRO_URLS and LRO_MIRRORLIST options of the handle are ignored!!

    h = librepo.Handle()
    #h.setopt(librepo.LRO_PROXY, "http://foo.proxy.bar:8080")

    fd = os.open(DEST_FN_2, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0o0666)
    librepo.download_url(URL, fd, handle=h)

if __name__ == "__main__":
    download_1()
    download_2()