sla 0.1.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79b603ee409c9bb9d7846dfd6d843496f961bd91edb04a4186c4ba3629ab9d2e
4
- data.tar.gz: 9d7b4862e1878354cf0dca9a62be98ad2db8b9f3aece306bb1ffdc439f27451d
3
+ metadata.gz: 20e5f6a05020d9aecc2ad6754a7a22cee70e18f45e3bc5f679daabb2042c749a
4
+ data.tar.gz: 2d5b0290dd9dd25169bbb89ff20df4aea66db616ea65585a56a982866579f568
5
5
  SHA512:
6
- metadata.gz: 9ed2eba3bb08b65766d7ef2246219f95271b44501e7a0085123427c33a4d8598bc1495d796a8aea5bd0e547a8266cc650bd500c539e0afb2ad8093ee4c67bfca
7
- data.tar.gz: bb9da599ff06fe917615d039086a51bd54070b8f80aa3785a02db6a09fe70921080d388ba27004763d42090667bbbb4b77ecab3a61ac8128d2e90952d61d9b15
6
+ metadata.gz: cc586125c98e82786f0c747fcdf9d21f45d933564e4aba416036d21a39a70c72bdb974665c8e6a6f5c5b17a4ad323a52bb896205f4e5bb7e49002dd4370b1d84
7
+ data.tar.gz: 10fadfccf9da8a7b427f6512bfb6365f890dc70cc01646280a5de51aeebee38026942dc78b30e1c5dac9196015e3e9565a804bf13e8c9c3c7c2bed00c9a5ca49
data/README.md CHANGED
@@ -1,101 +1,80 @@
1
- Site Link Analyzer
2
- ==================================================
3
-
4
- [![Gem Version](https://badge.fury.io/rb/sla.svg)](https://badge.fury.io/rb/sla)
5
- [![Build Status](https://travis-ci.com/DannyBen/sla.svg?branch=master)](https://travis-ci.com/DannyBen/sla)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/f78192aead8a74535a24/maintainability)](https://codeclimate.com/github/DannyBen/sla/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/f78192aead8a74535a24/test_coverage)](https://codeclimate.com/github/DannyBen/sla/test_coverage)
8
-
9
- ---
10
-
11
- SLA is a simple broken links checker, with built in caching.
12
-
13
- ---
14
-
15
- Install
16
- --------------------------------------------------
17
-
18
- ```
19
- $ gem install sla
20
- ```
21
-
22
- Or with bundler:
23
-
24
- ```ruby
25
- gem 'sla'
26
- ```
27
-
28
-
29
- Features
30
- --------------------------------------------------
31
-
32
- - Easy to use command line interface
33
- - Built in caching, to avoid over stressing the server
34
- - Outputs the site tree to screen and log file
35
-
36
-
37
- Example Output
38
- --------------------------------------------------
39
- ```
40
- $ sla check localhost:3000
41
- 1 200 - http://localhost:3000
42
- 2 200 -- /whiskey
43
- 3 200 --- /whiskey/tango
44
- 4 404 ---- /whiskey/tango/foxtrot
45
- 5 200 -- /ten
46
- 6 200 --- /ten/four
47
- 7 200 -- /roger
48
- Done with 1 failures
49
- ```
50
-
51
-
52
- Usage
53
- --------------------------------------------------
54
-
55
- ```
56
- $ sla --help
57
- SLA
58
-
59
- Usage:
60
- sla check DOMAIN [options]
61
- sla (-h|--help|--version)
62
-
63
- Commands:
64
- check
65
- Start checking for broken links on a given domain
66
-
67
- Options:
68
- --depth, -d DEPTH
69
- Set crawling depth [default: 5]
70
-
71
- --cache, -c LIFE
72
- Set cache life [default: 1d]. LIFE can be in any of the
73
- following formats:
74
- 10 = 10 seconds
75
- 20s = 20 seconds
76
- 10m = 10 minutes
77
- 10h = 10 hours
78
- 10d = 10 days
79
-
80
- --cache-dir DIR
81
- Set the cache directory
82
-
83
- --external
84
- Also check external links
85
-
86
- --no-color
87
- Disable colors in output
88
-
89
- --no-log
90
- Disable logging
91
-
92
- --log LOGFILE
93
- Set the name of the logfile [default: sla.log]
94
-
95
- Examples:
96
- sla check example.com
97
- sla check example.com -c10m -d10
98
- sla check example.com --cache-dir my_cache --no-log
99
- sla check example.com --depth 10 --log my_log.log
100
- sla check example.com --cache 30d
101
- ```
1
+ Site Link Analyzer
2
+ ==================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/sla.svg)](https://badge.fury.io/rb/sla)
5
+ [![Build Status](https://travis-ci.com/DannyBen/sla.svg?branch=master)](https://travis-ci.com/DannyBen/sla)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f78192aead8a74535a24/maintainability)](https://codeclimate.com/github/DannyBen/sla/maintainability)
7
+
8
+ ---
9
+
10
+ SLA is a simple broken links checker, with built in caching.
11
+
12
+ ![SLA Demo](demo/cast.svg "SLA Demo")
13
+
14
+ Install
15
+ --------------------------------------------------
16
+
17
+ ```
18
+ $ gem install sla
19
+ ```
20
+
21
+
22
+ Features
23
+ --------------------------------------------------
24
+
25
+ - Easy to use command line interface.
26
+ - Built in caching, to avoid overtaxing the server.
27
+ - Show and save list of broken links to a log file.
28
+ - Exits with non zero code on failure, for CI integration.
29
+
30
+
31
+ Usage
32
+ --------------------------------------------------
33
+
34
+ ```
35
+ $ sla --help
36
+ SLA
37
+
38
+ Usage:
39
+ sla check DOMAIN [options]
40
+ sla (-h|--help|--version)
41
+
42
+ Commands:
43
+ check
44
+ Start checking for broken links on a given domain.
45
+
46
+ Options:
47
+ --depth, -d DEPTH
48
+ Set crawling depth [default: 5].
49
+
50
+ --cache, -c LIFE
51
+ Set cache life [default: 1d]. LIFE can be in any of the
52
+ following formats:
53
+ 10 = 10 seconds
54
+ 20s = 20 seconds
55
+ 10m = 10 minutes
56
+ 10h = 10 hours
57
+ 10d = 10 days
58
+
59
+ --cache-dir DIR
60
+ Set the cache directory.
61
+
62
+ --external, -x
63
+ Also check external links.
64
+
65
+ --log, -l LOGFILE
66
+ Save errors to log file.
67
+
68
+ --ignore, -i URLS
69
+ Specify a list of space delimited URLs to skip.
70
+ URLs that start with the strings in this list will be skipped.
71
+
72
+ Examples:
73
+ sla check example.com
74
+ sla check example.com -c10m -d10
75
+ sla check example.com --cache-dir my_cache
76
+ sla check example.com --depth 10 --log my_log.log
77
+ sla check example.com --cache 30d
78
+ sla check example.com --ignore "/admin /customer/login"
79
+
80
+ ```
data/bin/sla CHANGED
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'sla'
4
- SLA::CommandLine.execute ARGV
4
+
5
+ begin
6
+ SLA::CommandLine.execute ARGV
7
+ rescue SLA::BrokenLinks => e
8
+ puts "(exit code 1)"
9
+ exit 1
10
+ end
data/lib/sla.rb CHANGED
@@ -1,13 +1,19 @@
1
- require 'webcache'
2
- require 'nokogiri'
3
- require 'colsole'
4
- require 'singleton'
5
- require 'super_docopt'
6
- require 'uri'
7
-
8
- require 'sla/version'
9
- require 'sla/link'
10
- require 'sla/checker'
11
- require 'sla/command_line'
12
-
13
- require 'byebug' if ENV['BYEBUG']
1
+ require 'webcache'
2
+ require 'nokogiri'
3
+ require 'colsole'
4
+ require 'singleton'
5
+ require 'super_docopt'
6
+ require 'uri'
7
+
8
+ require 'sla/version'
9
+ require 'sla/exceptions'
10
+ require 'sla/link'
11
+ require 'sla/checker'
12
+ require 'sla/command_line'
13
+
14
+ if ENV['BYEBUG']
15
+ # :nocov:
16
+ require 'byebug'
17
+ require 'lp'
18
+ # :nocov:
19
+ end
data/lib/sla/checker.rb CHANGED
@@ -2,12 +2,13 @@ module SLA
2
2
  class Checker
3
3
  include Colsole
4
4
 
5
- attr_accessor :max_depth, :checked_links, :check_external
5
+ attr_accessor :max_depth, :checked_links, :check_external, :ignore
6
6
 
7
7
  def initialize
8
8
  @max_depth = 10
9
9
  @checked_links = []
10
10
  @check_external = false
11
+ @ignore = []
11
12
  end
12
13
 
13
14
  def count
@@ -17,7 +18,10 @@ module SLA
17
18
  def check(link, depth=1, &block)
18
19
  link = Link.new link, depth: depth if link.is_a? String
19
20
 
20
- return if link.external? && !@check_external
21
+ return if link.external? && !check_external
22
+ ignore.each do |ignored|
23
+ return if link.ident.start_with? ignored
24
+ end
21
25
 
22
26
  link.validate
23
27
  yield link if block_given?
@@ -1,75 +1,83 @@
1
- module SLA
2
- class CommandLine < SuperDocopt::Base
3
- include Colsole
4
-
5
- version VERSION
6
- docopt File.expand_path 'docopt.txt', __dir__
7
- subcommands ['check']
8
-
9
- def before_execute
10
- @no_color = args['--no-color']
11
- @no_log = args['--no-log']
12
- end
13
-
14
- def check
15
- # :nocov:
16
- if !$cache
17
- $cache ||= WebCache.new
18
- $cache.life = args['--cache']
19
- $cache.dir = args['--cache-dir'] if args['--cache-dir']
20
- end
21
- # :nocov:
22
-
23
- checker = Checker.new
24
- checker.max_depth = args['--depth'].to_i
25
- checker.check_external = args['--external']
26
- logfile = args['--log']
27
- start_url = args['DOMAIN']
28
-
29
- start_url = "http://#{start_url}" unless start_url[0..3] == 'http'
30
-
31
- File.unlink logfile if File.exist? logfile
32
-
33
- count = 1
34
- failed = 0
35
-
36
- log = []
37
-
38
- checker.check start_url do |link|
39
- indent = '-' * link.depth
40
-
41
- status = link.status
42
- colored_status = color_status status
43
- failed +=1 if status != '200'
44
-
45
- say "#{count} #{colored_status} #{indent} #{link.ident}"
46
- log.push "#{count} #{status} #{indent} #{link.ident}" unless @no_log
47
- count += 1
48
- end
49
-
50
- color = failed > 0 ? '!txtred!' : '!txtgrn!'
51
- color = "" if @no_color
52
- say "#{color}Done with #{failed} failures"
53
- log.push "Done with #{failed} failures" unless @no_log
54
-
55
- File.write logfile, log.join("\n") unless @no_log
56
- end
57
-
58
- private
59
-
60
- def color_status(status)
61
- return status if @no_color
62
- # :nocov:
63
- case status
64
- when '200'
65
- '!txtgrn!200!txtrst!'
66
- when '404'
67
- '!txtred!404!txtrst!'
68
- else
69
- status
70
- end
71
- # :nocov:
72
- end
73
-
74
- end
1
+ module SLA
2
+ class CommandLine < SuperDocopt::Base
3
+ include Colsole
4
+
5
+ version VERSION
6
+ docopt File.expand_path 'docopt.txt', __dir__
7
+ subcommands ['check']
8
+
9
+ def before_execute
10
+ WebCache.life = args['--cache']
11
+ WebCache.dir = args['--cache-dir'] if args['--cache-dir']
12
+ end
13
+
14
+ def check
15
+ checker = Checker.new
16
+ checker.max_depth = args['--depth'].to_i
17
+ logfile = args['--log']
18
+ start_url = args['DOMAIN']
19
+ ignore = args['--ignore']
20
+ ignore = ignore.split " " if ignore
21
+ screen_width = terminal_width
22
+
23
+ checker.check_external = args['--external']
24
+ checker.ignore = ignore if ignore
25
+
26
+ start_url = "http://#{start_url}" unless start_url[0..3] == 'http'
27
+
28
+ File.unlink logfile if logfile and File.exist? logfile
29
+
30
+ count = 1
31
+ failed = 0
32
+
33
+ log = []
34
+
35
+ checker.check start_url do |link|
36
+ status = link.status
37
+ colored_status = color_status status
38
+ if status != '200'
39
+ failed +=1
40
+ resay "#{colored_status} #{link.ident}"
41
+ log.push "#{status} #{link.ident}" if logfile
42
+ end
43
+
44
+ message = "[#{failed}/#{count} @ #{link.depth}] #{status}"
45
+ remaining_width = screen_width - message.size - 4
46
+ trimmed_link = link.ident[0..remaining_width]
47
+
48
+ resay "[#{failed}/#{count} @ #{link.depth}] #{colored_status} #{trimmed_link} "
49
+ count += 1
50
+
51
+ sleep ENV['SLA_SLEEP'].to_f if ENV['SLA_SLEEP']
52
+ end
53
+
54
+ color = failed > 0 ? '!txtred!' : '!txtgrn!'
55
+ resay "#{color}Done checking #{count} links with #{failed} failures"
56
+
57
+ if logfile
58
+ logstring = log.join("\n") + "\n"
59
+ File.write logfile, logstring
60
+ end
61
+
62
+ if failed > 0 and !ENV['SLA_ALLOW_FAILS']
63
+ raise BrokenLinks
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def color_status(status)
70
+ case status
71
+ when '200'
72
+ '!txtgrn!200!txtrst!'
73
+ when '404'
74
+ '!txtred!404!txtrst!'
75
+ else
76
+ # :nocov:
77
+ status
78
+ # :nocov:
79
+ end
80
+ end
81
+
82
+ end
75
83
  end
data/lib/sla/docopt.txt CHANGED
@@ -1,44 +1,43 @@
1
- SLA
2
-
3
- Usage:
4
- sla check DOMAIN [options]
5
- sla (-h|--help|--version)
6
-
7
- Commands:
8
- check
9
- Start checking for broken links on a given domain
10
-
11
- Options:
12
- --depth, -d DEPTH
13
- Set crawling depth [default: 5]
14
-
15
- --cache, -c LIFE
16
- Set cache life [default: 1d]. LIFE can be in any of the
17
- following formats:
18
- 10 = 10 seconds
19
- 20s = 20 seconds
20
- 10m = 10 minutes
21
- 10h = 10 hours
22
- 10d = 10 days
23
-
24
- --cache-dir DIR
25
- Set the cache directory
26
-
27
- --external
28
- Also check external links
29
-
30
- --no-color
31
- Disable colors in output
32
-
33
- --no-log
34
- Disable logging
35
-
36
- --log LOGFILE
37
- Set the name of the logfile [default: sla.log]
38
-
39
- Examples:
40
- sla check example.com
41
- sla check example.com -c10m -d10
42
- sla check example.com --cache-dir my_cache --no-log
43
- sla check example.com --depth 10 --log my_log.log
44
- sla check example.com --cache 30d
1
+ SLA
2
+
3
+ Usage:
4
+ sla check DOMAIN [options]
5
+ sla (-h|--help|--version)
6
+
7
+ Commands:
8
+ check
9
+ Start checking for broken links on a given domain.
10
+
11
+ Options:
12
+ --depth, -d DEPTH
13
+ Set crawling depth [default: 5].
14
+
15
+ --cache, -c LIFE
16
+ Set cache life [default: 1d]. LIFE can be in any of the
17
+ following formats:
18
+ 10 = 10 seconds
19
+ 20s = 20 seconds
20
+ 10m = 10 minutes
21
+ 10h = 10 hours
22
+ 10d = 10 days
23
+
24
+ --cache-dir DIR
25
+ Set the cache directory.
26
+
27
+ --external, -x
28
+ Also check external links.
29
+
30
+ --log, -l LOGFILE
31
+ Save errors to log file.
32
+
33
+ --ignore, -i URLS
34
+ Specify a list of space delimited URLs to skip.
35
+ URLs that start with the strings in this list will be skipped.
36
+
37
+ Examples:
38
+ sla check example.com
39
+ sla check example.com -c10m -d10
40
+ sla check example.com --cache-dir my_cache
41
+ sla check example.com --depth 10 --log my_log.log
42
+ sla check example.com --cache 30d
43
+ sla check example.com --ignore "/admin /customer/login"
@@ -0,0 +1,3 @@
1
+ module SLA
2
+ class BrokenLinks < StandardError; end
3
+ end
data/lib/sla/link.rb CHANGED
@@ -24,7 +24,7 @@ module SLA
24
24
  end
25
25
 
26
26
  def content!
27
- response = $cache.get url
27
+ response = WebCache.get url
28
28
  @status = response.error ? '404' : '200'
29
29
  @real_uri = response.base_uri
30
30
  response.content
data/lib/sla/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SLA
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: super_docopt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,104 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.8'
69
- - !ruby/object:Gem::Dependency
70
- name: runfile
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.10'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.10'
83
- - !ruby/object:Gem::Dependency
84
- name: adsf
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.2'
97
- - !ruby/object:Gem::Dependency
98
- name: runfile-tasks
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.4'
111
- - !ruby/object:Gem::Dependency
112
- name: byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '10.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '10.0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.7'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.7'
139
- - !ruby/object:Gem::Dependency
140
- name: rspec_fixtures
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '0.4'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '0.4'
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.16'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.16'
167
69
  description: Check for broken links on a website
168
70
  email: db@dannyben.com
169
71
  executables:
@@ -177,6 +79,7 @@ files:
177
79
  - lib/sla/checker.rb
178
80
  - lib/sla/command_line.rb
179
81
  - lib/sla/docopt.txt
82
+ - lib/sla/exceptions.rb
180
83
  - lib/sla/link.rb
181
84
  - lib/sla/version.rb
182
85
  homepage: https://github.com/DannyBen/sla
@@ -198,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
101
  - !ruby/object:Gem::Version
199
102
  version: '0'
200
103
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.7.6
104
+ rubygems_version: 3.0.3
203
105
  signing_key:
204
106
  specification_version: 4
205
107
  summary: Command Line Site Link Analyzer