File: dump_lol.py

package info (click to toggle)
python-l20n 4.0.0~a1-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 444 kB
  • sloc: python: 1,618; makefile: 18; sh: 8
file content (31 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (4)
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
import argparse

from l20n.format.lol.parser import Parser
import pyast.dump.raw, pyast.dump.js

def read_file(filename, charset='utf-8', errors='strict'):
    with open(filename, 'rb') as f:
        return f.read().decode(charset, errors)

def dump_lol(path, t):
    source = read_file(path)
    p = Parser()
    lol = p.parse(source)
    if t == 'raw':
        print(pyast.dump.raw.dump(lol))
    else:
        print(pyast.dump.js.dump(lol))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Dump LOL\'s AST.',
        prog="dump_lol")
    parser.add_argument('path', type=str,
                        help='path to lol file')
    parser.add_argument('--type', '-t',
                        type=str,
                        choices=('json', 'raw'),
                        default='raw',
                        help='path to lol file')
    args = parser.parse_args()
    dump_lol(args.path, args.type)