File indexing completed on 2023-05-30 12:24:31
0001 # -*- coding: UTF-8 -*- 0002 0003 """ 0004 Tag untranslated messages. 0005 0006 Documented in C{doc/user/sieving.docbook}. 0007 0008 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net> 0009 @license: GPLv3 0010 """ 0011 0012 from pology import _, n_ 0013 from pology.comments import parse_summit_branches 0014 from pology.report import report 0015 0016 0017 def setup_sieve (p): 0018 0019 p.set_desc(_("@info sieve discription", 0020 "Tag all untranslated messages with '%(flag)s' flag.", 0021 flag=_flag_untranslated 0022 )) 0023 0024 p.add_param("strip", bool, 0025 desc=_("@info sieve parameter discription", 0026 "Remove tags from messages." 0027 )) 0028 p.add_param("wfuzzy", bool, 0029 desc=_("@info sieve parameter discription", 0030 "Also add tags to fuzzy messages." 0031 )) 0032 p.add_param("branch", str, seplist=True, 0033 metavar=_("@info sieve parameter value placeholder", "BRANCH"), 0034 desc=_("@info sieve parameter discription", 0035 "In summit catalogs, consider only messages belonging to given branch. " 0036 "Several branches can be given as comma-separated list." 0037 )) 0038 0039 0040 _flag_untranslated = "untranslated" 0041 0042 class Sieve (object): 0043 0044 def __init__ (self, params): 0045 0046 self.strip = params.strip 0047 self.wfuzzy = params.wfuzzy 0048 self.branches = set(params.branch or []) 0049 0050 self.ntagged = 0 0051 self.ncleared = 0 0052 0053 0054 def process (self, msg, cat): 0055 0056 # Skip obsolete messages. 0057 if msg.obsolete: 0058 return 0059 0060 # Summit: if branches were given, considered the message for 0061 # tagging based on whether it belongs to any of the given branches. 0062 may_tag = True 0063 if self.branches: 0064 msg_branches = parse_summit_branches(msg) 0065 if not set.intersection(self.branches, msg_branches): 0066 may_tag = False 0067 0068 ok_msg = msg.untranslated 0069 if self.wfuzzy and not ok_msg: 0070 ok_msg = msg.fuzzy 0071 0072 if not self.strip and may_tag and ok_msg: 0073 if _flag_untranslated not in msg.flag: 0074 msg.flag.add(_flag_untranslated) 0075 self.ntagged += 1 0076 else: 0077 if _flag_untranslated in msg.flag: 0078 msg.flag.remove(_flag_untranslated) 0079 self.ncleared += 1 0080 0081 0082 def finalize (self): 0083 0084 if self.ntagged > 0: 0085 msg = n_("@info:progress", 0086 "Tagged %(num)d untranslated message.", 0087 "Tagged %(num)d untranslated messages.", 0088 num=self.ntagged) 0089 report("===== " + msg) 0090 if self.ncleared > 0: 0091 msg = n_("@info:progress", 0092 "Cleared untranslated tag from %(num)d message.", 0093 "Cleared untranslated tag from %(num)d messages.", 0094 num=self.ncleared) 0095 report("===== " + msg) 0096