wcc 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/assets/filter.d/{only_changes_of.rb → changes_of.rb} +4 -4
- data/assets/filter.d/rel_changes_of.rb +21 -0
- data/lib/wcc/mail.rb +1 -1
- data/lib/wcc.rb +54 -15
- metadata +5 -4
@@ -1,15 +1,15 @@
|
|
1
1
|
|
2
|
-
WCC::Filters.add '
|
2
|
+
WCC::Filters.add 'changes_of' do |data,args|
|
3
3
|
case args['t'] || args['type']
|
4
|
-
when 'lines',nil
|
4
|
+
when 'line','lines',nil
|
5
5
|
cmp_val = data.diff.nlinesc
|
6
|
-
when 'chars'
|
6
|
+
when 'char','chars'
|
7
7
|
cmp_val = data.diff.ncharsc
|
8
8
|
when 'ins','insertions'
|
9
9
|
cmp_val = data.diff.ninsertions
|
10
10
|
when 'del','deletions'
|
11
11
|
cmp_val = data.diff.ndeletions
|
12
|
-
when 'hunks'
|
12
|
+
when 'hunk','hunks'
|
13
13
|
cmp_val = data.diff.nhunks
|
14
14
|
end
|
15
15
|
next (cmp_val >= args['at_least']) if args.key?('at_least')
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
# NOTE: the percentage may easily go above 100% when there are more
|
3
|
+
# changes than the whole site has lines.
|
4
|
+
|
5
|
+
WCC::Filters.add 'rel_changes_of' do |data,args|
|
6
|
+
case args['percent_of']
|
7
|
+
when 'all_lines',nil
|
8
|
+
percent = data.diff.nlinesc.to_f / data.site.content.count("\n").+(1).to_f * 100
|
9
|
+
# when 'all_chars','all_characters'
|
10
|
+
# percent = ...
|
11
|
+
# when 'nonblank_lines'
|
12
|
+
# percent = ...
|
13
|
+
end
|
14
|
+
next (percent >= args['at_least']) if args.key?('at_least')
|
15
|
+
next (percent > args['more_than']) if args.key?('more_than')
|
16
|
+
next (percent <= args['at_most']) if args.key?('at_most')
|
17
|
+
next (percent < args['fewer_then']) if args.key?('fewer_than')
|
18
|
+
next (percent == args['exactly']) if args.key?('exactly')
|
19
|
+
next (percent != args['not_quite']) if args.key('not_quite')
|
20
|
+
true
|
21
|
+
end
|
data/lib/wcc/mail.rb
CHANGED
@@ -41,9 +41,9 @@ module WCC
|
|
41
41
|
# does plain SMTP to host:port using [Net::SMTP].
|
42
42
|
class SmtpMailer
|
43
43
|
def initialize(host, port)
|
44
|
-
WCC.logger.info "Send mail via SMTP to #{@host}:#{@port}"
|
45
44
|
@host = host
|
46
45
|
@port = port
|
46
|
+
WCC.logger.info "Send mail via SMTP to #{@host}:#{@port}"
|
47
47
|
end
|
48
48
|
|
49
49
|
# Sends a mail built up from some [ERB] templates to the
|
data/lib/wcc.rb
CHANGED
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
module WCC
|
47
47
|
|
48
|
-
VERSION = "1.
|
48
|
+
VERSION = "1.2.0"
|
49
49
|
|
50
50
|
DIFF_TIME_FMT = '%Y-%m-%d %H:%M:%S %Z'
|
51
51
|
|
@@ -105,7 +105,6 @@ module WCC
|
|
105
105
|
opts.on('-f', '--from MAIL', 'Set From: mail address') do |m| self[:from_mail] = m end
|
106
106
|
opts.on('--host HOST', 'Set SMTP host') do |h| self[:host] = h end
|
107
107
|
opts.on('--port PORT', 'Set SMTP port') do |p| self[:port] = p end
|
108
|
-
#opts.on('--init', '--initialize')
|
109
108
|
opts.on('--show-config', 'Show config after loading config file (debug purposes)') do self[:show_config] = true end
|
110
109
|
opts.on('-h', '-?', '--help', 'Display this screen') do
|
111
110
|
puts opts
|
@@ -171,19 +170,6 @@ module WCC
|
|
171
170
|
exit 0
|
172
171
|
end
|
173
172
|
|
174
|
-
# create cache dir for hash and diff files
|
175
|
-
Dir.mkdir(self[:cache_dir]) unless File.directory?(self[:cache_dir])
|
176
|
-
|
177
|
-
if(self[:clean])
|
178
|
-
WCC.logger.warn "Cleanup hash and diff files"
|
179
|
-
Dir.foreach(self[:cache_dir]) do |f|
|
180
|
-
File.delete(self.file(f)) if f =~ /^.*\.(md5|site)$/
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# read filter.d
|
185
|
-
Dir[File.join(self[:filter_dir], '*.rb')].each { |file| require file }
|
186
|
-
|
187
173
|
# attach --no-mails filter
|
188
174
|
WCC::Filters.add '--no-mails' do |data|
|
189
175
|
!self[:nomails]
|
@@ -367,6 +353,40 @@ module WCC
|
|
367
353
|
# first use of Conf initializes it
|
368
354
|
WCC.logger = Logger.new(STDOUT)
|
369
355
|
|
356
|
+
# make sure logger is correctly configured
|
357
|
+
Conf.instance
|
358
|
+
|
359
|
+
# create cache dir for hash and diff files
|
360
|
+
Dir.mkdir(Conf[:cache_dir]) unless File.directory?(Conf[:cache_dir])
|
361
|
+
|
362
|
+
if(Conf[:clean])
|
363
|
+
WCC.logger.warn "Cleanup hash and diff files"
|
364
|
+
Dir.foreach(Conf[:cache_dir]) do |f|
|
365
|
+
File.delete(Conf.file(f)) if f =~ /^.*\.(md5|site)$/
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
# read filter.d
|
370
|
+
Dir[File.join(Conf[:filter_dir], '*.rb')].each { |file| require file }
|
371
|
+
|
372
|
+
# timestamps
|
373
|
+
cache_file = Conf.file('cache.yml')
|
374
|
+
if File.exists?(cache_file)
|
375
|
+
WCC.logger.debug "Load timestamps from '#{cache_file}'"
|
376
|
+
|
377
|
+
# may be *false* if file is empty
|
378
|
+
yaml = YAML.load_file(cache_file)
|
379
|
+
|
380
|
+
if not yaml
|
381
|
+
WCC.logger.info "No timestamps loaded"
|
382
|
+
else
|
383
|
+
@@timestamps = yaml['timestamps']
|
384
|
+
end
|
385
|
+
else
|
386
|
+
@@timestamps = {}
|
387
|
+
end
|
388
|
+
|
389
|
+
# templates
|
370
390
|
@@mail_plain = load_template('mail.alt.erb')
|
371
391
|
@@mail_bodies = {
|
372
392
|
:plain => load_template('mail-body.plain.erb'),
|
@@ -374,12 +394,23 @@ module WCC
|
|
374
394
|
}
|
375
395
|
|
376
396
|
Conf.sites.each do |site|
|
397
|
+
ts_old = get_timestamp(site)
|
398
|
+
ts_new = Time.now.to_i
|
399
|
+
if (ts_new-ts_old) < site.check_interval*60
|
400
|
+
ts_diff = (ts_new-ts_old)/60
|
401
|
+
WCC.logger.info "Skipping check for #{site.uri.host.to_s} due to check #{ts_diff} minute#{ts_diff == 1 ? '' : 's'} ago."
|
402
|
+
next
|
403
|
+
end
|
377
404
|
if checkForUpdate(site)
|
378
405
|
WCC.logger.warn "#{site.uri.host.to_s} has an update!"
|
379
406
|
else
|
380
407
|
WCC.logger.info "#{site.uri.host.to_s} is unchanged"
|
381
408
|
end
|
409
|
+
update_timestamp(site, ts_new)
|
382
410
|
end
|
411
|
+
|
412
|
+
# save timestamps
|
413
|
+
File.open(cache_file, 'w+') do |f| YAML.dump({"timestamps" => @@timestamps}, f) end
|
383
414
|
end
|
384
415
|
|
385
416
|
private
|
@@ -390,5 +421,13 @@ module WCC
|
|
390
421
|
# <> omit newline for lines starting with <% and ending in %>
|
391
422
|
ERB.new(t, 0, "<>")
|
392
423
|
end
|
424
|
+
|
425
|
+
def self.get_timestamp(site)
|
426
|
+
@@timestamps[site.uri.to_s] || 0
|
427
|
+
end
|
428
|
+
|
429
|
+
def self.update_timestamp(site, t)
|
430
|
+
@@timestamps[site.uri.to_s] = t
|
431
|
+
end
|
393
432
|
end
|
394
433
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wcc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christian Nicolai
|
@@ -59,7 +59,8 @@ extra_rdoc_files:
|
|
59
59
|
files:
|
60
60
|
- assets/conf.yml
|
61
61
|
- assets/filter.d/arg-test.rb
|
62
|
-
- assets/filter.d/
|
62
|
+
- assets/filter.d/changes_of.rb
|
63
|
+
- assets/filter.d/rel_changes_of.rb
|
63
64
|
- assets/filter.d/test.rb
|
64
65
|
- assets/template.d/mail.alt.erb
|
65
66
|
- assets/template.d/mail-body.html.erb
|