2006-09-14

Automatization

At last, I had enough time to automate the site update. The problem is quite simple - there is a certain number of html pages, which should be changed at a local server from time to time, then wait for the confirmation of the maden changes and send it to the Internet. I would like to have one big button for that purpose, because I'm lazy to synchronize sites, get accustomed to an external tool... since the problem is exactly for make utility. The only trouble is that I've completely forgotten what does the magic symbols ($@ $^ and so on) mean.

But there is more easy way.

By chance I came across Martin Fowler article about the magic rake utility, used for building projects in ruby. More fifteen minutes of ruby functions googling and voila:

require 'rake' 
require 'find'

task :default => :copychanges
task :copychanges do
print "all done"
end

Find.find('src/') do |srcfile|
target = srcfile.sub(/^src/,'data')
changes = srcfile.sub(/^src/,'changes')
file target => srcfile do
if test(?f, srcfile)
cp srcfile, target cp srcfile, changes
else
mkdir_p target mkdir_p changes
end
end
task :copychanges => target
end



Make changes in the folder src/, store the copy in the folder data/, by rake command new changes are moved to the folder changes.

No comments:

Post a Comment