Sha256: 2e88c629435e7511f79744a22020fe2d9f7b2ae9931025137c2fda2004a2a5e7
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
#!/usr/bin/env ruby # encoding: UTF-8 require File.expand_path(File.dirname(__FILE__) + '/../config/boot') require 'optparse' def validate(path, flags) ap({:path => path, :flags => flags}) if flags[:debug] File.umask(002) Dir.glob("#{flags[:srcdir]}/**/*.shp") do |shp| puts "Processing #{shp}" if flags[:debug] basefn = File.basename(shp, '.shp') unless GeoHydra::Utils.shapefile?(shp) puts "SyntaxError: Not a shapefile <#{shp}>. Trying to repair..." Dir.glob("#{File.dirname(shp)}/#{basefn.gsub(' ', "\\ ")}.*") do |fn| newfn = File.join(File.dirname(fn), File.basename(fn).gsub(/[^a-zA-Z0-9_]/, '_')) FileUtils.mv fn, newfn end end end end # __MAIN__ begin flags = { :debug => false, :verbose => false, :stagedir => GeoHydra::Config.geohydra.stage || 'stage', :tmpdir => GeoHydra::Config.geohydra.tmpdir || 'tmp' } OptionParser.new do |opts| opts.banner = <<EOM Usage: #{File.basename(__FILE__)} [options] srcdir EOM opts.on("--stagedir DIR", "Staging directory to place files (default: #{flags[:stagedir]})") do |v| flags[:stagedir] = v end opts.on("--tmpdir DIR", "Temporary directory (default: #{flags[:tmpdir]})") do |v| flags[:tmpdir] = v end opts.on("-v", "--verbose", "Run verbosely") do |v| flags[:debug] = true if flags[:verbose] flags[:verbose] = true end end.parse! [:stagedir].each do |k| raise ArgumentError, "Missing directory #{flags[k]}" unless File.directory? flags[k] end flags[:srcdir] = ARGV.pop raise ArgumentError, "Missing directory #{flags[:srcdir]}" unless flags[:srcdir] and File.directory?(flags[:srcdir]) puts "Examining #{flags[:srcdir]}" if flags[:debug] validate flags[:srcdir], flags rescue SystemCallError => e $stderr.puts "ERROR: #{e.message}" exit(-1) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geohydra-0.3.3 | scripts/validate_data.rb |