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
|
#!/usr/bin/env python3
# Ancillary wrapper around gdk-pixbuf-print-mime-types that sets up a
# modified environment in order to use the tools that we just built
# instead of the system ones
import argparse
import os
import subprocess
import sys
argparser = argparse.ArgumentParser(description='Compile resources')
argparser.add_argument('--printer', metavar='PATH', help='Path to gdk-pixbuf-print-mime-types')
argparser.add_argument('--pixdata', metavar='PATH', help='Path to gdk-pixbuf-pixdata')
argparser.add_argument('--loaders', metavar='PATH', help='Path to the loaders.cache file')
argparser.add_argument('--bindir', metavar='PATH', help='Path to the source directory')
argparser.add_argument('input', help='Template file')
argparser.add_argument('output', help='Output file')
args = argparser.parse_args()
newenv = os.environ.copy()
newenv['GDK_PIXBUF_PIXDATA'] = args.pixdata
newenv['GDK_PIXBUF_MODULE_FILE'] = args.loaders
cmd = args.printer
mimetypes_out = subprocess.Popen(cmd, env=newenv, stdout=subprocess.PIPE).communicate()[0]
if not mimetypes_out:
sys.exit(1)
infile = open(args.input, 'r')
outfile = open(args.output, 'w')
for line in infile:
line = line.replace('@bindir@', args.bindir)
line = line.replace('@mimetypes@', mimetypes_out.decode('ascii'))
outfile.write(line)
infile.close()
outfile.close()
sys.exit(0)
|