Rationale behind this is that maintainers
are mainly interested in packages currently
used in the distribution (tagged ones).
Closes #197.
Signed-off-by: Richard Marko <rmarko(a)redhat.com>
---
pyfaf/hub/problems/views.py | 15 +++++++++------
pyfaf/hub/templates/package_table.html | 33 +++++++++++++++++++++++++++++++++
pyfaf/hub/templates/problems/item.html | 4 ++--
pyfaf/storage/opsys.py | 19 +++++++++++++++++++
4 files changed, 63 insertions(+), 8 deletions(-)
create mode 100644 pyfaf/hub/templates/package_table.html
diff --git a/pyfaf/hub/problems/views.py b/pyfaf/hub/problems/views.py
index 4009c4f..8b23c18 100644
--- a/pyfaf/hub/problems/views.py
+++ b/pyfaf/hub/problems/views.py
@@ -124,18 +124,21 @@ def item(request, **kwargs):
.group_by(ReportPackage.installed_package_id)
.order_by(sql.expression.desc('cnt'))
.subquery())
- packages = [(pkg.nevr(), cnt) for (pkg, cnt) in
- db.session.query(Package, sub.c.cnt).join(sub).all()]
+
+ packages = db.session.query(Package, sub.c.cnt).join(sub).all()
# merge packages with different architectures
merged = dict()
for package, count in packages:
- if package in merged:
- merged[package] += count
+ key = package.nevr()
+ if key in merged:
+ merged[key] = (package, merged[key][1] + count)
else:
- merged[package] = count
+ merged[key] = (package, count)
- packages = merged
+ # sort by tag first, count second
+ sort_key = lambda (package, count): (package.build.newest_tag_name, count)
+ packages = sorted(merged.values(), key=sort_key, reverse=True)
forward = { 'problem': problem,
'osreleases': osreleases,
diff --git a/pyfaf/hub/templates/package_table.html
b/pyfaf/hub/templates/package_table.html
new file mode 100644
index 0000000..f83d763
--- /dev/null
+++ b/pyfaf/hub/templates/package_table.html
@@ -0,0 +1,33 @@
+{% load custom_filters %}
+
+{% if data %}
+ <table class="table table-striped table-bordered metric">
+ <tr>
+ <th>Name</th>
+ <th>Version</th>
+ <th>Tag</th>
+ <th>Count</th>
+ </tr>
+ {% for package, cnt in data %}
+ <tr
+ {% if forloop.counter > row_limit and data|length > row_limit|add:1 %} {#
avoid +1 more #}
+ class='hide'
+ {% endif %}
+ >
+ <td>{{ package.name }}</td>
+ <td>{{ package.nevr }}</td>
+ <td>{{ package.build.newest_tag_name }}</td>
+ <td>{{ cnt }}</td>
+ </tr>
+ {% if data|length > row_limit|add:1 and forloop.counter = row_limit %}
+ <tr>
+ <td colspan='4'>
+ <button class="btn btn-mini btn-more"
type="button">
+ + {{ data|length|substract:row_limit }} more
+ </button>
+ </td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
+{% endif %}
diff --git a/pyfaf/hub/templates/problems/item.html
b/pyfaf/hub/templates/problems/item.html
index 710b1c3..3a66837 100644
--- a/pyfaf/hub/templates/problems/item.html
+++ b/pyfaf/hub/templates/problems/item.html
@@ -124,8 +124,8 @@
{% with 'Package' as metric_name %}
{% with 3 as row_limit %}
- {% with packages.items as data %}
- {% include 'metric_table.html' %}
+ {% with packages as data %}
+ {% include 'package_table.html' %}
{% endwith %}
{% endwith %}
{% endwith %}
diff --git a/pyfaf/storage/opsys.py b/pyfaf/storage/opsys.py
index ee728b3..524fbd6 100644
--- a/pyfaf/storage/opsys.py
+++ b/pyfaf/storage/opsys.py
@@ -177,6 +177,25 @@ class Build(GenericTable):
return self.nvr()
return "{0}-{1}:{2}-{3}".format(self.component.name, self.epoch,
self.version, self.release)
+ @property
+ def sorted_tags(self):
+ """
+ Return tags for this build quasi-sorted from newer to older.
+ """
+
+ return sorted(self.tags, key=lambda x: x.name, reverse=True)
+
+ @property
+ def newest_tag_name(self):
+ """
+ Return newest tag string this build has.
+ """
+
+ if self.sorted_tags:
+ return self.sorted_tags[0].name
+
+ return ''
+
class BuildArch(GenericTable):
__tablename__ = "buildarchs"
__lobs__ = { "build.log": 1 << 26, "state.log": 1 <<
16, "root.log": 1 << 26 }
--
1.8.1.4
Show replies by date