Skip to content

Commit 8d4f68b

Browse files
authored
Update report download table (#2364)
1 parent 4c4c153 commit 8d4f68b

3 files changed

Lines changed: 78 additions & 10 deletions

File tree

libraries/forms.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def cache_key(self):
284284
report_configuration = self.cleaned_data["report_configuration"]
285285
return f"release-report-{lib_string}-{report_configuration.version}"
286286

287-
def get_stats(self):
287+
def get_stats(self, base_uri: str = None):
288288
report_configuration = self.cleaned_data["report_configuration"]
289289
committee_members = report_configuration.financial_committee_members.all()
290290
# NOTE TO FUTURE DEVS: remember to account for the fact that a report
@@ -366,7 +366,7 @@ def core_batchable(x):
366366
)
367367

368368
git_graph_data = get_git_graph_data(prior_version, version)
369-
download = get_download_links(version)
369+
download = get_download_links(version, base_uri)
370370
### completed task handling ###
371371
(mailinglist_contributor_release_count, mailinglist_contributor_new_count) = (
372372
mailing_list_contributors_task.get()
@@ -431,7 +431,10 @@ def core_batchable(x):
431431
}
432432

433433
def generate_context(
434-
self, report_configuration: ReportConfiguration, stats_results: dict
434+
self,
435+
report_configuration: ReportConfiguration,
436+
stats_results: dict,
437+
base_uri: str = None,
435438
):
436439
committee_members = report_configuration.financial_committee_members.all()
437440

@@ -506,7 +509,7 @@ def core_batchable(x):
506509
)
507510

508511
git_graph_data = get_git_graph_data(prior_version, version)
509-
download = get_download_links(version)
512+
download = get_download_links(version, base_uri)
510513

511514
return {
512515
"committee_members": committee_members,
@@ -554,7 +557,7 @@ def core_batchable(x):
554557
def render_with_stats(self, stats_results, base_uri=None):
555558
"""Render HTML with pre-computed stats results"""
556559
context = self.generate_context(
557-
self.cleaned_data["report_configuration"], stats_results
560+
self.cleaned_data["report_configuration"], stats_results, base_uri
558561
)
559562
if base_uri:
560563
context["base_uri"] = base_uri

libraries/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ def generate_release_report(user_id, params, base_uri=None, stats_results=None):
276276
return None
277277

278278
if stats_results:
279-
html = form.render_with_stats(stats_results, base_uri=base_uri)
279+
html = form.render_with_stats(
280+
stats_results,
281+
base_uri=base_uri,
282+
)
280283
else:
281284
html = form.cache_html(base_uri=base_uri)
282285

reports/generation.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import json
44
import logging
55
import random
6+
import re
67
from dataclasses import dataclass, field
78
from datetime import timedelta, date
89
from functools import cached_property
910
from itertools import chain, groupby
10-
from operator import attrgetter
11+
from operator import attrgetter, itemgetter
1112

1213
import psycopg2
1314
from django.conf import settings
1415
from django.contrib.staticfiles import finders
1516
from django.db.models import OuterRef, Q, F, Case, When, Value, Sum, Count
17+
from django.urls import reverse
1618
from matplotlib import pyplot as plt
1719
from wordcloud import WordCloud, STOPWORDS
1820
from algoliasearch.analytics.client import AnalyticsClientSync
@@ -612,15 +614,75 @@ def get_issues_counts(prior_version: Version, version: Version):
612614
return opened_issues_count, closed_issues_count
613615

614616

615-
def get_download_links(version: Version):
616-
return {
617+
def get_download_links(version: Version, base_uri: str = None):
618+
from versions.models import OperatingSystems
619+
620+
r_dict = {
617621
k: list(v)
618622
for k, v in groupby(
619-
version.downloads.all().order_by("operating_system"),
623+
version.downloads.all().order_by("operating_system", "display_name"),
620624
key=attrgetter("operating_system"),
621625
)
622626
}
623627

628+
# Some Version of Boost have no windows binaries, so we can return
629+
win_bin_d = r_dict.get(OperatingSystems.WINDOWS_BIN, None)
630+
if not bool(win_bin_d):
631+
return r_dict
632+
633+
# Attempt to match version name, in shape of Boost version - msvc - msvc version - bit.exe
634+
# e.g. boost_1_91_0_b1-msvc-14.5-64.exe
635+
# and return major and minor msvc version
636+
637+
v_reg = re.compile(
638+
r"^[^-]*-msvc-(?P<major_version>[\d]+)\.(?P<minor_version>[\d]+)-[\d.\w]+$"
639+
)
640+
641+
updated_win_dls = []
642+
msvc_versions = []
643+
version_files = {}
644+
645+
# Iterate over our files, group them by major and minor msvc version
646+
for dl in win_bin_d:
647+
match = v_reg.match(dl.display_name)
648+
if not match:
649+
# If our regex does not match, we have found an "all" file, so add it to the list
650+
updated_win_dls.append(dl)
651+
continue
652+
msvc_version = (
653+
int(match.groupdict().get("major_version")),
654+
int(match.groupdict().get("minor_version")),
655+
)
656+
msvc_versions.append(msvc_version)
657+
if msvc_version not in version_files:
658+
version_files[msvc_version] = []
659+
version_files[msvc_version].append(dl)
660+
661+
# Remove dupes and sort
662+
msvc_versions = list(set(msvc_versions))
663+
msvc_versions.sort(key=itemgetter(0, 1))
664+
665+
# If we somehow didn't generate anyversions, return to avoid an error
666+
# This might occure if all versions are "all" versions, or if the regex fails
667+
# in the future
668+
if not bool(msvc_versions):
669+
return r_dict
670+
671+
selected_version = msvc_versions[-1]
672+
updated_win_dls += version_files.get(selected_version, [])
673+
674+
# If we have passed a base_uri, use it to create a link to the release detail page
675+
if base_uri:
676+
updated_win_dls.append(
677+
{
678+
"display_name": "To see other windows versions, click here",
679+
"url": f"{base_uri}{reverse("release-detail", kwargs={"version_slug":version.slug})}",
680+
}
681+
)
682+
683+
r_dict[OperatingSystems.WINDOWS_BIN] = updated_win_dls
684+
return r_dict
685+
624686

625687
def get_mailinglist_msg_counts(version: Version) -> tuple[int, int]:
626688
total_mailinglist_count = EmailData.objects.filter(version=version).aggregate(

0 commit comments

Comments
 (0)