2 """Read YAML description of ODL builds and cache the required artifacts."""
11 sys.stderr.write("We recommend using our included Vagrant env.\n")
12 sys.stderr.write("Else, install the Python libs it installs.\n")
15 # Path to the directory that contains this file is assumed to be the cache dir
16 cache_dir = os.path.dirname(os.path.abspath(__file__))
19 def cache_build(build):
20 """Cache the artifacts required for the given debian build.
22 :param build: Description of an ODL build, typically from build_vars.yaml
26 # OpenDaylight's tarball release name for the given build
27 odl_tarball = build["download_url"].split('/')[-1]
29 # After getting the string, build the tarball's full path
30 odl_tarball_path = os.path.join(cache_dir, odl_tarball)
32 # Cache appropriate version of OpenDaylight's release tarball
33 if not os.path.isfile(odl_tarball_path):
34 print("Downloading: {}".format(build["download_url"]))
35 urllib.urlretrieve(build["download_url"], odl_tarball_path)
36 print("Cached: {}".format(odl_tarball))
38 print("Already cached: {}".format(odl_tarball))
40 return odl_tarball_path
43 # If run as a script, cache artifacts required for all builds
44 if __name__ == "__main__":
45 # Load debian build variables from a YAML config file
46 with open(os.path.join(cache_dir, os.pardir, "build_vars.yaml")) as var_fd:
47 build_vars = yaml.load(var_fd)
48 for build in build_vars["builds"]:
49 odl_tarball_path = cache_build(build)