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
Source
# 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 a single file from file_name
to dest_file
.
Source
# 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
Copy all files matching wildcard
into the directory dest_dir
.
Source
# 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
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 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
Recursively delete all files and directories matching wildcard
.
Source
# 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
Perform a block with each file matching a set of wildcards.
Source
# 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
Make dir
the current working directory for the duration of executing the given block.
Source
# 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
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 58 def link(file_name, dest_file) 59 log "Linking file #{file_name} to #{dest_file}" 60 File.link(file_name, dest_file) 61 end
Link file_name
to dest_file
.
Source
# File lib/rake/contrib/sys.rb 64 def link_files(wildcard, dest_dir) 65 for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) } 66 end
Link all files matching wildcard
into the directory dest_dir
.
Source
# File lib/rake/contrib/sys.rb 146 def log(msg) 147 print " " if $trace && $verbose 148 $stderr.puts msg if $verbose 149 end
Write a message to standard error if $verbose is enabled.
Source
# 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
Make the directories given in dirs
.
Source
# File lib/rake/contrib/sys.rb 152 def quiet(&block) 153 with_verbose(false, &block) 154 end
Perform a block with $verbose disabled.
Source
# File lib/rake/contrib/sys.rb 42 def ruby(*args) 43 run "#{RUBY} #{args.join(' ')}" 44 end
Run a Ruby interpreter with the given arguments.
Source
# File lib/rake/contrib/sys.rb 36 def run(cmd) 37 log cmd 38 system(cmd) or fail "Command Failed: [#{cmd}]" 39 end
Run the system command cmd
.
Source
# 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
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 69 def symlink(file_name, dest_file) 70 log "Symlinking file #{file_name} to #{dest_file}" 71 File.symlink(file_name, dest_file) 72 end
Symlink file_name
to dest_file
.
Source
# File lib/rake/contrib/sys.rb 75 def symlink_files(wildcard, dest_dir) 76 for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) } 77 end
Symlink all files matching wildcard
into the directory dest_dir
.
Source
# File lib/rake/contrib/sys.rb 157 def verbose(&block) 158 with_verbose(true, &block) 159 end
Perform a block with $verbose enabled.