serDiff - Language file merge tool

muarifer

Verified User
Joined
Jan 28, 2009
Messages
10
Hello,

I coded a small tool for merge languages files with Ruby.

After DirectAdmin updates, if the string is not in your own language file (maybe new added line or new file) the view of directadmin broken up.

The tool, add new lines from original files to own language files. Also, copy new files to own language directories.

It is coded in Ruby with power of 'wc' and 'tail' command.
It tested with ruby 1.8.7.

Example log:
Code:
Y admin/admin_cron_jobs.html
D admin/admin_settings.html : 9
Y admin/brute_force_ip_info.html
Y admin/brute_force_monitor.html
D admin/content_main.html : 3
D admin/create_reseller.html : 3
Y means 'new file', 'D' means new lines (also show how many lines added up)

Usage:
Code:
ruby serdiff.rb ORG-LANG-DIR OWN-LANG-DIR
serDiff.rb
Code:
# serDiff.rb
# directadmin dil dosyalari guncelleme araci
#
# SERENAY YAZILIM
# www.serenay.net.tr | info (@) serenay.net.tr
#
# 0.1 - 01/09/2011
#

# gerekli parametreler
#
if ARGV.length != 2
  puts "Kullanım: serdiff.rb orj-dir lang-dir"
  exit
end

$klasor1 = ARGV[0]    # orjinal directadmin dil klasoru
$klasor2 = ARGV[1]    # cevirilerimizin oldugu klasor
['find', 'ftools', 'fileutils'].each { |req| require req }

# dosyadaki satir sayisini dondurur
# performans icin 'wc' tercih edildi
#
def satir_adet(dosya, klasor) 
  count = `wc -l < #{klasor}#{dosya}`
  return Integer(count.chomp)
end

# son eklenen satirlari mevcut dosyamiza aliyoruz
# not: sistem hic satir silinmeme uzerine kurulu
#
def satir_kopyala(dosya, adet)
  `tail -n#{adet} #{$klasor1}#{dosya} >> #{$klasor2}#{dosya}`
end

# bizde olmayan dosyalari, klasor yapisina sadik kalarak 
# kopyaliyoruz
#
def dosya_kopyala(dosya) 
  klasor = File.dirname(dosya)
  hedef_klasor = "#{$klasor2}#{klasor}"
  unless File.exists?(hedef_klasor) 
    Dir.mkdir(hedef_klasor) 
    puts "K #{$klasor2}#{klasor}"
  end
  File.copy("#{$klasor1}#{dosya}", hedef_klasor)
end

# serDiff.rb
#
arr1, arr2 = [], []
Find.find($klasor1) { |file| arr1 << file.slice($klasor1.length..-1) unless File.directory?(file) }
Find.find($klasor2) { |file| arr2 << file.slice($klasor2.length..-1) unless File.directory?(file) }
[arr1, arr2].each { |arr| arr.sort! }

arr1.each do |file|
  
  if arr2.include?(file)
    # yeni eklenen satırlar
    adet1 = satir_adet(file, $klasor1)
    adet2 = satir_adet(file, $klasor2)
    if adet1 > adet2
      fark = adet1-adet2
      puts "D #{file} : #{adet1-adet2}"
      satir_kopyala(file, fark)
    end
  else
    # yeni eklenen dosyalar
    puts "Y #{file}"
    dosya_kopyala(file)
  end
  
end
 

muarifer

Verified User
Joined
Jan 28, 2009
Messages
10
1. All the stdout text is written in your native language
Just to clarify. The aren't any stdout texts in my native language (Turkish) or any language.
# lines are Ruby comments. The tool only print this texts:

  1. Y FILENAME means new file
  2. D FILENAME : COUNT means added COUNT lines end of FILENAME
  3. K DIR means created a new directory

2. Its written in the ruby programming language
I don't think it's a problem. I like coding with Ruby language.
 
Top