#!/usr/bin/ruby # This script walks the directory tree where I store my NGS Topo! # files and copies everything to a flash card so the Android # Atopo program can find them organized in a way that I like. # If you are using this you will almost certainly have to # edit the "target" variable to indicate the location of # your SD card. After doing that I do this: # # mkdir /run/media/tom/aaaa-bbbb/topo # cd /u1/topo # ./copy_maps_android # # Note that I make the "topo" directory on the SD card by hand. #$card = "/u1/topo/sdcard" #$card = "/run/media/tom/4CC0-7E18" #$card = "/run/media/tom/F009-64A5" #$card = "/run/media/tom/3232-3465" # for Mark Patton #$card = "/run/media/tom/3165-3630" # micro SD card 4-6-2014 #$card = "/run/media/tom/3433-3935" # for Jerry Baird #$card = "/run/media/tom/6634-6636" #$card = "/mnt/flash" # For LG tablet $card = "/run/media/tom/3930-6232" # I find that SD card to USB readers are really fussy with micro SD cards. # The little micro SD to SD adapters they always send have proven useless. # The only setup I have that works in my little multi card adapter. # the micro SD inserts into the slot labelled "T" unless FileTest.exist? $card puts "Cannot find flash card: " + $card exit end unless FileTest.writable? $card puts "flash card is not writeable: " + $card exit end $target = $card + "/topo" unless FileTest.directory? $target begin Dir.mkdir $target rescue puts "Cannot create target directory: " + $target exit end end unless FileTest.directory? $target puts "Cannot find/make target directory: " + $target exit; end def make_level ( lname ) td = $target + "/" + lname unless FileTest.exist? td Dir.mkdir td end unless FileTest.directory? td puts "Problem: " + td exit; end return td end $l3 = make_level "l3" $l4 = make_level "l4" $l5 = make_level "l5" def copyfile ( path, target ) if ( target ) # we may already have copied this one. if FileTest.exists? target print path + " -- " + target + " (DUPLICATE)\n" # XXX could do a cmp here, # but I just accept the first file I find. return end cmd = "cp #{path} #{target}" puts cmd begin system cmd system "chmod 444 #{target}" rescue puts "IO error writing: #{target}" exit end end end def process ( path, name ) lname = name.downcase lpath = path.downcase return if lname !~ /tpq$/ if ( lpath =~ /map[12]/ ) print path + " -- " + lname + " (SKIP)\n" return end if ( lpath =~ /l3buffer/ ) print path + " -- " + lname + " (SKIP)\n" return end # Skip these, they are level 3 maps included in # certain state sets, but the same coverage # (and for the entire nation) is # provided by "g" files in the SI directory if ( lname =~ /^f/ ) print path + " -- " + lname + " (SKIP)\n" return end # Alaska 250K if ( lname =~ /^y/ ) print path + " -- " + lname + " (SKIP - Alaska)\n" return end # Alaska 250K if ( lname =~ /^a/ ) print path + " -- " + lname + " (SKIP - Alaska)\n" return end target = nil # 500K from SI group if ( lname =~ /^g/ ) target = "#{$l3}/#{lname}" end # 100K # XXX - this also moves "CAL*" if ( lname =~ /^c/ or lname =~ /^k/ ) lname[0] = "c" target = "#{$l4}/#{lname}" end # 24K if ( lname =~ /^n/ or lname =~ /^q/ ) lname[0] = "n" target = "#{$l5}/#{lname}" end copyfile path, target end def walk ( path, name ) if FileTest.directory? path puts path + "/" else # leaf process path, name return end Dir.foreach(path) { |x| next if x == "." next if x == ".." walk path + "/" + x, x } end # XXX These two are for level 1 and 2, this is where they are # (and the case they are in) on my hard drive, but ... copyfile( "./SI_D01/USMAPS/US1_MAP1.tpq", "#{$target}/us1map1.tpq" ) copyfile( "./SI_D01/USMAPS/US1_MAP2.tpq", "#{$target}/us1map2.tpq" ) walk ".", "" # THE END