File: pogrep.py

package info (click to toggle)
python-mitogen 0.3.25~a2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,220 kB
  • sloc: python: 21,989; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (41 lines) | stat: -rw-r--r-- 1,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

# issue #429: tool for extracting keys out of message catalogs and turning them
# into the big gob of base64 as used in mitogen/sudo.py
#
# Usage:
#   - apt-get source libpam0g
#   - cd */po/
#   - python ~/pogrep.py "Password: "
from __future__ import print_function

import sys
import shlex
import glob


last_word = None

for path in glob.glob('*.po'):
    for line in open(path):
        bits = shlex.split(line, comments=True)
        if not bits:
            continue

        word = bits[0]
        if len(bits) < 2 or not word:
            continue

        rest = bits[1]
        if not rest:
            continue

        if last_word == 'msgid' and word == 'msgstr':
            if last_rest == sys.argv[1]:
                thing = rest.rstrip(': ').decode('utf-8').lower().encode('utf-8').encode('base64').rstrip()
                print('    %-60s # %s' % (repr(thing)+',', path))

        last_word = word
        last_rest = rest

#ag -A 1 'msgid "Password: "'|less | grep msgstr | grep -v '""'|cut -d'"' -f2|cut -d'"' -f1| tr -d :