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
- C
-
- D
-
- F
-
- I
-
- L
-
- M
-
- Q
-
- R
-
- S
-
- V
-
Constants
RUBY |
= |
RbConfig::CONFIG['ruby_install_name'] |
|
|
Instance Public methods
copy(file_name, dest_file)
Link
Copy a single file from file_name
to dest_file
.
Source:
show
| on GitHub
def copy(file_name, dest_file)
log "Copying file #{file_name} to #{dest_file}"
File.copy(file_name, dest_file)
end
copy_files(wildcard, dest_dir)
Link
Copy all files matching wildcard
into the directory
dest_dir
.
Source:
show
| on GitHub
def copy_files(wildcard, dest_dir)
for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
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:
show
| on GitHub
def delete(*wildcards)
wildcards.each do |wildcard|
FileList.glob(wildcard).each do |fn|
if File.directory?(fn)
log "Deleting directory #{fn}"
Dir.delete(fn)
else
log "Deleting file #{fn}"
File.delete(fn)
end
end
end
end
delete_all(*wildcards)
Link
Recursively delete all files and directories matching
wildcard
.
Source:
show
| on GitHub
def delete_all(*wildcards)
wildcards.each do |wildcard|
FileList.glob(wildcard).each do |fn|
next if ! File.exist?(fn)
if File.directory?(fn)
FileList.glob("#{fn}/*").each do |subfn|
next if subfn=='.' || subfn=='..'
delete_all(subfn)
end
log "Deleting directory #{fn}"
Dir.delete(fn)
else
log "Deleting file #{fn}"
File.delete(fn)
end
end
end
end
for_files(*wildcards)
Link
Perform a block with each file matching a set of wildcards.
Source:
show
| on GitHub
def for_files(*wildcards)
wildcards.each do |wildcard|
FileList.glob(wildcard).each do |fn|
yield(fn)
end
end
end
Make dir
the current working directory for the duration of
executing the given block.
Source:
show
| on GitHub
def indir(dir)
olddir = Dir.pwd
Dir.chdir(dir)
yield
ensure
Dir.chdir(olddir)
end
install(wildcard, dest_dir, mode)
Link
Install all the files matching wildcard
into the
dest_dir
directory. The permission mode is set to
mode
.
Source:
show
| on GitHub
def install(wildcard, dest_dir, mode)
FileList.glob(wildcard).each do |fn|
File.install(fn, dest_dir, mode, $verbose)
end
end
link(file_name, dest_file)
Link
Link file_name
to dest_file
.
Source:
show
| on GitHub
def link(file_name, dest_file)
log "Linking file #{file_name} to #{dest_file}"
File.link(file_name, dest_file)
end
link_files(wildcard, dest_dir)
Link
Link all files matching wildcard
into the directory
dest_dir
.
Source:
show
| on GitHub
def link_files(wildcard, dest_dir)
for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
end
Write a message to standard error if $verbose is enabled.
Source:
show
| on GitHub
def log(msg)
print " " if $trace && $verbose
$stderr.puts msg if $verbose
end
Make the directories given in dirs
.
Source:
show
| on GitHub
def makedirs(*dirs)
dirs.each do |fn|
log "Making directory #{fn}"
File.makedirs(fn)
end
end
Perform a block with $verbose disabled.
Source:
show
| on GitHub
def quiet(&block)
with_verbose(false, &block)
end
Run a Ruby interpreter with the given arguments.
Source:
show
| on GitHub
def ruby(*args)
run "#{RUBY} #{args.join(' ')}"
end
Run the system command cmd
.
Source:
show
| on GitHub
def run(cmd)
log cmd
system(cmd) or fail "Command Failed: [#{cmd}]"
end
Split a file path into individual directory names.
For example:
split_all("a/b/c") => ['a', 'b', 'c']
Source:
show
| on GitHub
def split_all(path)
head, tail = File.split(path)
return [tail] if head == '.' || tail == '/'
return [head, tail] if head == '/'
return split_all(head) + [tail]
end
symlink(file_name, dest_file)
Link
Symlink file_name
to dest_file
.
Source:
show
| on GitHub
def symlink(file_name, dest_file)
log "Symlinking file #{file_name} to #{dest_file}"
File.symlink(file_name, dest_file)
end
symlink_files(wildcard, dest_dir)
Link
Symlink all files matching wildcard
into the directory
dest_dir
.
Source:
show
| on GitHub
def symlink_files(wildcard, dest_dir)
for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
end
Perform a block with $verbose enabled.
Source:
show
| on GitHub
def verbose(&block)
with_verbose(true, &block)
end