SCons recipe: moved some Install builder methods to separate file.

This commit is contained in:
Sergey Popov 2008-05-22 13:51:51 +00:00
parent c470637f8f
commit 44280b5a9d
2 changed files with 63 additions and 51 deletions

View file

@ -75,7 +75,7 @@ opts.AddOptions(
# Setup
#
env = Environment(tools=["tar", "gettext"], options = opts, toolpath = ["scons"])
env = Environment(tools=["tar", "gettext", "install"], options = opts, toolpath = ["scons"])
if env["PLATFORM"] == "win32":
env.Tool("mingw")
else:
@ -365,62 +365,14 @@ def CopyFilter(fn):
"Filter out data-tree things that shouldn't be installed."
return not ".svn" in str(fn) and not "Makefile" in str(fn)
env["copy_filter"] = CopyFilter
for lang in filter(CopyFilter, os.listdir("doc/man")):
sourcedir = os.path.join("doc/man", lang)
if os.path.isdir(sourcedir):
targetdir = os.path.join(mandir, lang, "man6")
localized_man_dirs[sourcedir] = targetdir
def InstallFilteredHook(target, source, env):
if type(target) == type([]):
target = target[0]
target = str(target)
if type(source) == type([]):
map(lambda f: InstallFilteredHook(target, f, env), source)
elif os.path.isdir(str(source)):
if CopyFilter(source):
target = os.path.join(target, os.path.basename(str(source)))
if not os.path.exists(target):
if env["verbose"]:
print "Make directory", target
os.makedirs(target)
map(lambda f: InstallFilteredHook(target, os.path.join(str(source), f), env), os.listdir(str(source)))
elif CopyFilter(source):
if (env["gui"] == "tiny") and (source.endswith("jpg") or source.endswith("png")):
image_info = Popen(["identify", "-verbose", source], stdout = PIPE).communicate()[0]
target = os.path.join(target, os.path.basename(source))
if "Alpha: " in image_info:
command = "convert -filter point -resize %s %s %s"
else:
command = "convert -resize %s %s %s"
for (large, small) in (("1024x768","320x240"),
("640x480","240x180"),
("205x205","80x80")):
if ("Geometry: " + large) in image_info:
command = command % (small, source, target)
break
else:
command = command % ("50%", source, target)
if env["verbose"]:
print command
call(Split(command))
return None
# Just copy non-images, and images if tinygui is off
if env["verbose"]:
print "cp %s %s" % (str(source), target)
shutil.copy2(str(source), target)
return None
env.Append(BUILDERS={'InstallFiltered':Builder(action=InstallFilteredHook)})
def InstallWithSuffix(env, target, source):
if not source:
return source
return env.InstallAs(os.path.join(target, source[0].name + env["program_suffix"]), source)
#env.AddMethod(InstallWithSuffix)
from SCons.Script.SConscript import SConsEnvironment
SConsEnvironment.InstallWithSuffix = InstallWithSuffix
def InstallLocalizedManPage(alias, page, env):
actions = []
for (sourcedir, targetdir) in localized_man_dirs.items():

60
scons/install.py Normal file
View file

@ -0,0 +1,60 @@
# vi: syntax=python:et:ts=4
from SCons.Script import *
import shutil, os
from subprocess import call
def InstallFilteredHook(target, source, env):
CopyFilter = env["copy_filter"]
if type(target) == type([]):
target = target[0]
target = str(target)
if type(source) == type([]):
map(lambda f: InstallFilteredHook(target, f, env), source)
elif os.path.isdir(str(source)):
if CopyFilter(source):
target = os.path.join(target, os.path.basename(str(source)))
if not os.path.exists(target):
if env["verbose"]:
print "Make directory", target
os.makedirs(target)
map(lambda f: InstallFilteredHook(target, os.path.join(str(source), f), env), os.listdir(str(source)))
elif CopyFilter(source):
if (env["gui"] == "tiny") and (source.endswith("jpg") or source.endswith("png")):
image_info = Popen(["identify", "-verbose", source], stdout = PIPE).communicate()[0]
target = os.path.join(target, os.path.basename(source))
if "Alpha: " in image_info:
command = "convert -filter point -resize %s %s %s"
else:
command = "convert -resize %s %s %s"
for (large, small) in (("1024x768","320x240"),
("640x480","240x180"),
("205x205","80x80")):
if ("Geometry: " + large) in image_info:
command = command % (small, source, target)
break
else:
command = command % ("50%", source, target)
if env["verbose"]:
print command
call(Split(command))
return None
# Just copy non-images, and images if tinygui is off
if env["verbose"]:
print "cp %s %s" % (str(source), target)
shutil.copy2(str(source), target)
return None
def InstallWithSuffix(env, target, source):
if not source:
return source
return env.InstallAs(os.path.join(target, source[0].name + env["program_suffix"]), source)
def generate(env):
#env.AddMethod(InstallWithSuffix)
from SCons.Script.SConscript import SConsEnvironment
SConsEnvironment.InstallWithSuffix = InstallWithSuffix
env.Append(BUILDERS={'InstallFiltered':Builder(action=InstallFilteredHook)})
def exists():
return True