import os
import sys
+import shutil
import argparse
import subprocess
from string import Template
sys.stderr.write("Else, install the Python libs it installs.\n")
raise
+import cache.cache as cache
import templates.build_debianfiles as build_debfiles
# Common paths used in this script
# This file is assumed to be in the root of the .deb build logic's dir structure
project_root = os.path.dirname(os.path.abspath(__file__))
+# Cache directory for OpenDaylight's release tarball
+cache_dir = os.path.join(project_root, "cache")
+
# Debian templates directory
templates_dir = os.path.join(project_root, "templates")
# Specialized opendaylight directory for each build
odl_dir_template = Template("opendaylight/opendaylight-$version_major.$version_minor."
"$version_patch-$pkg_version/")
+odl_deb_template = Template("opendaylight/opendaylight_$version_major.$version_minor."
+ "$version_patch-${pkg_version}_all.deb")
def build_deb(build):
:type build: dict
"""
+ # Specialize a series of name templates for the given build
odl_dir_name = odl_dir_template.substitute(build)
odl_dir_path = os.path.join(templates_dir, os.pardir, odl_dir_name)
+ odl_deb = odl_deb_template.substitute(build)
# Call helper script to build the required debian files
build_debfiles.build_debfiles(build)
+ # Call a helper function to cache the artifacts required for each build
+ odl_tarball_path = cache.cache_build(build)
+
+ # Move ODL's tarball to the specialized OpenDaylight directory
+ shutil.copy(odl_tarball_path, odl_dir_path)
+
# Build debian package
os.chdir(odl_dir_path)
subprocess.call(["dpkg-buildpackage", "-us -uc -b", odl_dir_path], shell=True)
os.chdir(project_root)
+ # Copy the .debs from their output dir to the cache dir
+ shutil.copy(odl_deb, cache_dir)
+
# When run as a script, accept a set of builds and execute them
if __name__ == "__main__":
--- /dev/null
+#!/usr/bin/env python
+"""Read YAML description of ODL builds and cache the required artifacts."""
+
+import sys
+import os
+import urllib
+
+try:
+ import yaml
+except ImportError:
+ sys.stderr.write("We recommend using our included Vagrant env.\n")
+ sys.stderr.write("Else, install the Python libs it installs.\n")
+ raise
+
+# Path to the directory that contains this file is assumed to be the cache dir
+cache_dir = os.path.dirname(os.path.abspath(__file__))
+
+
+def cache_build(build):
+ """Cache the artifacts required for the given debian build.
+
+ :param build: Description of an ODL build, typically from build_vars.yaml
+ :type build: dict
+
+ """
+ # OpenDaylight's tarball release name for the given build
+ odl_tarball = build["download_url"].split('/')[-1]
+
+ # After getting the string, build the tarball's full path
+ odl_tarball_path = os.path.join(cache_dir, odl_tarball)
+
+ # Cache appropriate version of OpenDaylight's release tarball
+ if not os.path.isfile(odl_tarball_path):
+ print("Downloading: {}".format(build["download_url"]))
+ urllib.urlretrieve(build["download_url"], odl_tarball_path)
+ print("Cached: {}".format(odl_tarball))
+ else:
+ print("Already cached: {}".format(odl_tarball))
+
+ return odl_tarball_path
+
+
+# If run as a script, cache artifacts required for all builds
+if __name__ == "__main__":
+ # Load debian build variables from a YAML config file
+ with open(os.path.join(cache_dir, os.pardir, "build_vars.yaml")) as var_fd:
+ build_vars = yaml.load(var_fd)
+ for build in build_vars["builds"]:
+ odl_tarball_path = cache_build(build)
"""Build debian files from YAML debian config and Jinja2 debian templates."""
import os
+import re
import sys
import shutil
import urllib
"$version_patch-$pkg_version/")
odl_deb_template = Template("opendaylight/opendaylight_$version_major.$version_minor."
"$version_patch-${pkg_version}_all.deb")
-odl_changes_template = Template("opendaylight/opendaylight_$version_major.$version_minor."
- "$version_patch-${pkg_version}_all.changes")
+odl_files_template = Template("opendaylight_$version_major.$version_minor."
+ "$version_patch-${pkg_version}*")
def build_debfiles(build):
:type build: dict
"""
+ # Specialize a series of name templates for the given build
odl_dir_name = odl_dir_template.substitute(build)
odl_dir_path = os.path.join(templates_dir, os.pardir, odl_dir_name)
if os.path.isfile(odl_deb_path):
os.remove(odl_deb_path)
- # Delete old .changes file if it exists
- odl_changes_name = odl_changes_template.substitute(build)
- odl_changes_path = os.path.join(templates_dir, os.pardir, odl_changes_name)
- if os.path.isfile(odl_changes_path):
- os.remove(odl_changes_path)
+ # Delete old .changes, .dsc, .tar.gz files if they exist
+ odl_files_regex = odl_files_template.substitute(build)
+ odl_par_dir = os.path.join(templates_dir, os.pardir, "opendaylight")
+ if os.path.isdir(odl_par_dir):
+ for f in os.listdir(odl_par_dir):
+ if re.search(odl_files_regex, f):
+ os.remove(os.path.join(odl_par_dir, f))
# Create debian directory
debian_dir_path = os.path.join(odl_dir_path, "debian")
urllib.urlretrieve(unitfile_url, unitfile_path)
-# If run as a script, build .spec files for all builds
+# If run as a script, build debian files for all builds
if __name__ == "__main__":
# Load debian build variables from a YAML config file
with open(os.path.join(templates_dir, os.pardir, "build_vars.yaml")) as var_fd: