#!/usr/bin/ruby require 'getoptlong' require 'ftools' require 'tempfile' #require 'rdoc/usage' opts = GetoptLong.new( [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--directory', '-d', GetoptLong::REQUIRED_ARGUMENT ], [ '--translate', '-t', GetoptLong::REQUIRED_ARGUMENT ] ) $logsPath = nil $translations = Hash.new opts.each do |opt, arg| case opt when '--translate' parts=arg.split '=' if parts.length!=2 STDERR.print "Only xxx=yyy translations accepted\n" exit 1 end $translations[parts[0]] = parts[1] print "Translate #{parts[0]}=#{parts[1]}\n" when '--directory' if !File.directory? arg STDERR.print "Not a directory: #{arg.dump}\n" exit 1 end if !(File.readable?(arg) && File.writable?(arg) && File.executable?(arg)) STDERR.print "Can't access: #{arg.dump}\n" exit 1 end $logsPath = arg+'/' when '--help' print < #{to}\n" if !File.exist? to File.copy from, to else merge from, to end end def tryTranslate(filename) $translations.each do |transFrom,transTo| re = Regexp.new('^(.*)_at_'+Regexp.escape(transFrom)+'\.history$') m = re.match(filename); if m != nil translate($logsPath+filename, $logsPath+m[1]+'_at_'+transTo+'.history') return true end end return false end Dir.foreach($logsPath) do |filename| p = $logsPath+filename if File.directory?(p) next end if File.file?(p) && File.readable?(p) if tryTranslate filename next end else STDERR.print "Can't read #{filename.dump}\n" end end