Rewritten InstallFiltered builder.

Made it have semantics similar to env.InstallAs and operate only on
directories.
This commit is contained in:
Sergey Popov 2009-01-11 13:15:16 +00:00
parent 1f7e5b0b99
commit 15e0575116

View file

@ -5,44 +5,53 @@ from subprocess import call, Popen, PIPE
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)):
target = Flatten(target)
source = Flatten(source)
if(len(target) != len(source)):
raise ValueError, "Number of targets doesn't match number of sources"
def do_copy(target, 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
if os.path.isfile(source):
if (env["gui"] == "tiny") and (source.endswith("jpg") or source.endswith("png")):
image_info = Popen(["identify", "-verbose", source], stdout = PIPE).communicate()[0]
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))
else:
# Just copy non-images, and images if tinygui is off
if env["verbose"]:
print "cp %s %s" % (source, target)
shutil.copy2(source, target)
else:
if not os.path.exists(target):
if env["verbose"]:
print "Make directory", target
os.makedirs(target)
for file in os.listdir(source):
do_copy(os.path.join(target, file), os.path.join(source, file))
for (target_dir, source_dir) in zip(target, source):
target_path = str(target_dir)
source_path = str(source_dir)
if not os.path.exists(target_path):
os.makedirs(target_path)
for d in (target_path, source_path):
if not os.path.isdir(d):
raise ValueError, "%s is not a directory" % d
do_copy(target_path, source_path)
from SCons.Action import ActionFactory
from shutil import copy2
@ -85,7 +94,7 @@ def InstallData(env, datadir, component, source, subdir = ""):
else:
dirs.append(Dir(source))
if dirs:
install = env.InstallFiltered(installdir, map(Dir, dirs))
install = map(lambda x : env.InstallFiltered(os.path.join(installdir.path, x.name), x.path), dirs)
AlwaysBuild(install)
env.Alias("install-" + component, install)
@ -95,7 +104,7 @@ def generate(env):
SConsEnvironment.InstallBinary = InstallBinary
SConsEnvironment.InstallData = InstallData
env.Append(BUILDERS={'InstallFiltered':Builder(action=InstallFilteredHook)})
env.Append(BUILDERS={'InstallFiltered':Builder(action=InstallFilteredHook, target_factory=Dir, source_factory=Dir)})
def exists():
return True