Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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