checkzilla 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/checkzilla ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'clamp'
5
+ require 'pry'
6
+
7
+ require File.expand_path("../../lib/checkzilla", __FILE__)
8
+
9
+ CheckZilla::CLI.run
data/lib/checkzilla.rb ADDED
@@ -0,0 +1,15 @@
1
+ module CheckZilla
2
+
3
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'checkzilla')
4
+ CHECK_UPDATE_PATH = File.join(LIBRARY_PATH, 'check')
5
+ NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
6
+
7
+ [CHECK_UPDATE_PATH, NOTIFIER_PATH].each do |ext|
8
+ Dir["#{ext}/*.rb"].each { |lib| require lib }
9
+ end
10
+
11
+ %w{
12
+ model
13
+ cli
14
+ }.each {|lib| require File.join(LIBRARY_PATH, lib) }
15
+ end
@@ -0,0 +1,25 @@
1
+ module CheckZilla
2
+ module Check
3
+ class Npm
4
+
5
+ attr_accessor :results
6
+ attr_accessor :path
7
+
8
+ def initialize &block
9
+ @results = {}
10
+ instance_eval(&block) if block_given?
11
+ raise "npm: path required" if !@path
12
+ self
13
+ end
14
+
15
+ def perform!
16
+ raise "npm: directory doesn't exist" unless File.exists?(@path)
17
+ raw_result = `cd #{@path}; npm outdated --silent`
18
+ raw_result.split("\n").each do |outdated_package|
19
+ outdated_hash = outdated_package.match /^(.+)@(.+)\s.+\s.+=(.+)$/
20
+ @results[outdated_hash[1]] = [outdated_hash[3], outdated_hash[2]]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ # requires package-query
5
+ module CheckZilla
6
+ module Check
7
+ class Pacman
8
+
9
+ attr_accessor :results
10
+
11
+ def initialize &block
12
+ @results = {}
13
+ instance_eval(&block) if block_given?
14
+ self
15
+ end
16
+
17
+ def perform!
18
+ cmd = ''
19
+ cmd = "sudo pacman -Sy > /dev/null ; package-query -AQu -f '%n %l %V'"
20
+ packages = `#{cmd}`.split("\n")
21
+
22
+ packages.each do |package|
23
+ package_name, package_current_version, package_db_version = package.split(' ')
24
+ @results[package_name] = [package_current_version, package_db_version]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'bundler'
4
+
5
+ module CheckZilla
6
+ module Check
7
+ # Try to determine your gems dependencies and which are not up to date
8
+
9
+ # If a path is defined and a Gemfile.lock exists in the repository
10
+ # it will parse it via bundler
11
+
12
+ # Otherwise it will parse the output of the `gem list` command (ideal for system wide ruby)
13
+
14
+ # Finally it's matching your gem version against the last version in the rubygem api
15
+ # to determine what is up-to-date
16
+ class Rubygem
17
+
18
+ attr_accessor :path
19
+ attr_accessor :results
20
+
21
+ def initialize &block
22
+ @results = {}
23
+ instance_eval(&block) if block_given?
24
+ self
25
+ end
26
+
27
+ def perform!
28
+ dependencies = @path && gemfilelock_exists? ? deps_from_gemfilelock : deps_from_gem_list
29
+ dependencies.each do |gem_name, gem_version|
30
+ rubygems_response = Net::HTTP.get_response("rubygems.org","/api/v1/gems/#{gem_name}.json")
31
+ if rubygems_response.code.to_i >= 400
32
+ puts "#{rubygems_response.code} on rubygems.org for #{gem_name}: #{rubygems_response.body}"
33
+ next
34
+ end
35
+ newer_version = JSON.parse(rubygems_response.body)['version']
36
+ @results[gem_name] = [gem_version, newer_version] if gem_version != newer_version
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def deps_from_gem_list
43
+ gems = `gem list`.split("\n")
44
+ gems.inject({}) do |list, gem|
45
+ gem_name = gem.split(' ')[0]
46
+ gem_versions = gem.match(/^.+ (\(.+\))$/)[1][1..-2].split(', ')
47
+ list[gem_name] = gem_versions[0]
48
+ list
49
+ end
50
+ end
51
+
52
+ def deps_from_gemfilelock
53
+ list = {}
54
+ specs = Bundler::LockfileParser.new(Bundler.read_file(File.join(@path, "Gemfile.lock"))).specs
55
+ specs.each do |gem|
56
+ list[gem.name] = gem.version.to_s
57
+ end
58
+ list
59
+ end
60
+
61
+ def gemfilelock_exists?
62
+ File.exists?(File.join(@path, "Gemfile.lock"))
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,11 @@
1
+ module CheckZilla
2
+ class CLI < Clamp::Command
3
+ parameter "CONFIGURATION ...", "the configuration file", :attribute_name => :config_file
4
+
5
+ def execute
6
+ conf_relative_path = File::join(Dir.pwd, config_file)
7
+ require conf_relative_path
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module CheckZilla
2
+ class Model
3
+
4
+ attr_reader :checkers, :notifiers
5
+
6
+ def initialize(title = "Report", &block)
7
+ @title = title
8
+ @checkers = []
9
+ @notifiers = []
10
+
11
+ instance_eval(&block) if block_given?
12
+
13
+ @checkers.each do |checker|
14
+ checker.perform!
15
+ end
16
+
17
+ @notifiers.each do |notifier|
18
+ notifier.perform! @checkers
19
+ end
20
+ end
21
+
22
+ def check_updates klass, &block
23
+ @checkers << CheckZilla::Check.const_get(klass.to_s.capitalize).new(&block)
24
+ end
25
+
26
+ def notify_by klass, &block
27
+ @notifiers << CheckZilla::Notifier.const_get(klass.to_s.capitalize).new(&block)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module CheckZilla
2
+ module Notifier
3
+ class Console
4
+ def initialize &block
5
+ end
6
+
7
+ def perform! checkers
8
+ checkers.each do |checker|
9
+ checker_name = checker.class.name.split("::").last
10
+ title = "#{checker_name} Report"
11
+ puts "#{title}\n#{"="*title.size}"
12
+
13
+ checker.results.each do |name, versions|
14
+ local_version = versions[0]
15
+ newer_version = versions[1]
16
+ puts "#{name} from #{local_version} to #{newer_version}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ require 'pony'
2
+
3
+ module CheckZilla
4
+ module Notifier
5
+ class Email
6
+
7
+ attr_accessor :pony_settings
8
+
9
+ def initialize &block
10
+ instance_eval(&block) if block_given?
11
+ self
12
+ end
13
+
14
+ def perform! checkers
15
+ body = []
16
+ checkers.each do |checker|
17
+ checker_name = checker.class.name.split("::").last
18
+ title = "#{checker_name} Report"
19
+ body << "#{title}\n#{"="*title.size}"
20
+
21
+ checker.results.each do |name, versions|
22
+ local_version = versions[0]
23
+ newer_version = versions[1]
24
+ body << "#{name} from #{local_version} to #{newer_version}"
25
+ end
26
+ body << ["\n\n"]
27
+ end
28
+ binding.pry
29
+ Pony.mail(@pony_settings.merge(:body => body.join("\n")))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'hipchat'
2
+
3
+ module CheckZilla
4
+ module Notifier
5
+ class Hipchat
6
+
7
+ attr_accessor :api_token
8
+ attr_accessor :room
9
+ attr_accessor :username
10
+
11
+ def initialize &block
12
+ instance_eval(&block) if block_given?
13
+ self
14
+ end
15
+
16
+ def perform! checkers
17
+ client = HipChat::Client.new(@api_token)
18
+ notify_users = false
19
+
20
+ checkers.each do |checker|
21
+ checker_name = checker.class.name.split("::").last
22
+ title = "#{checker_name} Updates:"
23
+
24
+ body = []
25
+ checker.results.each do |name, versions|
26
+ local_version = versions[0]
27
+ newer_version = versions[1]
28
+ body << "#{name} (#{local_version} -> #{newer_version})"
29
+ end
30
+ client[@room].send(@username, "#{title} #{body.join(', ')}", :notify => true, :color => 'red')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: checkzilla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Bensoussan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: clamp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hipchat
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: clamp
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.3.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: pony
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: CheckZilla is a command line tool allowing you to check and be notified
79
+ of outdated software.
80
+ email:
81
+ - mbensoussan.is@gmail.com
82
+ executables:
83
+ - checkzilla
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - ./lib/checkzilla.rb
88
+ - ./lib/checkzilla/notifier/email.rb
89
+ - ./lib/checkzilla/notifier/console.rb
90
+ - ./lib/checkzilla/notifier/hipchat.rb
91
+ - ./lib/checkzilla/check/npm.rb
92
+ - ./lib/checkzilla/check/rubygem.rb
93
+ - ./lib/checkzilla/check/pacman.rb
94
+ - ./lib/checkzilla/cli.rb
95
+ - ./lib/checkzilla/model.rb
96
+ - ./bin/checkzilla
97
+ - bin/checkzilla
98
+ homepage: http://github.com/mickey/checkzilla
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: 1.3.6
116
+ requirements: []
117
+ rubyforge_project: checkzilla
118
+ rubygems_version: 1.8.24
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: CLI allowing to check and be notified of outdated software
122
+ test_files: []