1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6import os 

7from pyrocko import util 

8import logging 

9 

10 

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

12 

13 

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

15 ''' 

16 Download example data file needed in tutorials. 

17 

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

19 file with that name, nothing is done. 

20 

21 :param filename: name of the required file 

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

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

24 :returns: ``filename`` 

25 ''' 

26 

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

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

29 if recursive: 

30 util.download_dir(url, filename) 

31 else: 

32 util.download_file(url, filename) 

33 

34 return filename