Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Helper to download jars from MAVEN (for Pig, Hadoop)
4"""
5import os
6import urllib
7import urllib.request
10def download_jar_from_maven(group, lib, version, location, overwrite=False):
11 """
12 download a jar file from maven
14 @param group group
15 @param lib lib name
16 @param version version
17 @param location location
18 @return filename
19 """
20 group = group.replace(".", "/")
21 url = "http://central.maven.org/maven2/{2}/{0}/{1}/{0}-{1}.jar".format(
22 lib,
23 version,
24 group)
25 final = os.path.join(location, "{0}-{1}.jar".format(lib, version))
27 if not os.path.exists(location):
28 raise FileNotFoundError(location)
30 if os.path.exists(final) and not overwrite:
31 return final
32 else:
33 try:
34 u = urllib.request.urlopen(url)
35 alls = u.read()
36 u.close()
37 except Exception as e:
38 raise FileNotFoundError(url) from e
40 with open(final, "wb") as f:
41 f.write(alls)
43 return final