#37 Modularity UI - Generate components and buildorder to yaml file
Merged 7 years ago by clime. Opened 7 years ago by frostyx.

@@ -749,6 +749,8 @@ 

      name = wtforms.StringField("Name")

      stream = wtforms.StringField("Stream")

      version = wtforms.IntegerField("Version")

+     builds = wtforms.FieldList(wtforms.StringField("Builds ID list"))

+     packages = wtforms.FieldList(wtforms.StringField("Packages list"))

      filter = wtforms.FieldList(wtforms.StringField("Package Filter"))

      api = wtforms.FieldList(wtforms.StringField("Module API"))

      profile_names = wtforms.FieldList(wtforms.StringField("Install Profiles"), min_entries=2)

@@ -801,6 +801,18 @@ 

      def filter_by_group_name(cls, query, group_name):

          return query.filter(models.Group.name == group_name)

  

+     @classmethod

+     def build_upstream_tuple(cls, build):

+         """

+         Return upstream SCM source tuple for given build

+         Returns: Tuple (url, ref)

+         """

+         if build.source_type == helpers.BuildSourceEnum("git_and_tito"):

+             return build.source_json_dict["git_url"], build.source_json_dict["git_branch"]

+         if build.source_type == helpers.BuildSourceEnum("mock_scm"):

+             return build.source_json_dict["scm_url"], build.source_json_dict["scm_branch"]

+         return None, None

+ 

  

  class BuildChrootsLogic(object):

      @classmethod

@@ -60,6 +60,13 @@ 

            </div>

          </div>

  

+ 

+         {% for package, build in built_packages %}

+           <input type="hidden" name="{{ 'packages-%s' |format(loop.index0) }}" value="{{ package }}">

+           <input type="hidden" name="{{ 'builds-%s' |format(loop.index0) }}" value="{{ build.id }}">

+         {% endfor %}

+ 

+ 

          {% set no_packages = 'No successfully built packages in this project yet' %}

  

          <div class="col-sm-4">
@@ -73,7 +80,7 @@ 

              <div class="panel-body">

  

                <label for="exampleInputEmail1">Packages <span class="text-muted">to be included:</span></label>

-               {% for package in packages %}

+               {% for package, build in built_packages %}

                <div class="checkbox">

                  <label>

                    {{ render_checkbox("filter-{}".format(loop.index0), package, (package in form.filter.data or not form.is_submitted())) }}
@@ -98,7 +105,7 @@ 

              <div class="panel-body">

                <div class="form-group">

                  <label>Packages <span class="text-muted">defining API:</span></label>

-                 {% for package in packages %}

+                 {% for package, build in built_packages %}

                  <div class="checkbox">

                    <label>

                      {{ render_checkbox("api-{}".format(loop.index0), package, (package in form.api.data)) }}
@@ -129,7 +136,7 @@ 

                  </div>

                  <div class="form-group">

                    <label for="exampleInputEmail1">Packages <span class="text-muted">installed by this profile:</span></label>

-                   {% for package in packages %}

+                   {% for package, build in built_packages %}

                    <div class="checkbox">

                      <label>

                        {{ render_checkbox("profile_pkgs-{}-{}".format(i, loop.index0), package, (package in form.profile_pkgs[i].data)) }}

@@ -929,12 +929,12 @@ 

  

  

  def render_create_module(copr, form, profiles=2):

-     packages = []

+     built_packages = []

      for build in filter(None, [p.last_build(successful=True) for p in copr.packages]):

          for package in build.built_packages.split("\n"):

-             packages.append(package.split()[0])

+             built_packages.append((package.split()[0], build))

  

-     return flask.render_template("coprs/create_module.html", copr=copr, form=form, packages=packages, profiles=profiles)

+     return flask.render_template("coprs/create_module.html", copr=copr, form=form, built_packages=built_packages, profiles=profiles)

  

  

  @coprs_ns.route("/<username>/<coprname>/create_module/", methods=["POST"])
@@ -984,6 +984,18 @@ 

          for package in packages:

              mmd.profiles[name].add_rpm(str(package))

  

+     build_ids = sorted(list(set([int(id) for p, id in zip(form.packages.data, form.builds.data)

+                                  if p in form.filter.data])))

+     for package in form.filter.data:

+         build_id = form.builds.data[form.packages.data.index(package)]

+         build = builds_logic.BuildsLogic.get_by_id(build_id).first()

+ 

+         upstream_url, upstream_ref = builds_logic.BuildsLogic.build_upstream_tuple(build)

+ 

+         mmd.components.add_rpm(str(package), "User selected the package as a part of the module",

+                                repository=str(upstream_url) or "", ref=str(upstream_ref) or "",

+                                buildorder=build_ids.index(int(build.id)))

+ 

      module = ModulesLogic.add(flask.g.user, copr, ModulesLogic.from_modulemd(mmd.dumps()))

      db.session.flush()

      actions_logic.ActionsLogic.send_build_module(flask.g.user, copr, module)

This PR updates our module generation UI. It fills the components and buildorder in yaml file. It looks like this

  components:
    rpms:
      hello: {buildorder: 1, rationale: User selected the package as a part of the
          module, ref: None, repository: None}
      hello-debuginfo: {buildorder: 1, rationale: User selected the package as a part
          of the module, ref: None, repository: None}
      python2-tracer: {rationale: User selected the package as a part of the module,
        ref: master, repository: 'https://github.com/FrostyX/tracer.git'}

This is kind of problematic. We cover Tito method quite well by this but MockSCM not very well as for MockSCM there is additional param "spec". And for Tito, there is "--test".

'ref' and 'repository' fields seem to be best suited for dist-git resource, which is, by the way, not included in our support currently.

Also, this would be nice thing to have tested at some point.

I will accept this PR now but we might be making some tweaks to this.

Anyway, thank you for the good work!

Pull-Request has been merged by clime

7 years ago