Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/example.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Example data download helpers. 

8''' 

9 

10import os 

11from pyrocko import util 

12import logging 

13 

14 

15logger = logging.getLogger('pyrocko.example') 

16 

17 

18def get_example_data(filename, url=None, recursive=False): 

19 ''' 

20 Download example data file needed in tutorials. 

21 

22 The file is downloaded to given ``filename``. If there already exists a 

23 file with that name, nothing is done. 

24 

25 :param filename: name of the required file 

26 :param url: if not ``None`` get file from given URL otherwise fetch it from 

27 http://data.pyrocko.org/examples/<filename>. 

28 :returns: ``filename`` 

29 ''' 

30 

31 if not os.path.exists(filename): 

32 url = 'http://data.pyrocko.org/examples/' + filename 

33 if recursive: 

34 util.download_dir(url, filename) 

35 else: 

36 util.download_file(url, filename) 

37 

38 return filename