Klangworks.org


Code Snippets


A scons SContruct file and rake Rakefile that do the same thing 

I've been trying to figure out how to use Rake - and how to use Scons. Scons has been around a while and seems further along in some ways. At the same time, for someone that doesn't know anything (me) it's hard to even figure out how to copy files. There has to be a better way, but this is what I came up with

In Ant this would be easy, and I could be more recursive about it

<copy dir="${build.dir}" includes="**/.*py, **/.*kid, **/*.xsl"/>
or something to that effect. So for now Ant seems easier.


# THE RAKE FILE
directory "deploy/bin"
directory "deploy/pyscripts/whs"
directory "deploy/pyscripts/whs/stylesheet"
directory "deploy/pyscripts/whs/templates"

task :default => [:deploy]

file "publish.pyw" => ["publish.py"] do |f|
   cp "publish.py", f.name
end

task :publish => 'publish.pyw'

task :deploy => [:publish, "deploy/bin", "deploy/pyscripts/whs", 
    "deploy/pyscripts/whs/stylesheet", 
    "deploy/pyscripts/whs/templates"]

file "deploy/bin" do |f|
    cp Dir["**.pyw"], f.name
end

file "deploy/pyscripts/whs" do |f|
    cp Dir["whs/**.py"], f.name
end

file "deploy/pyscripts/whs/stylesheet" do |f|
    cp Dir["whs/stylesheet/**.xsl"], f.name 
end

file "deploy/pyscripts/whs/templates" do |f|
    cp Dir["whs/templates/**.kid"], f.name 
end

#END RAKE

# THE SCONS FILE
import glob
import os

environment = Environment(ENV = {'PATH' : os.environ['PATH']})

make_windows_file = environment.InstallAs('publish.pyw', 
        File('publish.py'))
copy_main = environment.Install(dir=Dir('deploy/bin'), 
        source=glob.glob("*.py[w]"))
copy_module = environment.Install(dir=Dir('deploy/pyscripts/whs'), 
        source=glob.glob("whs/*.py"))
copy_templates = environment.Install(dir=Dir('deploy/pyscripts/whs/templates'), 
        source=glob.glob("whs/templates/*.kid"))
copy_xsl = environment.Install(dir=Dir('deploy/pyscripts/whs/stylesheet'), 
        source=glob.glob("whs/stylesheet/*.xsl"))

Alias("make_windows_file", make_windows_file)
Alias("main", copy_main)
Alias("module", copy_module)
Alias("templates", copy_templates)
Alias("xsl", copy_xsl)

Default("make_windows_file", "main","module","templates","xsl")

# END SCONS

03/30/06