-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
206 lines (180 loc) · 7.81 KB
/
Rakefile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
require 'fileutils'
require 'yaml'
tracing = (Rake.application.options.trace)?"--trace":""
verbose = (Rake.application.options.verbose)?"--verbose":""
require 'rake'
def sudo(cmd)
puts "#{cmd}"
%x[sudo -p "Password: " #{cmd}]
end
#
# recognized variables
#
vars = ['PKG_BUILD', 'RCOV_PARAMS', 'RAILS_ENV', 'RAILS_PARENT']
ENV['RAILS_PARENT'] = File.join(Dir.pwd, 'webservice')
env = ENV.map { |key,val| (ENV[key] && vars.include?( key )) ? %(#{key}="#{ENV[key]}") : nil }.compact.join(' ')
#
# Pick up the plugins as PROJECTS
#
plugins = Dir.glob('plugins/*')#.reject{|x| ['users'].include?(File.basename(x))}
PROJECTS = ['webservice', *plugins]
desc 'Run all tests by default'
task :default => :test
#
# list of common tasks, being run for every plugin
#
%w(notes test makemo updatepot rdoc pgem package release install install_policies check_syntax package-local buildrpm buildrpm-local test:test:rcov restdoc deploy_local license:report).each do |task_name|
desc "Run #{task_name} task for all projects"
task task_name do
PROJECTS.each do |project|
Dir.chdir(project) do
if File.exist? "Rakefile"
system %(#{env} #{$0} #{tracing} #{task_name})
raise "Error on execute '#{$0} #{tracing} #{verbose} #{task_name}' inside #{project}/" if $?.exitstatus != 0
end
end
end
end
end
desc "Fetch po files from lcn. Parameter: source directory of lcn e.g. ...lcn/trunk/"
task :fetch_po, [:lcn_dir] do |t, args|
args.with_defaults(:lcn_dir => File.join(File.dirname(__FILE__),"../../", "lcn", "trunk"))
#remove translation statistik
File.delete(File.join("pot", "translation_status.yaml")) if File.exist?("pot/translation_status.yaml")
result = Hash.new()
task_name = "fetch_po"
PROJECTS.each do |project|
Dir.chdir project do
if File.exist? "Rakefile" #avoid endless loop if directory doesn't contain Rakefile
system %(#{env} #{$0} #{task_name}[#{args.lcn_dir}] )
raise "Error on execute task #{task_name} on #{project}" if $?.exitstatus != 0
end
end
#collecting translation information
Dir.glob("#{project}/**/*.po").each {|po_file|
output = `LANG=C msgfmt -o /dev/null -c -v --statistics #{po_file} 2>&1`
language = File.basename(File.dirname(po_file))
output.split(",").each {|column|
value = column.split(" ")
if value.size > 2
if result.has_key? language
if result[language].has_key? value[1]
result[language][value[1]] += value[0].to_i
else
result[language][value[1]] = value[0].to_i
end
else
result[language] = Hash.new
result[language][value[1]] = value[0].to_i
end
end
}
}
end
#saving result to pot/translation_status.yaml
destdir = File.join(File.dirname(__FILE__), "pot")
Dir.mkdir destdir unless File.directory?(destdir)
f = File.open(File.join(destdir, "translation_status.yaml"), "w")
f.write(result.to_yaml)
f.close
#remove translations which have not at least 80 percent translated text
limit = Float(80)
result.each {|key,value|
translated = un_translated = Float(0)
translated = value["translated"].to_f if value.has_key? "translated"
un_translated += value["untranslated"].to_f if value.has_key? "untranslated"
un_translated += value["fuzzy"].to_f if value.has_key? "fuzzy"
limit_eval = translated/(un_translated+translated)
if limit_eval < limit/100
puts "Language #{key} should be deleted cause it has only #{(limit_eval*100).to_i} percent translation reached."
Dir.glob("**/#{key}/").each {|po_dir|
unless po_dir.include? "lang_helper" #do not delete translations for language selections
# puts "deleting #{po_dir}"
# remove_dir(po_dir, true) #force=true
end
}
end
}
end
desc "Run doc to generate whole documentation"
task :doc do
#clean old documentation
puts "cleaning old doc"
system "rm -rf doc"
Dir.mkdir 'doc'
copy 'index.html.template', "doc/index.html"
#handle rest service separate from plugins
puts "create framework documentation"
Dir.chdir('webservice') do
raise "generating documentation fail" unless system "rake doc:app"
end
system "cp -r webservice/doc/app doc/webservice"
puts "create plugins documentation"
plugins_names = []
Dir.chdir('plugins') do
plugins_names = Dir.glob '*'
end
plugins_names.each do |plugin|
Dir.chdir("plugins/#{plugin}") do
if File.exist? "Rakefile"
raise "generating documentation fail" unless system "rake doc:app"
end
end
system "cp -r plugins/#{plugin}/doc/app doc/#{plugin}"
end
puts "generate links for plugins"
code = ""
plugins_names.sort.each do |plugin|
code = "#{code}<a href=\"./#{plugin}/index.html\"><b>#{plugin}</b></a><br>"
end
system "sed -i 's:%%PLUGINS%%:#{code}:' doc/index.html"
puts "documentation successfully generated"
end
desc "Grant policies installed in /usr/share/PolicyKit/policy to root"
task :grant_policies do |t|
puts "Running from #{__FILE__}"
puts "You must deploy webservice first!" and return unless File.exists? "/usr/sbin/grantwebyastrights"
system "/usr/sbin/grantwebyastrights --user root --action grant >/dev/null 2>&1"
raise "Error on execute '/usr/sbin/grantwebyastrights --user root --action grant '" if $?.exitstatus != 0
system "/usr/sbin/grantwebyastrights --user yastws --action grant >/dev/null 2>&1"
raise "Error on execute '/usr/sbin/grantwebyastrights --user yastws --action grant '" if $?.exitstatus != 0
end
desc "Deploy for development - create dirs, install configuration files and custom yast modules. Then install and update PolKit policies for root."
# :install policies uses grantwebyastrights, which is installed in :deploy_local
task :deploy_devel_all => [:deploy_local,:install_policies,:grant_policies]
=begin
require 'metric_fu'
MetricFu::Configuration.run do |config|
#define which metrics you want to use
config.metrics = [:churn, :saikuro, :flog, :reek, :roodi, :rcov] #missing flay and stats both not working
config.graphs = [:flog, :reek, :roodi, :rcov]
config.flay = { :dirs_to_flay => ['webservice', 'plugins'] }
config.flog = { :dirs_to_flog => ['webservice', 'plugins'] }
config.reek = { :dirs_to_reek => ['webservice', 'plugins'] }
config.roodi = { :dirs_to_roodi => ['webservice', 'plugins'] }
config.saikuro = { :output_directory => 'tmp/metric_fu/output',
:input_directory => ['webservice', 'plugins'],
:cyclo => "",
:filter_cyclo => "0",
:warn_cyclo => "5",
:error_cyclo => "7",
:formater => "html"} #this needs to be set to "text"
config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
config.rcov = { :test_files => ['webservice/test/**/*_test.rb',
'plugins/**/test/**/*_test.rb'],
:rcov_opts => ["--sort coverage",
"--no-html",
"--text-coverage",
"--no-color",
"--profile",
"--rails",
"--exclude /gems/,/Library/,spec"]}
end
=end
=begin
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = ['webservice/app/**/*.rb','webservice/lib/**/*.rb','webservice/test/plugin_basic_tests.rb', 'plugins/*/app/**/*.rb', 'plugins/*/lib/**/*.rb','webservice/doc/README_FOR_APP', 'plugins/**/README_FOR_APP'] # optional
t.options = ['--private', '--protected'] # optional
end
=end