File: parse.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 (28 lines) | stat: -rwxr-xr-x 621 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
#!/usr/bin/python 

import sys

sys.path.append('./')
import codecs
import ftl.format.parser
import ftl.format.ast
import json

def read_file(path):
    with codecs.open(path, 'r', encoding='utf-8') as file:
        text = file.read()
    return text

def print_ast(fileType, data):
    ftlParser = ftl.format.parser.FTLParser()
    [ast, errors] = ftlParser.parseResource(data)
    print(json.dumps(ast, indent=2, ensure_ascii=False))

    print('Errors:')
    for error in errors:
        print(error.message)

if __name__ == "__main__":
    file_type = 'ftl'
    f = read_file(sys.argv[1])
    print_ast(file_type, f)