[netcore] Fix WaitHandle.SignalAndWait (#13809)
[mono-project.git] / netcore / dl-test-assets.py
blob8d902e835fc0de6428d6e16df7365a65962d071b
1 #!/usr/bin/env python
3 import sys
4 import os
5 import subprocess
6 import xml.etree.ElementTree as ET
7 import zipfile
8 import urllib
9 import multiprocessing
11 if len(sys.argv) < 4:
12 print("Usage: dl-test-assets.py <path to assets.xml> <base url> <output dir>")
13 sys.exit(1)
15 infile_name = sys.argv [1]
16 base_url = sys.argv [2]
17 outdir = sys.argv [3]
18 tree = ET.parse(infile_name)
19 root = tree.getroot()
21 if not os.path.exists(outdir):
22 os.makedirs(outdir)
24 def downloadAsset(elem):
25 if elem.tag != "Blob":
26 return
27 id = elem.attrib ["Id"]
28 filename = os.path.basename(id)
29 print "Downloading " + filename
30 try:
31 name, hdrs = urllib.urlretrieve(base_url + "/" + id, outdir + "/" + filename)
32 except IOError, e:
33 print ("Download failed for " + id)
34 sys.exit (1)
35 print "Extracting " + filename
36 with zipfile.ZipFile(outdir + "/" + filename) as zf:
37 zf.extractall(outdir + "/extracted/" + filename[:-4])
39 pool = multiprocessing.Pool(multiprocessing.cpu_count())
40 results = pool.map(downloadAsset, root)
41 pool.close()
42 pool.join()