# Path: weechat/debian/views.py
# def repos(request, active='active', files=''):
#     """Page with debian repositories."""
#     if active == 'active':
#         repositories = (Repo.objects.all().filter(active=1).filter(visible=1)
#                         .order_by('priority'))
#     else:
#         repositories = (Repo.objects.all().filter(visible=1)
#                         .order_by('priority'))
#     debpkgs = []
#     errors = []
#     for repository in repositories:
#         try:
#             repo_packages = get_repository_packages(repository)
#             debpkgs.extend(sorted(repo_packages,
#                                   key=lambda p: p['builddatetime'],
#                                   reverse=True))
#         except:  # noqa: E722  pylint: disable=bare-except
#             errors.append(f'{repository.name} {repository.version}')
#     return render(
#         request,
#         'download/debian.html',
#         {
#             'debpkgs': debpkgs,
#             'active': active,
#             'allfiles': files == 'files',
#             'repositories': repositories,
#             'errors': errors,
#         },
#     )
# 
# Path: weechat/download/views.py
# def packages(request, version='stable'):
#     """Page with packages for a version (stable, devel, all, old, or x.y.z)."""
#     package_list = None
#     release_progress = None
#     try:
#         if version == 'stable':
#             stable_desc = Release.objects.get(version='stable').description
#             package_list = (Package.objects.all().filter(version=stable_desc)
#                             .order_by('type__priority'))
#         elif version == 'devel':
#             package_list = (Package.objects.all().filter(version='devel')
#                             .order_by('type__priority'))
#         elif version == 'all':
#             package_list = (Package.objects.all().exclude(version='devel')
#                             .order_by('-version__date', 'type__priority'))
#         elif version == 'old':
#             stable_desc = Release.objects.get(version='stable').description
#             package_list = (Package.objects.all().exclude(version='devel')
#                             .exclude(version=stable_desc)
#                             .order_by('-version__date', 'type__priority'))
#         else:
#             package_list = (Package.objects.filter(version=version)
#                             .order_by('type__priority'))
#         release_progress = get_release_progress()
#     except ObjectDoesNotExist:
#         package_list = None
#         release_progress = None
#     return render(
#         request,
#         'download/packages.html',
#         {
#             'version': version,
#             'package_list': package_list,
#             'release_progress': release_progress,
#         },
#     )
# 
# def package_checksums(request, version, checksum_type):
#     """Page with checksums of packages in a version."""
#     package_list = (Package.objects.filter(version=version)
#                     .order_by('type__priority'))
#     checksums = []
#     for package in package_list:
#         checksum = package.checksum()
#         if checksum:
#             checksums.append(f'{checksum}  {package.filename}')
#     response = HttpResponse('\n'.join(checksums), content_type='text/plain')
#     response['Content-disposition'] = (f'inline; filename=weechat-'
#                                        f'{version}-{checksum_type}.txt')
#     return response
# 
# def release(request):
#     """Page with release in progress."""
#     return render(
#         request,
#         'download/release.html',
#         {
#             'release_progress': get_release_progress(),
#         },
#     )


from django.urls import path, re_path
from weechat.debian.views import repos as view_repos
from weechat.download.views import (
    packages as view_packages,
    package_checksums as view_package_checksums,
    release as view_release,
)
#
# This file is part of WeeChat.org.
#
# WeeChat.org is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# WeeChat.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat.org.  If not, see <https://www.gnu.org/licenses/>.
#

"""URLs for "download" menu."""

# pylint: disable=invalid-name, no-value-for-parameter



