Module | Sys
In: | lib/rake/contrib/sys.rb

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.

### Methods

copy copy_files delete delete_all for_files indir install link link_files log makedirs quiet ruby run split_all symlink symlink_files verbose

### Constants

RUBY | = | Config::CONFIG['ruby_install_name']

### Public Instance methods

copy(file_name, dest_file)

Copy a single file from `file_name` to `dest_file`.

[Source]

        # File lib/rake/contrib/sys.rb, line 62
    62:   def copy(file_name, dest_file)
    63:     log "Copying file #{file_name} to #{dest_file}"
    64:     File.copy(file_name, dest_file)
    65:   end

copy_files(wildcard, dest_dir)

Copy all files matching `wildcard` into the directory `dest_dir`.

[Source]

        # File lib/rake/contrib/sys.rb, line 68
    68:   def copy_files(wildcard, dest_dir)
    69:     for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
    70:   end

delete(*wildcards)

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.

[Source]

         # File lib/rake/contrib/sys.rb, line 97
     97:   def delete(*wildcards)
     98:     wildcards.each do |wildcard|
     99:       Dir[wildcard].each do |fn|
    100:         if File.directory?(fn)
    101:           log "Deleting directory #{fn}"
    102:           Dir.delete(fn)
    103:         else
    104:           log "Deleting file #{fn}"
    105:           File.delete(fn)
    106:         end
    107:       end
    108:     end
    109:   end

delete_all(*wildcards)

Recursively delete all files and directories matching `wildcard`.

[Source]

         # File lib/rake/contrib/sys.rb, line 112
    112:   def delete_all(*wildcards)
    113:     wildcards.each do |wildcard|
    114:       Dir[wildcard].each do |fn|
    115:         next if ! File.exist?(fn)
    116:         if File.directory?(fn)
    117:           Dir["#{fn}/*"].each do |subfn|
    118:             next if subfn=='.' || subfn=='..'
    119:             delete_all(subfn)
    120:           end
    121:           log "Deleting directory #{fn}"
    122:           Dir.delete(fn)
    123:         else
    124:           log "Deleting file #{fn}"
    125:           File.delete(fn)
    126:         end
    127:       end
    128:     end
    129:   end

for_files(*wildcards) {|fn| ...}

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

[Source]

         # File lib/rake/contrib/sys.rb, line 177
    177:   def for_files(*wildcards)
    178:     wildcards.each do |wildcard|
    179:       Dir[wildcard].each do |fn|
    180:         yield(fn)
    181:       end
    182:     end
    183:   end

indir(dir) {|| ...}

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

[Source]

         # File lib/rake/contrib/sys.rb, line 141
    141:   def indir(dir)
    142:     olddir = Dir.pwd
    143:     Dir.chdir(dir)
    144:     yield
    145:   ensure
    146:     Dir.chdir(olddir)
    147:   end

install(wildcard, dest_dir, mode)

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

[Source]

        # File lib/rake/contrib/sys.rb, line 44
    44:   def install(wildcard, dest_dir, mode)
    45:     Dir[wildcard].each do |fn|
    46:       File.install(fn, dest_dir, mode, $verbose)
    47:     end
    48:   end

link(file_name, dest_file)

Link `file_name` to `dest_file`.

[Source]

        # File lib/rake/contrib/sys.rb, line 73
    73:   def link(file_name, dest_file)
    74:     log "Linking file #{file_name} to #{dest_file}"
    75:     File.link(file_name, dest_file)
    76:   end

link_files(wildcard, dest_dir)

Link all files matching `wildcard` into the directory `dest_dir`.

[Source]

        # File lib/rake/contrib/sys.rb, line 79
    79:   def link_files(wildcard, dest_dir)
    80:     for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
    81:   end

log(msg)

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

[Source]

         # File lib/rake/contrib/sys.rb, line 161
    161:   def log(msg)
    162:     print "  " if $trace && $verbose
    163:     puts msg if $verbose
    164:   end

makedirs(*dirs)

Make the directories given in `dirs`.

[Source]

         # File lib/rake/contrib/sys.rb, line 132
    132:   def makedirs(*dirs)
    133:     dirs.each do |fn|
    134:       log "Making directory #{fn}"
    135:       File.makedirs(fn)
    136:     end
    137:   end

quiet(&block)

Perform a block with $verbose disabled.

[Source]

         # File lib/rake/contrib/sys.rb, line 167
    167:   def quiet(&block)
    168:     with_verbose(false, &block)
    169:   end

ruby(*args)

Run a Ruby interpreter with the given arguments.

[Source]

        # File lib/rake/contrib/sys.rb, line 57
    57:   def ruby(*args)
    58:     run "#{RUBY} #{args.join(' ')}"
    59:   end

run(cmd)

Run the system command `cmd`.

[Source]

        # File lib/rake/contrib/sys.rb, line 51
    51:   def run(cmd)
    52:     log cmd
    53:     system(cmd) or fail "Command Failed: [#{cmd}]"
    54:   end

split_all(path)

Split a file path into individual directory names.

For example:

      split_all("a/b/c") =>  ['a', 'b', 'c']

[Source]

         # File lib/rake/contrib/sys.rb, line 153
    153:   def split_all(path)
    154:     head, tail = File.split(path)
    155:     return [tail] if head == '.' || tail == '/'
    156:     return [head, tail] if head == '/'
    157:     return split_all(head) + [tail]
    158:   end

symlink(file_name, dest_file)

Symlink `file_name` to `dest_file`.

[Source]

        # File lib/rake/contrib/sys.rb, line 84
    84:   def symlink(file_name, dest_file)
    85:     log "Symlinking file #{file_name} to #{dest_file}"
    86:     File.symlink(file_name, dest_file)
    87:   end

symlink_files(wildcard, dest_dir)

Symlink all files matching `wildcard` into the directory `dest_dir`.

[Source]

        # File lib/rake/contrib/sys.rb, line 90
    90:   def symlink_files(wildcard, dest_dir)
    91:     for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
    92:   end

verbose(&block)

Perform a block with $verbose enabled.

[Source]

         # File lib/rake/contrib/sys.rb, line 172
    172:   def verbose(&block)
    173:     with_verbose(true, &block)
    174:   end

[Validate]