Debian Codegraph @

private/update-header-fields

raw
1 #!/usr/bin/env python3
2 # encoding=UTF-8
3
4 # Copyright © 2012-2025 Jakub Wilk <[email protected]>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the “Software”), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
23
24 import os
25 import subprocess as ipc
26 import tempfile
27
28 type(...) # Python 3 is required
29
30 xgettexts = {'xgettext', 'pygettext'}
31
32 def main():
33 os.environ['LC_ALL'] = 'C'
34 xgettext_versions = {
35 ipc.check_output([xgettext, '--version']).splitlines()[0].decode('ASCII', 'replace')
36 for xgettext in xgettexts
37 }
38 with tempfile.TemporaryDirectory(prefix='i18nspector.private.') as tmpdir:
39 path = os.path.join(tmpdir, 'dummy.c')
40 with open(path, 'wt', encoding='ASCII') as file:
41 file.write('ngettext("1", "2");')
42 pos = {
43 ipc.check_output([xgettext, '-o', '-', path])
44 for xgettext in xgettexts
45 }
46 headers = set()
47 for po in pos:
48 po = po.decode('ASCII').splitlines()
49 for line in po:
50 if line.startswith('"'):
51 header = line[1:].split(':', 1)[0]
52 headers.add(header)
53 basedir = os.path.join(
54 os.path.dirname(__file__),
55 os.pardir,
56 )
57 path = os.path.join(basedir, 'data', 'header-fields')
58 with open(path, 'wt', encoding='ASCII') as file:
59 print('''\
60 # This file has been generated automatically by
61 # private/update-header-fields. Do not edit.
62 #
63 # The following string extraction tools have been used:\
64 ''', file=file)
65 for xgettext_version in sorted(xgettext_versions):
66 print('# *', xgettext_version, file=file)
67 print(file=file)
68 for header in sorted(headers):
69 print(header, file=file)
70
71 if __name__ == '__main__':
72 main()
73
74 # vim:ts=4 sts=4 sw=4 et