wcc 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,11 +16,6 @@ conf:
16
16
  # email:
17
17
  # fake_file:
18
18
  # from: root@localhost
19
- # # this allows wcc to send IM messages via
20
- # # it's own jabber account
21
- # jabber:
22
- # jid: wcc@example.org/wcc
23
- # password: s3cr3t
24
19
 
25
20
  # a recipient is like a user profile, it says in which ways wcc
26
21
  # might contact you and provides a central place where to change
@@ -28,7 +23,6 @@ conf:
28
23
  recipients:
29
24
  - me:
30
25
  - email: me@my.place
31
- - jabber: me@jabber.org
32
26
  - my_friend:
33
27
  - email: mail@example.com
34
28
  # 'syslog' profile that notifies syslog on change
@@ -3,7 +3,7 @@
3
3
  # changes than the whole site had lines before.
4
4
 
5
5
  WCC::Filters.add 'rel_changes_of' do |data,args|
6
- next true if data.diffnil?
6
+ next true if data.diff.nil?
7
7
  case args['percent_of']
8
8
  when 'all_lines',nil
9
9
  percent = data.diff.nlinesc.to_f / data.site.content.count("\n").+(1).to_f * 100
data/lib/wcc.rb CHANGED
@@ -19,7 +19,6 @@ require 'yaml'
19
19
  # ruby gem dependencies
20
20
  require 'diff-lcs'
21
21
  require 'htmlentities'
22
- require 'xmpp4r/client'
23
22
 
24
23
  # wcc
25
24
  require 'wcc/diff'
@@ -28,7 +27,6 @@ require 'wcc/mail'
28
27
  require 'wcc/site'
29
28
  require 'wcc/syslog'
30
29
  require 'wcc/version'
31
- require 'wcc/xmpp'
32
30
 
33
31
  class String
34
32
  # Remove all HTML tags with at least one character name and
@@ -48,6 +46,26 @@ class String
48
46
  end
49
47
  end
50
48
 
49
+ class Hash
50
+ # Recursively merges the other hash into self while
51
+ # overwriting duplicate keys in self.
52
+ #
53
+ # @param [Hash] other the hash to get merged in
54
+ # @return [Hash] copy of self with other hash merged in
55
+ def recursive_merge(other)
56
+ copy = self.dup
57
+ other.keys.each do |k|
58
+ if other[k].is_a?(Hash) and self[k].is_a?(Hash)
59
+ copy[k] = copy[k].recursive_merge(other[k])
60
+ else
61
+ # ignore nils from other
62
+ copy[k] = other[k] unless other[k].nil?
63
+ end
64
+ end
65
+ copy
66
+ end
67
+ end
68
+
51
69
  module WCC
52
70
 
53
71
  DIFF_TIME_FMT = '%Y-%m-%d %H:%M:%S %Z'
@@ -134,21 +152,19 @@ module WCC
134
152
 
135
153
  # register standard notificators - these are already loaded
136
154
  Notificators.map 'email', MailNotificator
137
- Notificators.map 'jabber', XMPPNotificator
138
155
  Notificators.map 'syslog', SyslogNotificator
139
156
 
140
157
  WCC.logger.debug "Load config from '#{self[:conf]}'"
141
158
 
142
159
  # may be false if file is empty
143
160
  yaml = YAML.load_file(self[:conf])
161
+
162
+ # inject dummy value {} for 'email' in 'conf' section to make the parser
163
+ # load MailNotificator and it's defaults even if the key is missing
164
+ # since email has always been the backbone of wcc
165
+ yaml = {'conf' => {'email' => {}}}.recursive_merge(yaml) if yaml.is_a?(Hash)
166
+
144
167
  if yaml.is_a?(Hash) and yaml['conf'].is_a?(Hash)
145
-
146
- # load MailNotificator and it's defaults even if the key is missing
147
- # since email has always been the backbone of wcc
148
- if not yaml['conf'].key?('email')
149
- yaml['conf']['email'] = nil
150
- end
151
-
152
168
  yaml['conf'].each do |key,val|
153
169
  case key
154
170
  when 'cache_dir'
@@ -470,9 +486,15 @@ module WCC
470
486
  end
471
487
  end
472
488
 
489
+ # Attempts to read the named template file from template.d
490
+ # and converts it into ERB.
491
+ #
492
+ # @param [String] name file name of template file
493
+ # @return [ERB] the ERB template or nil when file not found
473
494
  def self.load_template(name)
474
495
  t_path = File.join(Conf[:template_dir], name)
475
496
  if File.exists?(t_path)
497
+ WCC.logger.debug "Load template '#{name}'"
476
498
  t = File.open(t_path, 'r') { |f| f.read }
477
499
  # <> omit newline for lines starting with <% and ending in %>
478
500
  return ERB.new(t, 0, "<>")
@@ -480,6 +502,23 @@ module WCC
480
502
  nil
481
503
  end
482
504
 
