|
3 | 3 | import json |
4 | 4 | import logging |
5 | 5 | import random |
| 6 | +import re |
6 | 7 | from dataclasses import dataclass, field |
7 | 8 | from datetime import timedelta, date |
8 | 9 | from functools import cached_property |
9 | 10 | from itertools import chain, groupby |
10 | | -from operator import attrgetter |
| 11 | +from operator import attrgetter, itemgetter |
11 | 12 |
|
12 | 13 | import psycopg2 |
13 | 14 | from django.conf import settings |
14 | 15 | from django.contrib.staticfiles import finders |
15 | 16 | from django.db.models import OuterRef, Q, F, Case, When, Value, Sum, Count |
| 17 | +from django.urls import reverse |
16 | 18 | from matplotlib import pyplot as plt |
17 | 19 | from wordcloud import WordCloud, STOPWORDS |
18 | 20 | from algoliasearch.analytics.client import AnalyticsClientSync |
@@ -612,15 +614,75 @@ def get_issues_counts(prior_version: Version, version: Version): |
612 | 614 | return opened_issues_count, closed_issues_count |
613 | 615 |
|
614 | 616 |
|
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 = { |
617 | 621 | k: list(v) |
618 | 622 | for k, v in groupby( |
619 | | - version.downloads.all().order_by("operating_system"), |
| 623 | + version.downloads.all().order_by("operating_system", "display_name"), |
620 | 624 | key=attrgetter("operating_system"), |
621 | 625 | ) |
622 | 626 | } |
623 | 627 |
|
| 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 | + |
624 | 686 |
|
625 | 687 | def get_mailinglist_msg_counts(version: Version) -> tuple[int, int]: |
626 | 688 | total_mailinglist_count = EmailData.objects.filter(version=version).aggregate( |
|
0 commit comments