Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17f7d64

Browse files
authored
Mejora rendimiento y renderizado en find_in_po (#1364)
Este set de cambios introduce dos mejoras en el script find_in_po. Enprimer lugar usa multiprocessing para realizar la búsqueda deexpresiones regulares en paralelo (buscando en distintos archivos almismo tiempo). En segundo lugar, después de generar la tabla con losresultados, los resultados de la expresión regular son destacados almomento de ser impresos en el terminal para encontrarlos más fácilmente.Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
1 parentbc2f1d2 commit17f7d64

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

‎scripts/find_in_po.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python3
22

33
importargparse
4+
importfunctools
45
fromglobimportglob
6+
importmultiprocessing
57
importos
68
fromtextwrapimportfill
79

@@ -10,26 +12,46 @@
1012
fromtabulateimporttabulate# fades
1113

1214

15+
REVERSE='\033[7m'
16+
NORMAL='\033[m'
17+
18+
def_get_file_entries(pattern,width,filename):
19+
entries= []
20+
forentryin (entryforentryinpolib.pofile(filename)ifentry.msgstr):
21+
match=pattern.search(entry.msgid)
22+
ifmatch:
23+
add_str=entry.msgid+" ·filename: "+filename+"·"
24+
entries.append(
25+
[
26+
fill(add_str,width=width),
27+
fill(entry.msgstr,width=width),
28+
]
29+
)
30+
returnentries
31+
1332
deffind_in_po(pattern):
14-
table=[]
33+
pattern=regex.compile(pattern)
1534
try:
1635
_,columns=os.popen("stty size","r").read().split()
1736
available_width=int(columns)//2-3
1837
except:
1938
available_width=80//2-3
2039

21-
forfileinglob("**/*.po"):
22-
pofile=polib.pofile(file)
23-
forentryinpofile:
24-
ifentry.msgstrandregex.search(pattern,entry.msgid):
25-
add_str=entry.msgid+" ·filename: "+file+"·"
26-
table.append(
27-
[
28-
fill(add_str,width=available_width),
29-
fill(entry.msgstr,width=available_width),
30-
]
31-
)
32-
print(tabulate(table,tablefmt="fancy_grid"))
40+
# Find entries in parallel
41+
get_file_entries=functools.partial(_get_file_entries,pattern,available_width)
42+
pool=multiprocessing.Pool()
43+
all_entries=pool.map(get_file_entries,glob("**/*.po"))
44+
table= [entryforfile_entriesinall_entriesforentryinfile_entries]
45+
46+
# Create table and highlight results
47+
table=tabulate(table,tablefmt="fancy_grid")
48+
forlineintable.splitlines():
49+
match=pattern.search(line)
50+
ifmatch:
51+
span=match.span()
52+
line= (line[:span[0]]+REVERSE+line[span[0]:span[1]]+NORMAL+
53+
line[span[1]:])
54+
print(line)
3355

3456

3557
defparse_args():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp