module Sys

Sys provides a number of file manipulation tools for the convenience of writing Rakefiles. All commands in this module will announce their activity on standard output if the $verbose flag is set ($verbose = true is the default). You can control this by globally setting $verbose or by using the verbose and quiet methods.

Sys has been deprecated in favor of the FileUtils module available in Ruby 1.8.

Constants

RUBY

Public Instance Methods

copy(file_name, dest_file) click to toggle source

Copy a single file from file_name to dest_file.

   # File lib/rake/contrib/sys.rb
47 def copy(file_name, dest_file)
48   log "Copying file #{file_name} to #{dest_file}"
49   File.copy(file_name, dest_file)
50 end
copy_files(wildcard, dest_dir) click to toggle source

Copy all files matching wildcard into the directory dest_dir.

   # File lib/rake/contrib/sys.rb
53 def copy_files(wildcard, dest_dir)
54   for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
55 end
delete(*wildcards) click to toggle source

Remove all files matching wildcard. If a matching file is a directory, it must be empty to be removed. used delete_all to recursively delete directories.

   # File lib/rake/contrib/sys.rb
82 def delete(*wildcards)
83   wildcards.each do |wildcard|
84     Dir[wildcard].each do |fn|
85       if File.directory?(fn)
86         log "Deleting directory #{fn}"
87         Dir.delete(fn)
88       else
89         log "Deleting file #{fn}"
90         File.delete(fn)
91       end
92     end
93   end
94 end
delete_all(*wildcards) click to toggle source

Recursively delete all files and directories matching wildcard.

    # File lib/rake/contrib/sys.rb
 97 def delete_all(*wildcards)
 98   wildcards.each do |wildcard|
 99     Dir[wildcard].each do |fn|
100       next if ! File.exist?(fn)
101       if File.directory?(fn)
102         Dir["#{fn}/*"].each do |subfn|
103           next if subfn=='.' || subfn=='..'
104           delete_all(subfn)
105         end
106         log "Deleting directory #{fn}"
107         Dir.delete(fn)
108       else
109         log "Deleting file #{fn}"
110         File.delete(fn)
111       end
112     end
113   end
114 end
for_files(*wildcards) { |fn| ... } click to toggle source

Perform a block with each file matching a set of wildcards.

    # File lib/rake/contrib/sys.rb
162 def for_files(*wildcards)
163   wildcards.each do |wildcard|
164     Dir[wildcard].each do |fn|
165       yield(fn)
166     end
167   end
168 end
indir(dir) { || ... } click to toggle source

Make dir the current working directory for the duration of executing the given block.

    # File lib/rake/contrib/sys.rb
126 def indir(dir)
127   olddir = Dir.pwd
128   Dir.chdir(dir)
129   yield
130 ensure
131   Dir.chdir(olddir)
132 end
install(wildcard, dest_dir, mode) click to toggle source

Install all the files matching wildcard into the dest_dir directory. The permission mode is set to mode.

   # File lib/rake/contrib/sys.rb
29 def install(wildcard, dest_dir, mode)
30   Dir[wildcard].each do |fn|
31     File.install(fn, dest_dir, mode, $verbose)
32   end
33 end
log(msg) click to toggle source

Write a message to standard error if $verbose is enabled.

    # File lib/rake/contrib/sys.rb
146 def log(msg)
147   print "  " if $trace && $verbose
148   $stderr.puts msg if $verbose
149 end
makedirs(*dirs) click to toggle source

Make the directories given in dirs.

    # File lib/rake/contrib/sys.rb
117 def makedirs(*dirs)
118   dirs.each do |fn|
119     log "Making directory #{fn}"
120     File.makedirs(fn)
121   end
122 end
quiet(&block) click to toggle source

Perform a block with $verbose disabled.

    # File lib/rake/contrib/sys.rb
152 def quiet(&block)
153   with_verbose(false, &block)
154 end
ruby(*args) click to toggle source

Run a Ruby interpreter with the given arguments.

   # File lib/rake/contrib/sys.rb
42 def ruby(*args)
43   run "#{RUBY} #{args.join(' ')}"
44 end
run(cmd) click to toggle source

Run the system command cmd.

   # File lib/rake/contrib/sys.rb
36 def run(cmd)
37   log cmd
38   system(cmd) or fail "Command Failed: [#{cmd}]"
39 end
split_all(path) click to toggle source

Split a file path into individual directory names.

For example:

split_all("a/b/c") =>  ['a', 'b', 'c']
    # File lib/rake/contrib/sys.rb
138 def split_all(path)
139   head, tail = File.split(path)
140   return [tail] if head == '.' || tail == '/'
141   return [head, tail] if head == '/'
142   return split_all(head) + [tail]
143 end
verbose(&block) click to toggle source

Perform a block with $verbose enabled.

    # File lib/rake/contrib/sys.rb
157 def verbose(&block)
158   with_verbose(true, &block)
159 end