|
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.
| Methods |
| Public Instance methods |
| copy(file_name, dest_file) |
Copy a single file from file_name to dest_file.
# File lib/rake/contrib/sys.rb, line 65
65: def copy(file_name, dest_file)
66: log "Copying file #{file_name} to #{dest_file}"
67: File.copy(file_name, dest_file)
68: end
| copy_files(wildcard, dest_dir) |
Copy all files matching wildcard into the directory dest_dir.
# File lib/rake/contrib/sys.rb, line 71
71: def copy_files(wildcard, dest_dir)
72: for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
73: 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.
# File lib/rake/contrib/sys.rb, line 100
100: def delete(*wildcards)
101: wildcards.each do |wildcard|
102: Dir[wildcard].each do |fn|
103: if File.directory?(fn)
104: log "Deleting directory #{fn}"
105: Dir.delete(fn)
106: else
107: log "Deleting file #{fn}"
108: File.delete(fn)
109: end
110: end
111: end
112: end
| delete_all(*wildcards) |
Recursively delete all files and directories matching wildcard.
# File lib/rake/contrib/sys.rb, line 115
115: def delete_all(*wildcards)
116: wildcards.each do |wildcard|
117: Dir[wildcard].each do |fn|
118: next if ! File.exist?(fn)
119: if File.directory?(fn)
120: Dir["#{fn}/*"].each do |subfn|
121: next if subfn=='.' || subfn=='..'
122: delete_all(subfn)
123: end
124: log "Deleting directory #{fn}"
125: Dir.delete(fn)
126: else
127: log "Deleting file #{fn}"
128: File.delete(fn)
129: end
130: end
131: end
132: end
| for_files(*wildcards) {|fn| ...} |
Perform a block with each file matching a set of wildcards.
# File lib/rake/contrib/sys.rb, line 180
180: def for_files(*wildcards)
181: wildcards.each do |wildcard|
182: Dir[wildcard].each do |fn|
183: yield(fn)
184: end
185: end
186: end
| indir(dir) {|| ...} |
Make dir the current working directory for the duration of executing the given block.
# File lib/rake/contrib/sys.rb, line 144
144: def indir(dir)
145: olddir = Dir.pwd
146: Dir.chdir(dir)
147: yield
148: ensure
149: Dir.chdir(olddir)
150: end
| install(wildcard, dest_dir, mode) |
Install all the files matching wildcard into the dest_dir directory. The permission mode is set to mode.
# File lib/rake/contrib/sys.rb, line 47
47: def install(wildcard, dest_dir, mode)
48: Dir[wildcard].each do |fn|
49: File.install(fn, dest_dir, mode, $verbose)
50: end
51: end
| link(file_name, dest_file) |
Link file_name to dest_file.
# File lib/rake/contrib/sys.rb, line 76
76: def link(file_name, dest_file)
77: log "Linking file #{file_name} to #{dest_file}"
78: File.link(file_name, dest_file)
79: end
| link_files(wildcard, dest_dir) |
Link all files matching wildcard into the directory dest_dir.
# File lib/rake/contrib/sys.rb, line 82
82: def link_files(wildcard, dest_dir)
83: for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
84: end
| log(msg) |
Write a message to standard out if $verbose is enabled.
# File lib/rake/contrib/sys.rb, line 164
164: def log(msg)
165: print " " if $trace && $verbose
166: puts msg if $verbose
167: end
| makedirs(*dirs) |
Make the directories given in dirs.
# File lib/rake/contrib/sys.rb, line 135
135: def makedirs(*dirs)
136: dirs.each do |fn|
137: log "Making directory #{fn}"
138: File.makedirs(fn)
139: end
140: end
| quiet(&block) |
Perform a block with $verbose disabled.
# File lib/rake/contrib/sys.rb, line 170
170: def quiet(&block)
171: with_verbose(false, &block)
172: end
| ruby(*args) |
Run a Ruby interpreter with the given arguments.
# File lib/rake/contrib/sys.rb, line 60
60: def ruby(*args)
61: run "#{RUBY} #{args.join(' ')}"
62: end
| run(cmd) |
Run the system command cmd.
# File lib/rake/contrib/sys.rb, line 54
54: def run(cmd)
55: log cmd
56: system(cmd) or fail "Command Failed: [#{cmd}]"
57: end
| split_all(path) |
Split a file path into individual directory names.
For example:
split_all("a/b/c") => ['a', 'b', 'c']
# File lib/rake/contrib/sys.rb, line 156
156: def split_all(path)
157: head, tail = File.split(path)
158: return [tail] if head == '.' || tail == '/'
159: return [head, tail] if head == '/'
160: return split_all(head) + [tail]
161: end
| symlink(file_name, dest_file) |
Symlink file_name to dest_file.
# File lib/rake/contrib/sys.rb, line 87
87: def symlink(file_name, dest_file)
88: log "Symlinking file #{file_name} to #{dest_file}"
89: File.symlink(file_name, dest_file)
90: end
| symlink_files(wildcard, dest_dir) |
Symlink all files matching wildcard into the directory dest_dir.
# File lib/rake/contrib/sys.rb, line 93
93: def symlink_files(wildcard, dest_dir)
94: for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
95: end
| verbose(&block) |
Perform a block with $verbose enabled.
# File lib/rake/contrib/sys.rb, line 175
175: def verbose(&block)
176: with_verbose(true, &block)
177: end