def run
package_dir_path = "#{@dir}/#{@package_name}"
if FileTest.directory?(package_dir_path)
print "Package '#{package_name}' already exists. Clobber? [y/N] "
until inp = $stdin.gets[0,1] ; sleep 1 ; end
if (inp || 'y').downcase == 'y'
puts "Removing old directory '#{File.expand_path(package_dir_path)}'..."
FileUtils.rm_r(package_dir_path)
else
puts "Reap package task canceled."
exit 0
end
end
package_files = FileList.new
package_files.include(*@include)
package_files.exclude(*@exclude) if @exclude and not @exclude.empty?
FileUtils.mkdir_p @dir
package_files.each do |f|
pkgf = File.join(package_dir_path, f)
fdir = File.dirname(pkgf)
FileUtils.mkdir_p(fdir) if not File.exist?(fdir)
if File.directory?(f)
FileUtils.mkdir_p(pkgf)
else
FileUtils.rm_f(pkgf)
FileUtils.safe_ln(f, pkgf)
end
end
FileUtils.chdir(@dir) do
@types.each do |t|
sh_cmd = nil
prefix = 'ERROR'
case t
when 'tbz', 'bz2', 'bzip2', 'tar.bz2'
prefix = ( t == 'tbz' ? 'tbz' : 'tar.bz2' )
sh_cmd = 'tar --bzip2 -cvf'
puts "\nReap is shelling out work to tar and bzip2..."
when 'tgz', 'tar.gz'
prefix = ( t == 'tgz' ? 'tgz' : 'tar.gz' )
sh_cmd = 'tar --gzip -cvf'
puts "\nReap is shelling out work to tar and gzip..."
when 'zip'
prefix = 'zip'
sh_cmd = 'zip -r'
puts "\nReap is shelling out work to zip..."
when 'gem'
sh_cmd = nil
else
puts "Unknown package type '#{t}' skipped."
sh_cmd = nil
end
sh %{#{sh_cmd} #{@package_name}.#{prefix} #{@package_name}} if sh_cmd
end
puts
end
run_gem if defined?(Gem) and @types.include?('gem')
return true
end