File: download.py

package info (click to toggle)
python3-dmm 0.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: python: 441; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (2)
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
"""
download remote content for dmm
"""

import os
import pathlib

def init():
    """
    Initialization for download module
    """


def recipe_run(config, globalconf):
    """
    Perform actions for download module
    """
    if config['action'] == 'download_files':
        for download in config['files']:
            download_file(download['url'], download['destination'])


def download_file(url, destination):
    """
    Download file using curl and store it at location
    """
    print("Downloading %s to %s" % (url, destination))
    # Ensure that base path exists
    path = pathlib.Path(destination).parent
    path.mkdir(parents=True, exist_ok=True)
    os.system("curl %s -o %s" % (url, destination))


init()