aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/fontconfig/process-template.py
blob: 5ea60bdb8aeb12a9c46e57dd26fbc731a1ef95da (plain)
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
#!/usr/bin/python

# Copyright 2014 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# A simple template processing script.

import argparse
import os
import sys

parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input')
parser.add_argument('-o', '--output')
parser.add_argument(
    '-k', '--keyword_substitution',  action='append', nargs=2,
     metavar=('KEY', 'VALUE'), help='Changes KEY to VALUE in the template.')
parser.add_argument(
    '-p', '--path_substitution', action='append', nargs=2,
    metavar=('KEY', 'PATH'),
    help='Makes PATH absolute then changes KEY to PATH in the template.')

args = parser.parse_args()

input = sys.stdin
if args.input:
  input = open(args.input, 'r')

output = sys.stdout
if args.output:
  output = open(args.output, 'w')

path_subs = None
if args.path_substitution:
  path_subs = [
      [sub[0], os.path.abspath(sub[1])] for sub in args.path_substitution
  ]

for line in input:
  if args.keyword_substitution:
    for (key, value) in args.keyword_substitution:
      line = line.replace(key, value)
  if path_subs:
    for (key, path) in path_subs:
      line = line.replace(key, path)
  output.write(line)

input.close()
output.close()