trackchange 0.2.0 → 0.3.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/lib/trackchange/exec.rb +22 -3
- data/lib/trackchange/probe.rb +20 -7
- data/lib/trackchange/version.rb +1 -1
- metadata +4 -4
data/lib/trackchange/exec.rb
CHANGED
@@ -41,13 +41,17 @@ module Trackchange
|
|
41
41
|
|
42
42
|
def add
|
43
43
|
config.sites ||= []
|
44
|
-
config.sites |= [ args.first ]
|
44
|
+
config.sites |= [ { url: args.first } ]
|
45
45
|
store_config!
|
46
|
+
|
47
|
+
# instant probe on add
|
48
|
+
config.sites = [ { url: args.first } ]
|
49
|
+
probe
|
46
50
|
end
|
47
51
|
|
48
52
|
def list
|
49
|
-
config.sites.each_with_index do |
|
50
|
-
puts "% 4s %s" % [pos+1, url]
|
53
|
+
config.sites.each_with_index do |site, pos|
|
54
|
+
puts "% 4s %s" % [pos+1, site[:url]]
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -80,6 +84,17 @@ module Trackchange
|
|
80
84
|
return @config if @config
|
81
85
|
data = { version: VERSION }
|
82
86
|
data = YAML.load(File.read(config_path)) if File.exist?(config_path)
|
87
|
+
|
88
|
+
# upgrade from <= 0.2.0
|
89
|
+
if v(data[:version]) <= v('0.2.0')
|
90
|
+
data[:version] = VERSION
|
91
|
+
data[:sites] = data[:sites].map do |site|
|
92
|
+
{ url: site }
|
93
|
+
end
|
94
|
+
@config = OpenStruct.new(data)
|
95
|
+
store_config!
|
96
|
+
end
|
97
|
+
|
83
98
|
@config = OpenStruct.new(data)
|
84
99
|
end
|
85
100
|
|
@@ -87,5 +102,9 @@ module Trackchange
|
|
87
102
|
File.open(config_path, 'w') { |f| f.print(YAML.dump(config.marshal_dump)) }
|
88
103
|
end
|
89
104
|
|
105
|
+
def v(version)
|
106
|
+
Gem::Version.new(version)
|
107
|
+
end
|
108
|
+
|
90
109
|
end
|
91
110
|
end
|
data/lib/trackchange/probe.rb
CHANGED
@@ -17,14 +17,15 @@ module Trackchange
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def probe(site)
|
20
|
-
|
20
|
+
url = site[:url]
|
21
|
+
fname = url.sub(%r{https?://}, '').tr_s('/?&', '...')
|
21
22
|
site_path = File.expand_path(fname, '~/.trackchange')
|
22
|
-
lynx = "lynx -dump '#{
|
23
|
+
lynx = "lynx -dump '#{url}' | uniq > #{site_path}.new"
|
23
24
|
logger.debug "% #{lynx}"
|
24
25
|
system lynx
|
25
26
|
|
26
27
|
unless File.exist?(site_path) # new site
|
27
|
-
logger.warn "new site #{
|
28
|
+
logger.warn "new site #{url}"
|
28
29
|
FileUtils.mv("#{site_path}.new", site_path)
|
29
30
|
return
|
30
31
|
end
|
@@ -34,13 +35,23 @@ module Trackchange
|
|
34
35
|
result = %x[ #{diff} ]
|
35
36
|
|
36
37
|
if result.empty? # same old
|
37
|
-
logger.info "same old #{
|
38
|
+
logger.info "same old #{url}"
|
38
39
|
FileUtils.rm_f("#{site_path}.new")
|
39
40
|
return
|
40
41
|
end
|
41
42
|
|
43
|
+
if site[:threshold]
|
44
|
+
diffgrepwc = "#{diff} | grep '^[-+]:' | wc -l"
|
45
|
+
logger.debug "% #{diffgrepwc}"
|
46
|
+
degree = %x[ #{diffgrepwc} ]
|
47
|
+
if degree.to_i < site[:threshold].to_i
|
48
|
+
logger.warn 'change below threshold, skipping notification'
|
49
|
+
skip_notification = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
42
53
|
# changed
|
43
|
-
logger.warn "changed #{
|
54
|
+
logger.warn "changed #{url}"
|
44
55
|
if pat = config.archive_pattern
|
45
56
|
time = File.ctime(site_path).strftime(pat)
|
46
57
|
logger.info "archived #{site_path}.#{time}"
|
@@ -48,13 +59,15 @@ module Trackchange
|
|
48
59
|
end
|
49
60
|
FileUtils.mv("#{site_path}.new", site_path)
|
50
61
|
|
62
|
+
return if skip_notification
|
63
|
+
|
51
64
|
if email = config.email # send email
|
52
65
|
logger.info "sending notification to #{email}"
|
53
66
|
begin
|
54
67
|
file = Tempfile.new('changetrack')
|
55
|
-
file.write "#{
|
68
|
+
file.write "#{url}\n\n#{result}"
|
56
69
|
file.close
|
57
|
-
mail = "cat #{file.path} | mail -s 'Change detected on #{
|
70
|
+
mail = "cat #{file.path} | mail -s 'Change detected on #{url}' #{email}"
|
58
71
|
logger.debug mail
|
59
72
|
system mail
|
60
73
|
ensure
|
data/lib/trackchange/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cronedit
|
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
segments:
|
96
96
|
- 0
|
97
|
-
hash: -
|
97
|
+
hash: -4153791099187356125
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
segments:
|
105
105
|
- 0
|
106
|
-
hash: -
|
106
|
+
hash: -4153791099187356125
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
109
|
rubygems_version: 1.8.23
|