forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscheck.rb
82 lines (72 loc) · 1.93 KB
/
transcheck.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Author: Pavel 'argent-smith' Argentov <[email protected]>
#
# Serves leader/translations sync check for web.rake (see web:translations:check).
class Transcheck
attr_reader :leader, :tr_list
attr_accessor :verbose
# Takes leader dirname, a list of translation language codes and an optional
# verbosity flag.
def initialize(l, trl, v = false)
@leader = l
@tr_list = trl
@bugs = {}
@verbose = v
@base, @llcode = File.split l
end
# Fires up the recursive directories check.
def check
puts "\nTRANSLATION CHECK: Checking '#{@leader}' recursively against #{@tr_list.join ", "} versions\n\n" if @verbose
check_recursive @leader
end
# Prints the overall detection status and stats.
def status
@bugs.size == 0 ? ok : nb
end
private
# Recursive check per se.
def check_recursive lname
unless (File.split lname).last =~ /^\.{1,2}$/
if File.directory? lname
Dir.new(lname).each do |n|
check_recursive File.join(lname, n)
end
else
@tr_list.each do |lcode|
tfname = File.join @base, lcode, (lname.gsub leader, '')
if File.exist? tfname
@bugs[lname] = "is younger than its '#{lcode}' version" if File.mtime(tfname) < File.mtime(lname)
else
@bugs[lname] = "doesn't exist in '#{lcode}' edition"
end
end
end
end
end
# Says OK and explains this trouble.
def ok
puts "OK: Everything in #{@tr_list.to_s} is in sync with the leader '#{@leader}'\n\n"
end
# Notice the Bugs!
def nb
puts "NB:"
bugs
end
# Displays found bugs.
def bugs
[
[/doesn't exist/, "LOST"],
[/younger/, "LAG"]
].each do |re,lbl|
if (hsh = @bugs.select do |k,v|
v =~ re
end).size > 0
puts "\n #{lbl} IN TRANSLATION:"
hsh.each do |bug|
puts " " + (bug.join ": ")
end
puts
end
end
end
end