| |
@@ -1,5 +1,8 @@
|
| |
+ import jinja2
|
| |
import sys
|
| |
import modulemd
|
| |
+ import pkg_resources
|
| |
+ import yaml
|
| |
import logging
|
| |
from . import _depchase, _repodata
|
| |
|
| |
@@ -18,12 +21,21 @@
|
| |
remaining_rpm_deps.add(pkgname)
|
| |
return module_deps, remaining_rpm_deps
|
| |
|
| |
+ def sortitems_filter(items):
|
| |
+ return sorted(items, key=lambda item: item[0])
|
| |
+
|
| |
+ def key_filter(obj):
|
| |
+ return yaml.dump({obj: 'x'}, default_flow_style=False).strip()[:-3]
|
| |
+ def value_filter(obj):
|
| |
+ return yaml.dump({'x': obj}, default_flow_style=False).strip()[3:]
|
| |
+
|
| |
class ModuleGenerator(object):
|
| |
|
| |
def __init__(self, pkgs):
|
| |
self.pkgs = pkgs
|
| |
self.core_srpm = None
|
| |
self.mmd = modulemd.ModuleMetadata()
|
| |
+ self.template = 'module.yaml.j2'
|
| |
self._pool = _depchase.make_pool("x86_64")
|
| |
|
| |
def _calculate_dependencies(self, build_deps_iterations):
|
| |
@@ -74,11 +86,19 @@
|
| |
Function writes modulemd to either stdout or the given filename
|
| |
:return:
|
| |
"""
|
| |
+
|
| |
+ env = jinja2.Environment(loader=jinja2.PackageLoader('_fedmod', 'templates'),
|
| |
+ autoescape=False)
|
| |
+ env.filters['sortitems'] = sortitems_filter
|
| |
+ env.filters['key'] = key_filter
|
| |
+ env.filters['value'] = value_filter
|
| |
+ template = env.get_template('module.yaml.j2')
|
| |
+
|
| |
if output_fname is not None:
|
| |
- self.mmd.dump(output_fname)
|
| |
+ template.stream(mmd=self.mmd).dump(output_fname)
|
| |
print('Generated modulemd file: %r' % output_fname)
|
| |
else:
|
| |
- print(self.mmd.dumps())
|
| |
+ print(template.render(mmd=self.mmd))
|
| |
return True
|
| |
|
| |
def _update_module_md(self):
|
| |
Instead of depending on modulemd functionality, format the output using
a Jinja2 template. While this is somewhat more cumbersome, it allows for
ordering and indenting the output as we want, and will allow comments
to be added in the future.
See: https://pagure.io/modularity/fedmod/issue/8