urlpatterns = [
    path('', view_packages, name='download'),
    path('debian/', view_repos, kwargs={'active': 'active'},
         name='download_debian'),
    re_path(r'^debian/(?P<active>(active|all))/$', view_repos,
            name='download_debian_active'),
    re_path(r'^debian/(?P<active>(active|all))/(?P<files>[a-zA-Z0-9.]*)/$',

# Path: weechat/debian/views.py
# def repos(request, active='active', files=''):
#     """Page with debian repositories."""
#     if active == 'active':
#         repositories = (Repo.objects.all().filter(active=1).filter(visible=1)
#                         .order_by('priority'))
#     else:
#         repositories = (Repo.objects.all().filter(visible=1)
#                         .order_by('priority'))
#     debpkgs = []
#     errors = []
#     for repository in repositories:
#         try:
#             repo_packages = get_repository_packages(repository)
#             debpkgs.extend(sorted(repo_packages,
#                                   key=lambda p: p['builddatetime'],
#                                   reverse=True))
#         except:  # noqa: E722  pylint: disable=bare-except
#             errors.append(f'{repository.name} {repository.version}')
#     return render(
#         request,
#         'download/debian.html',
#         {
#             'debpkgs': debpkgs,
#             'active': active,
#             'allfiles': files == 'files',
#             'repositories': repositories,
#             'errors': errors,
#         },
#     )
# 
# Path: weechat/download/views.py
# def packages(request, version='stable'):
#     """Page with packages for a version (stable, devel, all, old, or x.y.z)."""
#     package_list = None
#     release_progress = None
#     try:
#         if version == 'stable':
#             stable_desc = Release.objects.get(version='stable').description
#             package_list = (Package.objects.all().filter(version=stable_desc)
#                             .order_by('type__priority'))
#         elif version == 'devel':
#             package_list = (Package.objects.all().filter(version='devel')
#                             .order_by('type__priority'))
#         elif version == 'all':
#             package_list = (Package.objects.all().exclude(version='devel')
#                             .order_by('-version__date', 'type__priority'))
#         elif version == 'old':
#             stable_desc = Release.objects.get(version='stable').description
#             package_list = (Package.objects.all().exclude(version='devel')
#                             .exclude(version=stable_desc)
#                             .order_by('-version__date', 'type__priority'))
#         else:
#             package_list = (Package.objects.filter(version=version)
#                             .order_by('type__priority'))
#         release_progress = get_release_progress()
#     except ObjectDoesNotExist:
#         package_list = None
#         release_progress = None
#     return render(
#         request,
#         'download/packages.html',
#         {
#             'version': version,
#             'package_list': package_list,
#             'release_progress': release_progress,
#         },
#     )
# 
# def package_checksums(request, version, checksum_type):
#     """Page with checksums of packages in a version."""
#     package_list = (Package.objects.filter(version=version)
#                     .order_by('type__priority'))
#     checksums = []
#     for package in package_list:
#         checksum = package.checksum()
#         if checksum:
#             checksums.append(f'{checksum}  {package.filename}')
#     response = HttpResponse('\n'.join(checksums), content_type='text/plain')
#     response['Content-disposition'] = (f'inline; filename=weechat-'
#                                        f'{version}-{checksum_type}.txt')
#     return response
# 
# def release(request):
#     """Page with release in progress."""
#     return render(
#         request,
#         'download/release.html',
#         {
#             'release_progress': get_release_progress(),
#         },
#     )


# Path: weechat/download/urls.py
from django.urls import path, re_path
from weechat.debian.views import repos as view_repos
from weechat.download.views import (
    packages as view_packages,
    package_checksums as view_package_checksums,
    release as view_release,
)

#
# This file is part of WeeChat.org.
#
# WeeChat.org is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# WeeChat.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat.org.  If not, see <https://www.gnu.org/licenses/>.
#

"""URLs for "download" menu."""

# pylint: disable=invalid-name, no-value-for-parameter



urlpatterns = [
    path('', view_packages, name='download'),
    path('debian/', view_repos, kwargs={'active': 'active'},
         name='download_debian'),
    re_path(r'^debian/(?P<active>(active|all))/$', view_repos,
            name='download_debian_active'),
    re_path(r'^debian/(?P<active>(active|all))/(?P<files>[a-zA-Z0-9.]*)/$',

            view_repos),