File: dump_text.py

package info (click to toggle)
renpy 6.6.2.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 8,740 kB
  • ctags: 3,407
  • sloc: python: 22,153; ansic: 3,724; makefile: 138; lisp: 128; sh: 14
file content (71 lines) | stat: -rwxr-xr-x 1,398 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python

# This program dumps all the text found in the script to stdout.

import codecs
import sys
import os
import re
import glob

import renpy
renpy.import_all()

def process_block(block, out):

    for fn, ln, text, child in block:

        if text.startswith("$") or text.startswith("python"):
            continue

        if text.startswith("init"):
            continue

        if text.startswith("if") or text.startswith("while"):
            process_block(child, out)
            continue

        for m in re.finditer(r'"((?:[^\\"]+|\\.)+)"|' +
                             r"'((?:[^\\']+|\\.)+)'", text):

            s = m.group(1) or m.group(2)

            s = re.sub(r'\s+', ' ', s)
            s = re.sub(r'\\.', ' ', s)

            s = re.sub(r'\{.*?\}', '', s)

            print >>out, s.encode('utf-8')
            print >>out

        process_block(child, out)
        

def process(fn, out):

    block = renpy.parser.group_logical_lines(renpy.parser.list_logical_lines(fn))

    process_block(block, out)


def main():

    pattern = "game/*.rpy"

    if len(sys.argv) >= 2:
        pattern = sys.argv[1]

    files = glob.glob(pattern)
    files = [ i for i in files if not i.startswith("common/") ]

    out = sys.stdout
    out.write(codecs.BOM_UTF8)

    for fn in files:
        process(fn, out)

    out.close()


if __name__ == "__main__":
    main()