505
+ # Attempts to write the given raw content to the named template file
506
+ # in template.d. This should be used to create initial template files on demand
507
+ # and will work only when file does not already exist.
508
+ #
509
+ # @param [String] name file name of template file
510
+ # @param [String] raw_content content that should be written to template file
511
+ def self.save_template(name, raw_content)
512
+ t_path = File.join(Conf[:template_dir], name)
513
+ if File.exists?(t_path)
514
+ WCC.logger.warn "Trying to save template '#{name}' which already exists!"
515
+ return
516
+ end
517
+ WCC.logger.info "Save template '#{name}' to #{t_path}"
518
+ File.open(t_path, 'w') { |f| f.write(raw_content) }
519
+ end
520
+
521
+ # Central exit function, allows wcc a clean shutdown.
483
522
  def self.exit(errno)
484
523
  Kernel::exit errno
485
524
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module WCC
3
- VERSION = "2.0.3"
3
+ VERSION = "2.1.0"
4
4
  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: 9
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 2.0.3
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Nicolai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-05 00:00:00 Z
18
+ date: 2011-11-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: htmlentities
@@ -47,20 +47,6 @@ dependencies:
47
47
  version: "1.1"
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: xmpp4r
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- type: :runtime
63
- version_requirements: *id003
64
50
  description: wcc tracks changes of websites and notifies you by email and as of version 2.0 via XMPP/Jabber too.
65
51
  email: chrnicolai@gmail.com
66
52
  executables:
@@ -84,7 +70,6 @@ files:
84
70
  - assets/template.d/mail-body.html.erb
85
71
  - assets/template.d/mail-body.plain.erb
86
72
  - assets/template.d/mail.plain.erb
87
- - assets/template.d/xmpp-body.plain.erb
88
73
  - bin/wcc
89
74
  - bin/wcc-init
90
75
  - bin/wcc-upgrade
@@ -95,7 +80,6 @@ files:
95
80
  - lib/wcc/site.rb
96
81
  - lib/wcc/syslog.rb
97
82
  - lib/wcc/version.rb
98
- - lib/wcc/xmpp.rb
99
83
  - lib/wcc.rb
100
84
  - LICENSE
101
85
  - README.md
@@ -1,9 +0,0 @@
1
- <% if data.diff.nil? %>
2
- Checked <%= data.site.uri.to_s %> the first time so no diff was possible.
3
- <% else %>
4
- Change at <%= data.site.uri.to_s %> - diff follows:
5
-
6
- <%= data.diff.to_s %>
7
-
8
- nHunks: <%= data.diff.nhunks %>, nIns: <%= data.diff.ninsertions %>, nDel: <%= data.diff.ndeletions %>, nLinesC: <%= data.diff.nlinesc %>, nCharsC: <%= data.diff.ncharsc %>
9
- <% end %>
@@ -1,71 +0,0 @@
1
-
2
- module WCC
3
- class XMPPNotificator
4
- @@client = nil
5
- @@template = nil
6
-
7
- def initialize(opts)
8
- @jid = Jabber::JID.new(opts)
9
- end
10
-
11
- def notify!(data)
12
- # prepare message
13
- subject = "[#{data.tag}] #{data.site.uri.host} changed"
14
- body = self.class.get_template.result(binding)
15
- m = Jabber::Message.new(@jid, body)
16
- m.type = :normal
17
- m.subject = subject
18
- # send it
19
- c = self.class.get_client
20
- c.send(m) unless c.nil?
21
- end
22
-
23
- def self.parse_conf(conf)
24
- if conf.is_a?(Hash)
25
- if conf['jid'].nil?
26
- WCC.logger.fatal "Missing jabber ID!"
27
- return {:xmpp_jid => nil}
28
- elsif conf['password'].nil?
29
- WCC.logger.fatal "Missing jabber password!"
30
- else
31
- return {
32
- :xmpp_jid => Jabber::JID.new(conf['jid']),
33
- :xmpp_password => conf['password']
34
- }
35
- end
36
- end
37
- # no defaults
38
- {}
39
- end
40
-
41
- def self.shut_down
42
- if not @@client.nil?
43
- #@@client.send(Jabber::Presence.new.set_type(:unavailable))
44
- @@client.close
45
- end
46
- end
47
-
48
- def self.get_client
49
- if @@client.nil? and not Conf[:xmpp_jid].nil?
50
- @@client = Jabber::Client.new(Conf[:xmpp_jid])
51
- @@client.connect
52
- begin
53
- @@client.auth(Conf[:xmpp_password])
54
- @@client.send(Jabber::Presence.new.set_status('At your service every night.'))
55
- rescue Jabber::ClientAuthenticationFailure => ex
56
- WCC.logger.fatal "Wrong jabber password for #{Conf[:xmpp_jid]}!"
57
- @@client.close
58
- @@client = nil
59
- end
60
- end
61
- @@client
62
- end
63
-
64
- def self.get_template
65
- if @@template.nil?
66
- @@template = WCC::Prog.load_template('xmpp-body.plain.erb')
67
- end
68
- @@template
69
- end
70
- end
71
- end