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

Mejora rendimiento y renderizado en find_in_po#1364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
cmaureir merged 1 commit intopython:3.9fromrtobar:mejoras-find-in-po
Aug 30, 2021
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletionsscripts/find_in_po.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python3

import argparse
import functools
from glob import glob
import multiprocessing
import os
from textwrap import fill

Expand All@@ -10,26 +12,46 @@
from tabulate import tabulate # fades


REVERSE = '\033[7m'
NORMAL = '\033[m'

def _get_file_entries(pattern, width, filename):
entries = []
for entry in (entry for entry in polib.pofile(filename) if entry.msgstr):
match = pattern.search(entry.msgid)
if match:
add_str = entry.msgid + " ·filename: " + filename + "·"
entries.append(
[
fill(add_str, width=width),
fill(entry.msgstr, width=width),
]
)
return entries

def find_in_po(pattern):
table =[]
pattern =regex.compile(pattern)
try:
_, columns = os.popen("stty size", "r").read().split()
available_width = int(columns) // 2 - 3
except:
available_width = 80 // 2 - 3

for file in glob("**/*.po"):
pofile = polib.pofile(file)
for entry in pofile:
if entry.msgstr and regex.search(pattern, entry.msgid):
add_str = entry.msgid + " ·filename: " + file + "·"
table.append(
[
fill(add_str, width=available_width),
fill(entry.msgstr, width=available_width),
]
)
print(tabulate(table, tablefmt="fancy_grid"))
# Find entries in parallel
get_file_entries = functools.partial(_get_file_entries, pattern, available_width)
pool = multiprocessing.Pool()
all_entries = pool.map(get_file_entries, glob("**/*.po"))
table = [entry for file_entries in all_entries for entry in file_entries]

# Create table and highlight results
table = tabulate(table, tablefmt="fancy_grid")
for line in table.splitlines():
match = pattern.search(line)
if match:
span = match.span()
line = (line[:span[0]] + REVERSE + line[span[0]:span[1]] + NORMAL +
line[span[1]:])
print(line)


def parse_args():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp