# 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
        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']


def handler_repo_saved(sender, **kwargs):
    """Handler called when a Repo is saved."""
    # pylint: disable=unused-argument
    strings = []
    for repo in Repo.objects.order_by('priority'):
        if repo.message:
            strings.append(repo.message)

# 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

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


def handler_repo_saved(sender, **kwargs):
    """Handler called when a Repo is saved."""
    # pylint: disable=unused-argument
    strings = []
    for repo in Repo.objects.order_by('priority'):
        if repo.message:
            strings.append(repo.message)

    i18n_autogen('debian', 'repo', strings)