Sha256: c70fa2cc06f195f05d88123faf3d719ba924349f7bb58da32a4d21e50544e71c

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 KB

Contents

# stdlib
require 'fileutils'

def recursive_run( dir, &block )
  block.call( dir )
  Dir.entries( dir ).each { |entry|
    next if entry == "." or entry == ".."
    next if not FileTest.directory?( dir + File::Separator + entry )
    next if $config.ignore_dir( entry )
    recursive_run( dir + File::Separator + entry, block )
  }
end

def copy_dir( indir, outdir, re )
  if not File.directory?(indir)
    raise "#{indir} is not a directory"
  end
  if not File.directory?( outdir )
    FileUtils.mkpath( outdir )
  end
  Dir.entries( indir ).each { |e|
    if e.match( re )
      from = File.join( indir,  e )
      to   = File.join( outdir, e )
      # puts "#{from}  #{to}"
      if File.exist?(to) and File.mtime(from) <= File.mtime(to)
        next
      end
      FileUtils.cp from, to
    end
  }
end

def copy_file( inpath, outdir )
  from = inpath
  to   = File.join( outdir, File.basename( from ) )
  # puts "#{from}  #{to}"
  if File.exist?(to) and File.mtime(from) <= File.mtime(to)
    next
  end
  FileUtils.cp from, to
end

#
# substitute into a file
#
def subfile( filename, map )
  lines = IO.readlines( filename)
  if $options.backup
    FileUtils.mv( filename, filename + ".bck" )
  end

  lines.each_with_index { |l,i|
    map.each { |l1, l2|
      #puts "#{l} #{l1} #{l.index(l1)}"
      if l.index( l1 ) == 0
        puts "subst #{l1}"
        lines[i] = l2
      end
    }
  }

  File.open( filename,  "w" ) { |f|
    lines.each{ |l| f.puts l }
  }
  puts "patched #{filename}"

rescue Errno::ENOENT => e
  puts "file not found '#{filename}'"
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gf-treevisitor-0.0.10 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.11 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.12 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.13 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.15 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.16 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.18 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.19 lib/gf_utilities/file_utilities.rb
gf-treevisitor-0.0.8 lib/gf_utilities/file_utilities.rb