1212# * regenerate_tx_config: recreate configuration for all resources.
1313
1414from argparse import ArgumentParser
15- from collections import Counter
1615import os
16+ from collections import Counter
1717from dataclasses import dataclass
18+ from pathlib import Path
1819from re import match
1920from subprocess import call , run
2021import sys
22+ from timeit import timeit
2123from typing import Self , Callable
2224from urllib .parse import urlparse , parse_qs
2325
26+ from polib import pofile
27+
2428LANGUAGE = 'pl'
2529
2630
@@ -168,14 +172,16 @@ def progress_from_resources(resources: list[ResourceLanguageStatistics], filter_
168172
169173
170174def get_number_of_translators ():
171- process = run (
172- ['grep' , '-ohP' , r'(?<=^# )(.+)(?=, \d+$)' , '-r' , '.' ],
173- capture_output = True ,
174- text = True ,
175- )
176- translators = [match ('(.*)( <.*>)?' , t ).group (1 ) for t in process .stdout .splitlines ()]
177- unique_translators = Counter (translators ).keys ()
178- return len (unique_translators )
175+ translators = set ()
176+ for file in Path ().rglob ('*.po' ):
177+ header = pofile (file ).header .splitlines ()
178+ for translator_record in header [header .index ('Translators:' ) + 1 :]:
179+ translator , _ = translator_record .split (', ' )
180+ if (email_match := match ('.* <(.*)>' , translator )):
181+ translators .add (email_match .group (1 ))
182+ else :
183+ translators .add (translator )
184+ return len (translators )
179185
180186
181187def language_switcher (entry : ResourceLanguageStatistics ) -> bool :
@@ -184,10 +190,13 @@ def language_switcher(entry: ResourceLanguageStatistics) -> bool:
184190
185191
186192if __name__ == "__main__" :
187- RUNNABLE_SCRIPTS = ('fetch' , 'recreate_tx_config' )
188-
189- parser = ArgumentParser ()
190- parser .add_argument ('cmd' , choices = RUNNABLE_SCRIPTS )
191- options = parser .parse_args ()
192-
193- eval (options .cmd )()
193+ # RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config')
194+ #
195+ # parser = ArgumentParser()
196+ # parser.add_argument('cmd', choices=RUNNABLE_SCRIPTS)
197+ # options = parser.parse_args()
198+ #
199+ # eval(options.cmd)()
200+ print (timeit (get_number_of_translators , number = 10 ))
201+
202+ print (timeit (get_number_of_translators_old , number = 10 ))
0 commit comments