File: resource_template.py

package info (click to toggle)
gpick 0.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,400 kB
  • ctags: 3,306
  • sloc: cpp: 22,216; python: 740; ansic: 476; yacc: 252; lex: 197; makefile: 49; xml: 11; sh: 8
file content (28 lines) | stat: -rw-r--r-- 789 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
from SCons.Script import *
from SCons.Tool.install import copyFunc

import re

def addResourceTemplateBuilder(env):
	
	def buildResourceFile(target, source, env):
		source_dest = SCons.Util.splitext(str(target[0]))[0] + ".rc"
		wfile = open(source_dest,"w")
		data = open(str(File(source[0]).srcnode())).read()
		for key, var in env['RESOURCE_TEMPLATE_VARS'].iteritems():
			data = re.sub("%" + key + "%", var, data)
		wfile.write(data)
		wfile.close()
		return 0

	def buildResourceFileString(target, source, env):
		return "Preparing resource file %s" % os.path.basename(str(target[0]))

	builder = Builder(
		action = SCons.Action.Action(buildResourceFile, buildResourceFileString),
		suffix = '.rc',
		src_suffix = '.rct',
		)
		
	env.Append(BUILDERS = {'ResourceTemplate': builder})