Skip to content

Commit

Permalink
finish translation
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Jul 4, 2024
1 parent 266c433 commit b4a619c
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 35 deletions.
5 changes: 3 additions & 2 deletions lilac2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from .cmd import git_pull, git_push, UNTRUSTED_PREFIX
from .cmd import run_cmd as _run_cmd
from . import const
from . import const, intl
from .const import _G, SPECIAL_FILES
from .typing import PkgRel, Cmd
from .pypi2pkgbuild import gen_pkgbuild
Expand Down Expand Up @@ -421,10 +421,11 @@ def update_aur_repo() -> None:
try:
_update_aur_repo_real(pkgbase)
except subprocess.CalledProcessError as e:
l10n = intl.get_l10n('mail')
_G.repo.send_error_report(
_G.mod,
exc = e,
subject = '提交软件包 %s 到 AUR 时出错',
subject = l10n.format_value('aur-submit-error'),
)

def git_pkgbuild_commit() -> None:
Expand Down
9 changes: 7 additions & 2 deletions lilac2/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .tools import reap_zombies
from .nomypy import BuildResult # type: ignore
from . import systemd
from . import intl

if TYPE_CHECKING:
from .repo import Repo
Expand Down Expand Up @@ -91,10 +92,14 @@ def build_package(
destdir.mkdir()
sign_and_copy(pkgdir, destdir)
if staging:
l10n = intl.get_l10n('mail')
notify_maintainers(
repo, lilacinfo,
f'{pkgbase} {pkg_version} 刚刚打包了',
'软件包已被置于 staging 目录,请查验后手动发布。',
l10n.format_value('package-staged-subject', {
'pkg': pkgbase,
'version': pkg_version,
}),
l10n.format_value('package-staged-body'),
)
result = BuildResult.staged()
else:
Expand Down
4 changes: 3 additions & 1 deletion lilac2/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from contextlib import suppress

from .typing import Cmd
from . import intl

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -148,7 +149,8 @@ def child_exited(signum: int, sigframe: Optional[types.FrameType]) -> None:
outs = outs.replace('\r\n', '\n')
outs = re.sub(r'.*\r', '', outs)
if outlen > 1024 ** 3: # larger than 1G
outs += '\n\n输出过多,已击杀。\n'
l10n = intl.get_l10n('mail')
outs += '\n\n' + l10n.format_value('too-much-output') + '\n'
if code != 0:
# set output by keyword to avoid being included in repr()
raise subprocess.CalledProcessError(code, cmd, output=outs)
Expand Down
41 changes: 41 additions & 0 deletions lilac2/l10n/en/mail.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,44 @@ dependency-issue-failed-this-batch = {$count_deps ->
[one] { $faileddeps } has
*[other] { $faileddeps } have
} failed this time.
aur-submit-error = Failed to submit %s to AUR
package-staged-subject = { $pkg } { $version } has been packaged just now
package-staged-body = The package has been placed in the staging directory, please check it and then publish manually.
too-much-output = Too much output, killed.
log-too-long = Log too long, omitting...
nvchecker-error-report = nvchecker error report
github-token-not-set = github token not configured, unable to retrieve Email address from GitHub
github-email-error = Error retrieving maintainer's Email address from GitHub: { $error }
github-email-private = GitHub user { $user } doesn't make their Email address public
unsupported-maintainer-info = Unsupported format: { $info }
maintainers-error-subject = maintainers for { $pkg } has errors
maintainers-error-body = The following maintainers information has errors, please fix:
packaging-error-subprocess-subject = Error packaging %s
packaging-error-subprocess =
Command failed!
Command { $cmd } returned error code { $returncode }.
packaging-error-subprocess-output = Output of the command follows:
packaging-error-traceback = Traceback:
packaging-error-aur-subject = Error retrieving AUR package
packaging-error-aur = Failed to retrieve AUR package!
packaging-error-timeout-subject = Timeout when packaging %s
packaging-error-unknown-subject = Unknown error when packaging %s
packaging-error-unknown = An unknown error happend!
packaging-log = Packaging log:
lilac-yaml-loadding-error = Failed to load lilac.yaml for %s
package-in-official-group = Packages is added to official groups: { $groups }{ "\n" }
package-replacing-official-package = Package is replacing official packages: { $packages }{ "\n" }
package-conflicts-with-official-repos = %s conflicts with official repos
package-older-subject = Built package %s has an older version than the one in repo
package-older-body = Package { $pkg } built as version { $built_version }, but there is a version { $repo_version } in repo already.{ "\n" }
3 changes: 3 additions & 0 deletions lilac2/l10n/en/main.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
runtime-error = Runtime error
runtime-error-traceback = Traceback follows:
nvchecker-issues-subject = nvchecker issues
nvchecker-issues-body = There are some errors while running nvchecker:
41 changes: 41 additions & 0 deletions lilac2/l10n/zh_CN/mail.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,44 @@ update_on_build-error = %s update_on_build 检查出错
dependency-issue-subject = %s 出现依赖问题
dependency-issue-failed = { $pkg } 的依赖 { $faileddeps } 打包失败了。
dependency-issue-failed-this-batch = { $pkg } 缺少依赖 { $deps },其中 { $faileddeps } 本次打包失败了。
aur-submit-error = 提交软件包 %s 到 AUR 时出错
package-staged-subject = { $pkg } { $version } 刚刚打包了
package-staged-body = 软件包已被置于 staging 目录,请查验后手动发布。
too-much-output = 输出过多,已击杀。
log-too-long = 日志过长,省略ing……
nvchecker-error-report = nvchecker 错误报告
github-token-not-set = 未设置 github token,无法从 GitHub 取得用户 Email 地址
github-email-error = 从 GitHub 获取维护者 Email 地址时出错:{ $error }
github-email-private = GitHub 用户 { $user } 未公开 Email 地址
unsupported-maintainer-info = 不支持的格式:{ $info }
maintainers-error-subject = { $pkg } 的 maintainers 信息有误
maintainers-error-body = 以下 maintainers 信息有误,请修正。
packaging-error-subprocess-subject = 在打包软件包 %s 时发生错误
packaging-error-subprocess =
命令执行失败!
命令 { $cmd } 返回了错误号 { $returncode }
packaging-error-subprocess-output = 命令的输出如下:
packaging-error-traceback = 调用栈如下:
packaging-error-aur-subject = 在获取AUR包 %s 时发生错误
packaging-error-aur = 获取AUR包失败!
packaging-error-timeout-subject = 打包软件包 %s 超时
packaging-error-unknown-subject = 在打包软件包 %s 时发生未知错误
packaging-error-unknown = 发生未知错误!
packaging-log = 打包日志:
lilac-yaml-loadding-error = 为软件包 %s 载入 lilac.yaml 时失败
package-in-official-group = 软件包被加入了官方组:{ $groups }{ "\n" }
package-replacing-official-package = 软件包将取代官方包:{ $packages }{ "\n" }
package-conflicts-with-official-repos = %s 与官方软件库冲突
package-older-subject = %s 新打的包比仓库里的包旧
package-older-body = { $pkg } 打的版本为 { $built_version },但在仓库里已有较新版本 { $repo_version }{ "\n" }
3 changes: 3 additions & 0 deletions lilac2/l10n/zh_CN/main.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
runtime-error = 运行时错误
runtime-error-traceback = 调用栈如下:
nvchecker-issues-subject = nvchecker 问题
nvchecker-issues-body = 在更新检查时出现了一些错误:
5 changes: 4 additions & 1 deletion lilac2/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Union, Type, List, Dict, Any

from .vendor.mailutils import assemble_mail
from . import intl

SMTPClient = Union[smtplib.SMTP, smtplib.SMTP_SSL]

Expand Down Expand Up @@ -44,7 +45,9 @@ def sendmail(self, to: Union[str, List[str]],

s = self.smtp_connect()
if len(msg) > 5 * 1024 ** 2:
msg = msg[:1024 ** 2] + '\n\n日志过长,省略ing……\n\n' + \
l10n = intl.get_l10n('mail')
too_long = l10n.format_value('log-too-long')
msg = msg[:1024 ** 2] + '\n\n' + too_long + '\n\n' + \
msg[-1024 ** 2:]
mail = assemble_mail('[%s] %s' % (
self.mailtag, subject), to, self.from_, text=msg)
Expand Down
9 changes: 6 additions & 3 deletions lilac2/nvchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .const import mydir
from .typing import LilacInfos, PathLike
from .tools import reap_zombies
from . import intl

if TYPE_CHECKING:
from .repo import Repo, Maintainer
Expand Down Expand Up @@ -177,15 +178,17 @@ def packages_need_update(
'event': 'wrong or missing `update_on` config',
})

l10n = intl.get_l10n('mail')
for who, their_errors in error_owners.items():
logger.warning('send nvchecker report for %r packages to %s',
{x['name'] for x in their_errors}, who)
repo.sendmail(who, 'nvchecker 错误报告',
repo.sendmail(who, l10n.format_value('nvchecker-error-report'),
'\n'.join(_format_error(e) for e in their_errors))

if None in errors: # errors belong to unknown packages
subject = 'nvchecker 问题'
msg = '在更新检查时出现了一些错误:\n\n' + '\n'.join(
l10n = intl.get_l10n('main')
subject = l10n.format_value('nvchecker-issues-subject')
msg = l10n.format_value('nvchecker-issues-body') + '\n\n' + '\n'.join(
_format_error(e) for e in errors[None]) + '\n'
repo.send_repo_mail(subject, msg)

Expand Down
58 changes: 38 additions & 20 deletions lilac2/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from .mail import MailService
from .tools import ansi_escape_re
from . import api, lilacyaml
from . import api, lilacyaml, intl
from .typing import LilacMod, Maintainer, LilacInfos, LilacInfo
from .nomypy import BuildResult # type: ignore
if TYPE_CHECKING:
Expand Down Expand Up @@ -62,7 +62,9 @@ def __init__(self, config: dict[str, Any]) -> None:
@lru_cache()
def maintainer_from_github(self, username: str) -> Optional[Maintainer]:
if self.gh is None:
raise ValueError('未设置 github token,无法从 GitHub 取得用户 Email 地址')
l10n = intl.get_l10n('mail')
msg = l10n.format_value('github-token-not-set')
raise ValueError(msg)

userinfo = self.gh.get_user_info(username)
if userinfo['email']:
Expand All @@ -77,6 +79,7 @@ def parse_maintainers(
ret = []
errors = []

l10n = intl.get_l10n('mail')
for m in ms:
if 'github' in m and 'email' in m:
ret.append(
Expand All @@ -86,15 +89,18 @@ def parse_maintainers(
try:
u = self.maintainer_from_github(m['github'])
except Exception as e:
errors.append(f'从 GitHub 获取用户 Email 地址时出错:{e!r}')
msg = l10n.format_value('github-email-error', {'error': repr(e)})
errors.append(msg)
else:
if u is None:
errors.append(f'GitHub 用户 {m["github"]} 未公开 Email 地址')
msg = l10n.format_value('github-email-private', {'user': m['github']})
errors.append(msg)
else:
ret.append(u)
else:
logger.error('unsupported maintainer info: %r', m)
errors.append(f'不支持的格式:{m!r}')
msg = l10n.format_value('unsupported-maintainer-info', {'info': repr(m)})
errors.append(msg)
continue

return ret, errors
Expand Down Expand Up @@ -190,10 +196,11 @@ def _find_maintainers_impl(

if errors:
error_str = '\n'.join(errors)
l10n = intl.get_l10n('mail')
self.sendmail(
git_maintainer,
subject = f'{pkgbase}maintainers 信息有误',
msg = f"以下 maintainers 信息有误,请修正。\n\n{error_str}\n",
subject = l10n.format_value('maintainers-error-subject', {'pkg': pkgbase}),
msg = l10n.format_value('maintainers-error-body') + f'\n\n{error_str}\n',
)

if not ret and fallback_git:
Expand Down Expand Up @@ -262,24 +269,34 @@ def send_error_report(
if msg is not None:
msgs.append(msg)

l10n = intl.get_l10n('mail')

if exc is not None:
tb = ''.join(traceback.format_exception(type(exc), exc, exc.__traceback__))
if isinstance(exc, subprocess.CalledProcessError):
subject_real = subject or '在打包软件包 %s 时发生错误'
msgs.append('命令执行失败!\n\n命令 %r 返回了错误号 %d。' % (
exc.cmd, exc.returncode))
subject_real = subject or l10n.format_value('packaging-error-subproces-subject')
msg1 = l10n.format_value('packaging-error-subprocess', {
'cmd': repr(exc.cmd),
'returncode': exc.returncode,
})
msgs.append(msg1)
if exc.output:
msgs.append('命令的输出如下:\n\n%s' % exc.output)
msgs.append('调用栈如下:\n\n' + tb)
msg1 = l10n.format_value('packaging-error-subprocess-output')
msgs.append(msg1 + '\n\n' + exc.output)
msg1 = l10n.format_value('packaging-error-traceback')
msgs.append(msg1 + '\n\n' + tb)
elif isinstance(exc, api.AurDownloadError):
subject_real = subject or '在获取AUR包 %s 时发生错误'
msgs.append('获取AUR包失败!\n\n')
msgs.append('调用栈如下:\n\n' + tb)
subject_real = subject or l10n.format_value('packaging-error-aur-subject')
msg1 = l10n.format_value('packaging-error-aur')
msgs.append(msg1 + '\n\n')
msg1 = l10n.format_value('packaging-error-traceback')
msgs.append(msg1 + '\n\n' + tb)
elif isinstance(exc, TimeoutError):
subject_real = subject or '打包软件包 %s 超时'
subject_real = subject or l10n.format_value('packaging-error-timeout-subject')
else:
subject_real = subject or '在打包软件包 %s 时发生未知错误'
msgs.append('发生未知错误!调用栈如下:\n\n' + tb)
subject_real = subject or l10n.format_value('packaging-error-unknown-subject')
msg1 = l10n.format_value('packaging-error-unknown') + l10n.format_value('packaging-error-traceback')
msgs.append(msg1 + '\n\n' + tb)
else:
if subject is None:
raise ValueError('subject should be given but not')
Expand All @@ -295,7 +312,7 @@ def send_error_report(
with logfile.open(errors='replace') as f:
build_output = f.read()
if build_output:
log_header = '打包日志:'
log_header = l10n.format_value('packaging-log')
with suppress(ValueError, KeyError): # invalid template or wrong key
if self.logurl_template and len(logfile.parts) >= 2:
# assume the directory name is the time stamp for now.
Expand Down Expand Up @@ -332,13 +349,14 @@ def manages(self, dep: Dependency) -> bool:
def load_managed_lilac_and_report(self) -> dict[str, tuple[str, ...]]:
self.lilacinfos, errors = lilacyaml.load_managed_lilacinfos(self.repodir)
failed: dict[str, tuple[str, ...]] = {p: () for p in errors}
l10n = intl.get_l10n('mail')
for name, exc_info in errors.items():
logger.error('error while loading lilac.yaml for %s', name, exc_info=exc_info)
exc = exc_info[1]
if not isinstance(exc, Exception):
raise
self.send_error_report(name, exc=exc,
subject='为软件包 %s 载入 lilac.yaml 时失败')
subject=l10n.format_value('lilac-yaml-loadding-error'))
build_logger_old.error('%s failed', name)
build_logger.exception('lilac.yaml error', pkgbase = name, exc_info=exc_info)

Expand Down
Loading

0 comments on commit b4a619c

Please sign in to comment.