2 """Build RPM .spec files from build description and a Jinja2 .spec template."""
5 from string import Template
9 from jinja2 import Environment, FileSystemLoader
11 sys.stderr.write("We recommend using our included Vagrant env.\n")
12 sys.stderr.write("Else, do `pip install -r requirements.txt` in a venv.\n")
15 # Path to the directory that contains this file is assumed to be the spec dir
16 spec_dir = os.path.dirname(os.path.abspath(__file__))
18 # Create the Jinja2 Environment
19 env = Environment(loader=FileSystemLoader(spec_dir))
21 # Load the OpenDaylight RPM .spec file Jinja2 template
22 template = env.get_template("opendaylight.spec")
24 # Python string Template, specialized into a specfile file name per-build
25 specfile_template = Template("opendaylight-$version_major.$version_minor."
26 "$version_patch-$pkg_version.spec")
29 def build_spec(build):
30 """Build the RPM .spec file from a template for the given build description.
32 :param build: Description of an RPM build
36 specfile_name = specfile_template.substitute(build)
37 specfile_path = os.path.join(spec_dir, specfile_name)
38 with open(specfile_path, "w") as specfile:
39 specfile.write(template.render(build))