# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# Path: weechat/common/path.py
# def repo_path_join(*args):
#     """Join multiple paths after settings.REPO_DIR."""
#     return __path_join(settings.REPO_DIR, *args)


from django.db import models
from django.db.models.signals import post_save
from weechat.common.i18n import i18n_autogen
from weechat.common.path import repo_path_join
    """The nick and name of person building packages in this repository."""
    nick = models.CharField(max_length=64, primary_key=True)
    name = models.CharField(max_length=128)

    def __str__(self):
        return f'{self.name} ({self.nick})'


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."""

# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# 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
from django.db import models
from django.db.models.signals import post_save
from weechat.common.i18n import i18n_autogen
from weechat.common.path import repo_path_join

    """The nick and name of person building packages in this repository."""
    nick = models.CharField(max_length=64, primary_key=True)
    name = models.CharField(max_length=128)

    def __str__(self):
        return f'{self.name} ({self.nick})'


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',