# Path: weechat/common/path.py
# def repo_path_join(*args):
#     """Join multiple paths after settings.REPO_DIR."""
#     return __path_join(settings.REPO_DIR, *args)
# 
# Path: weechat/debian/models.py
# class Repo(models.Model):
#     """A Debian repository."""
#     visible = models.BooleanField(default=True)
#     active = models.BooleanField(default=True)
#     name = models.CharField(max_length=64)
#     version = models.ForeignKey(Version, on_delete=models.CASCADE)
#     url = models.CharField(max_length=512)
#     arch = models.CharField(max_length=128)
#     builder = models.ForeignKey(Builder, on_delete=models.CASCADE)
#     # in hours, 0 = unknown frequency (next build date is not displayed)
#     build_frequency = models.IntegerField(default=24)
#     message = models.CharField(max_length=1024, blank=True)
#     priority = models.IntegerField(default=0)
# 
#     def __str__(self):
#         visible = 'visible' if self.visible else 'hidden'
#         active = 'active' if self.active else 'discontinued'
#         return (f'{self.name} {self.version}, {visible}, {active} '
#                 f'({self.arch}) ({self.priority})')
# 
#     def path_packages_gz(self, arch):
#         """Return path/name to the Packages.gz file of repository."""
#         return repo_path_join(self.name, 'dists',
#                               self.version.codename, 'main',
#                               f'binary-{arch}', 'Packages.gz')
# 
#     def apt_url(self):
#         """
#         Return the URL to use with apt for binary packages, for example:
#         "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg]
#         https://weechat.org/debian sid main".
#         """
#         return (f'deb [signed-by=/usr/share/keyrings/weechat-archive-'
#                 f'keyring.gpg] {self.url} {self.version.codename} main')
# 
#     def apt_url_src(self):
#         """
#         Return the URL to use with apt for sources packages, for example:
#         "deb-src [signed-by=/usr/share/keyrings/weechat-archive-
#         keyring.gpg] https://weechat.org/debian sid main".
#         """
#         return (
#             f'deb-src [signed-by=/usr/share/keyrings/weechat-'
#             f'archive-keyring.gpg] {self.url} {self.version.codename} main'
#         )
# 
#     class Meta:
#         """Sort Repos by priority."""
#         ordering = ['priority']


from datetime import datetime, timedelta
from django.conf import settings
from django.shortcuts import render
from weechat.common.path import repo_path_join
from weechat.debian.models import Repo
import gzip
import os
import re
import pytz
                        pkg['builddatetime'] = date_time
                        add_hours = repository.build_frequency
                        if repository.active and add_hours > 0:
                            nextbuilddatetime = (date_time +
                                                 timedelta(hours=add_hours))
                            if nextbuilddatetime > now:
                                pkg['nextbuilddatetime'] = nextbuilddatetime
                        pkg['basename'] = os.path.basename(pkg['Filename'])
                        pkg['anchor'] = (f'{repository.name}_'
                                         f'{repository.version.codename}_'
                                         f'{pkg["Version"]}_{arch}')
                        if 'Source' not in pkg:
                            pkg['Source'] = pkg['Package']
                        pkg['version_type'] = ('dev'
                                               if 'dev' in pkg['Version']
                                               else 'stable')
                        repopkgs.append(pkg)
                    pkg = {}
                match = re.match('^([^ ]+): (.*)$', line)
                if match:
                    pkg[match.group(1)] = match.group(2)
    return repopkgs


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:

# Path: weechat/common/path.py
# def repo_path_join(*args):
#     """Join multiple paths after settings.REPO_DIR."""
#     return __path_join(settings.REPO_DIR, *args)
# 
# Path: weechat/debian/models.py
# class Repo(models.Model):
#     """A Debian repository."""
#     visible = models.BooleanField(default=True)
#     active = models.BooleanField(default=True)
#     name = models.CharField(max_length=64)
#     version = models.ForeignKey(Version, on_delete=models.CASCADE)
#     url = models.CharField(max_length=512)
#     arch = models.CharField(max_length=128)
#     builder = models.ForeignKey(Builder, on_delete=models.CASCADE)
#     # in hours, 0 = unknown frequency (next build date is not displayed)
#     build_frequency = models.IntegerField(default=24)
#     message = models.CharField(max_length=1024, blank=True)
#     priority = models.IntegerField(default=0)
# 
#     def __str__(self):
#         visible = 'visible' if self.visible else 'hidden'
#         active = 'active' if self.active else 'discontinued'
#         return (f'{self.name} {self.version}, {visible}, {active} '
#                 f'({self.arch}) ({self.priority})')
# 
#     def path_packages_gz(self, arch):
#         """Return path/name to the Packages.gz file of repository."""
#         return repo_path_join(self.name, 'dists',
#                               self.version.codename, 'main',
#                               f'binary-{arch}', 'Packages.gz')
# 
#     def apt_url(self):
#         """
#         Return the URL to use with apt for binary packages, for example:
#         "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg]
#         https://weechat.org/debian sid main".
#         """
#         return (f'deb [signed-by=/usr/share/keyrings/weechat-archive-'
#                 f'keyring.gpg] {self.url} {self.version.codename} main')
# 
#     def apt_url_src(self):
#         """
#         Return the URL to use with apt for sources packages, for example:
#         "deb-src [signed-by=/usr/share/keyrings/weechat-archive-
#         keyring.gpg] https://weechat.org/debian sid main".
#         """
#         return (
#             f'deb-src [signed-by=/usr/share/keyrings/weechat-'
#             f'archive-keyring.gpg] {self.url} {self.version.codename} main'
#         )
# 
#     class Meta:
#         """Sort Repos by priority."""
#         ordering = ['priority']


# Path: weechat/debian/views.py
from datetime import datetime, timedelta
from django.conf import settings
from django.shortcuts import render
from weechat.common.path import repo_path_join
from weechat.debian.models import Repo
import gzip
import os
import re
import pytz

                        pkg['builddatetime'] = date_time
                        add_hours = repository.build_frequency
                        if repository.active and add_hours > 0:
                            nextbuilddatetime = (date_time +
                                                 timedelta(hours=add_hours))
                            if nextbuilddatetime > now:
                                pkg['nextbuilddatetime'] = nextbuilddatetime
                        pkg['basename'] = os.path.basename(pkg['Filename'])
                        pkg['anchor'] = (f'{repository.name}_'
                                         f'{repository.version.codename}_'
                                         f'{pkg["Version"]}_{arch}')
                        if 'Source' not in pkg:
                            pkg['Source'] = pkg['Package']
                        pkg['version_type'] = ('dev'
                                               if 'dev' in pkg['Version']
                                               else 'stable')
                        repopkgs.append(pkg)
                    pkg = {}
                match = re.match('^([^ ]+): (.*)$', line)
                if match:
                    pkg[match.group(1)] = match.group(2)
    return repopkgs


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)