Mercurial > p > roundup > code
annotate roundup/scripts/roundup_gettext.py @ 8446:14c7c07b32d8
feature: add thread local trace_id and trace_reason to logging.
Added trace_id to default logging so that all logs for a given request
share the same trace_id.
This allows correlation of logs across a request.
admin_guide.txt, upgrading.txt:
add docs
update sample configs to include trace_id.
rewrite logging docs in admin_guide. Hopefully they are clearer now.
clean up some stuff in the logging config file docs.
admin.py:
add decorators to run_command to enable trace_id.
change calls to db.commit() to use run_command to get trace_id.
configuration.py:
clean up imports.
update docstrings, comments and inline docs.
add trace_id to default log format.
add function for testing decorated with trace_id.
add support for dumping stack trace in logging.
add check for pytest in sys.modules to enable log propagation when
pytest is running. Otherwise tests fail as the caplog logger doesn't
see the roundup logs.
logcontext.py:
new file to handle thread local contextvar mangement.
mailgw.py:
add decorators for trace_id etc.
scripts/roundup_xlmrpc_server.py:
add decorators for trace_id etc.
fix encoding bug turning bytes into a string.
fix command line issue where we can't set encoding. (not sure if
changing encoding via command line even works)
cgi/client.py
decorate two entry points for trace_id etc.
cgi/wsgi_handler.py:
decorate entry point for trace_id etc.
test/test_config.py:
add test for trace_id in new log format.
test various cases for sinfo and errors in formating msg.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 16 Sep 2025 22:53:00 -0400 |
| parents | 586f76eb33e8 |
| children | b6b0da04e768 |
| rev | line source |
|---|---|
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
2 # |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
5 """Extract translatable strings from tracker templates and detectors/extensions""" |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
6 |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4766
diff
changeset
|
7 from __future__ import print_function |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
8 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
9 import os |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
10 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
11 # --- patch sys.path to make sure 'import roundup' finds correct version |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
12 import os.path as osp |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
13 import sys |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
14 import tempfile |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
15 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
16 thisdir = osp.dirname(osp.abspath(__file__)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
17 rootdir = osp.dirname(osp.dirname(thisdir)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
18 if (osp.exists(thisdir + '/__init__.py') and |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
19 osp.exists(rootdir + '/roundup/__init__.py')): |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
20 # the script is located inside roundup source code |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
21 sys.path.insert(0, rootdir) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
22 # --/ |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
23 |
|
8091
586f76eb33e8
fix: keep python2 working a little longer.
John Rouillard <rouilj@ieee.org>
parents:
8089
diff
changeset
|
24 from roundup.anypy import scandir_ |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
25 from roundup import configuration |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
26 from roundup.cgi.TAL import talgettext |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
27 from roundup.i18n import _ |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
28 from roundup.pygettext import TokenEater, make_escapes, tokenize |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
29 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
30 try: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
31 import polib |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
32 except ImportError: |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
33 print(_("\nExtracting translatable strings only from html templates.\n" |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
34 "Because the 'polib' module is missing, unable to extract\n" |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
35 "translations from detectors or extensions.\n" |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
36 "The 'polib' module can be installed with pip.\n")) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
37 polib = None |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
38 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
39 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
40 # from pygettext's main(): |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
41 class Options: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
42 # constants |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
43 GNU = 1 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
44 SOLARIS = 2 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
45 # defaults |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
46 extractall = 0 # FIXME: currently this option has no effect at all. |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
47 escape = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
48 keywords = ["_", "gettext", "ngettext", "ugettext"] |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
49 outpath = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
50 outfile = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
51 writelocations = 1 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
52 locationstyle = GNU |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
53 verbose = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
54 width = 10 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
55 excludefilename = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
56 docstrings = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
57 nodocstrings = {} |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
58 toexclude = [] # TODO we should exclude all strings already found in some template |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
59 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
60 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
61 tokeneater_options = Options() |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
62 |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
63 # name of message template file. |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
64 # i don't think this will ever need to be changed, but still... |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
65 TEMPLATE_FILE = "messages.pot" |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
66 |
| 6044 | 67 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
68 def run(): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
69 # return unless command line arguments contain single directory path |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
70 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")): |
| 6044 | 71 print(_("Usage: %(program)s <tracker home>") % |
| 72 {"program": sys.argv[0]}) | |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
73 return |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
74 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
75 home = os.path.abspath(sys.argv[1]) |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
76 # collect file paths of html templates from config |
|
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
77 config = configuration.CoreConfig(home) |
|
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
78 htmldir = config["TEMPLATES"] |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
79 if os.path.isdir(htmldir): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
80 # glob is not used because i want to match file names |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
81 # without case sensitivity, and that is easier done this way. |
|
8088
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
8084
diff
changeset
|
82 htmlfiles = [e.name for e in os.scandir(htmldir) |
|
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
8084
diff
changeset
|
83 if e.is_file() |
|
1045425c23b2
refactor!: replace os.listdir() with os.scandir()
John Rouillard <rouilj@ieee.org>
parents:
8084
diff
changeset
|
84 and e.name.lower().endswith(".html")] |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
85 else: |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
86 htmlfiles = [] |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
87 # return if no html files found |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
88 if not htmlfiles: |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
89 print(_("No tracker templates found in directory %s") % htmldir) |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
90 return |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
91 # change to locale dir to have relative source references |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
92 locale = os.path.join(home, "locale") |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
93 if not os.path.isdir(locale): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
94 os.mkdir(locale) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
95 os.chdir(locale) |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
96 |
|
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
97 # compute relative path to template directory from locale directory |
|
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
98 relpath = os.path.relpath(htmldir) |
|
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
99 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
100 # tweak sys.argv as this is the only way to tell talgettext what to do |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
101 # Note: unix-style paths used instead of os.path.join deliberately |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
102 sys.argv[1:] = ["-o", TEMPLATE_FILE] \ |
|
8089
f2b049b49fca
fix: replace hardcoded 'html' as template directory
John Rouillard <rouilj@ieee.org>
parents:
8088
diff
changeset
|
103 + [relpath + "/" + filename for filename in htmlfiles] |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
104 # run |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
105 talgettext.main() |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
106 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
107 if not polib: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
108 return |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
109 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
110 # we have now everything from the templates in the TEMPLATE_FILE |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
111 # now we search in home/detectors and home/extensions *.py files for |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
112 # tokeneater_options.keywords |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
113 # this is partly assembled from pygettext's main() |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
114 make_escapes(not tokeneater_options.escape) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
115 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
116 pyfiles = [] |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
117 for source in ["detectors", "extensions"]: |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
118 for root, _dirs, files in os.walk(os.path.join("..", source)): |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
119 pyfiles.extend([os.path.join(root, f) for f in files if f.endswith(".py")]) |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
120 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
121 eater = TokenEater(tokeneater_options) |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
122 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
123 for filename in pyfiles: |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
124 eater.set_filename(filename) |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
125 with open(filename, "r") as f: |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
126 try: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
127 for token in tokenize.generate_tokens(f.readline): |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
128 eater(*token) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
129 except tokenize.TokenError as e: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
130 print('%s: %s, line %d, column %d' % ( |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
131 e[0], filename, e[1][0], e[1][1]), file=sys.stderr) |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
132 |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
133 with tempfile.NamedTemporaryFile("w") as tf: |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
134 eater.write(tf) |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
135 tf.seek(0) |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
136 p1 = polib.pofile(TEMPLATE_FILE) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
137 p2 = polib.pofile(tf.name) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
138 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
139 p2_msg_ids = {e.msgid for e in p2} |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
140 for e in p1: |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
141 if e.msgid in p2_msg_ids: |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
142 p2_e = p2.find(e.msgid) |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
143 e.occurrences.extend(p2_e.occurrences) |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
144 p2_msg_ids.remove(e.msgid) |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
145 |
|
8084
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
146 for msgid in p2_msg_ids: |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
147 p1.append(p2.find(msgid)) |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
148 p1.save() |
|
2943140f5286
chore: some ruff linter cleanups.
John Rouillard <rouilj@ieee.org>
parents:
8080
diff
changeset
|
149 |
| 6044 | 150 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
151 if __name__ == "__main__": |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
152 run() |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
153 |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
154 # vim: set et sts=4 sw=4 : |
