gems-status 0.49.0 → 0.50.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.49.0
1
+ 0.50.0
data/bin/gems-status CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/ruby
2
+ # -*- coding: UTF-8 -*-
3
+
4
+ require "erb"
2
5
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
6
  require "gems-status"
4
7
 
@@ -19,9 +22,9 @@ end
19
22
 
20
23
  conf_file = ARGV[0]
21
24
  begin
22
- conf = YAML::load(File::open(conf_file))
25
+ conf = YAML::load(ERB.new(File::read(conf_file)).result)
23
26
  rescue
24
- Utils::log_error("?", "There was a problem opening #{conf_file}")
27
+ GemsStatus::Utils::log_error("?", "There was a problem opening #{conf_file}")
25
28
  end
26
29
  gs = GemsStatus::GemStatus.new(conf)
27
30
  gs.execute
data/lib/gems-status.rb CHANGED
@@ -15,12 +15,12 @@ module GemsStatus
15
15
  class GemStatus
16
16
  def initialize(conf)
17
17
  @conf = conf
18
+ Utils::known_licenses = @conf["licenses"]
18
19
  @gems_composite_command = nil
19
- @gems_composite_command = GemsCompositeCommand.new(@conf["target"])
20
- @conf["sources"].each do |c|
21
- gems = eval(c["classname"]).new(c)
22
- @gems_composite_command.add_command(gems)
23
- end
20
+ @gems_composite_command = GemsCompositeCommand.new
21
+ c = @conf["source"]
22
+ gems = eval(c["classname"]).new(c)
23
+ @gems_composite_command.command = gems
24
24
  if @conf["checkers"]
25
25
  @conf["checkers"].each do |c|
26
26
  checker = eval(c["classname"]).new(c)
@@ -1,11 +1,11 @@
1
- require "gems-status/checkers/exists_in_upstream"
1
+ require "gems-status/checkers/is_rubygems"
2
2
  require "gems-status/checkers/git_check_messages"
3
3
  require "gems-status/checkers/hg_check_messages"
4
4
  require "gems-status/checkers/not_a_security_alert_checker"
5
- require "gems-status/checkers/not_native_gem_checker"
6
- require "gems-status/checkers/not_rails_checker"
7
5
  require "gems-status/checkers/scm_check_messages"
8
6
  require "gems-status/checkers/scm_security_messages"
9
7
  require "gems-status/checkers/svn_check_messages"
10
8
  require "gems-status/checkers/print_gem_versions"
9
+ require "gems-status/checkers/has_a_license"
10
+ require "gems-status/checkers/is_not_gpl"
11
11
 
@@ -0,0 +1,12 @@
1
+ module GemsStatus
2
+ class HasALicense
3
+ def initialize(conf)
4
+ end
5
+ def check?(gem)
6
+ gem.license && !gem.license.empty?
7
+ end
8
+ def description
9
+ "This gem has not license"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module GemsStatus
2
+ class IsNotGpl
3
+ def initialize(conf)
4
+ end
5
+ def check?(gem)
6
+ if !gem.license || gem.license.empty?
7
+ return true
8
+ end
9
+ gem.license.upcase != "GPL"
10
+ end
11
+ def description
12
+ "This gem is GPL"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'open-uri'
3
+ require 'gems-status/checkers/gem_checker'
4
+ require 'gems-status/utils'
5
+
6
+ module GemsStatus
7
+
8
+ class IsRubygems < GemChecker
9
+
10
+ def initialize(configuration)
11
+ @md5 = nil
12
+ @gem_md5 = nil
13
+ super configuration
14
+ end
15
+
16
+ def check?(gem)
17
+ Utils::log_debug("Looking for #{gem.name}")
18
+ result = nil
19
+ gem_uri = "http://rubygems.org/downloads/#{gem.name}-#{gem.version}.gem"
20
+ @md5 = Utils::download_md5(gem.name, gem.version, "http://rubygems.org/downloads")
21
+ @gem_md5 = gem.md5
22
+ !@md5 && !@gem_md5 && @gem_md5== @md5
23
+ end
24
+
25
+ def description
26
+ if !@md5
27
+ "This gem does not exist in rubygems.org "
28
+ elsif !@gem_md5
29
+ "This gem does not exist in your server"
30
+ elsif @md5 != @gem_md5
31
+ "This gem has a different md5sum than in rubygems.org\nrubygems: #{@md5} your server #{@gem_md5}"
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -14,12 +14,7 @@ module GemsStatus
14
14
  class NotASecurityAlertChecker < GemChecker
15
15
  def initialize(conf)
16
16
  Utils::check_parameters('NotASecurityAlertChecker', conf, ["fixed", "source_repos", "email_username", "email_password", "mailing_lists", "email_to"])
17
- begin
18
- @fixed = YAML::load(File::open(conf["fixed"]))
19
- rescue
20
- Utils::log_error("?", "There was a problem opening #{conf["fixed"]}")
21
- @fixed = []
22
- end
17
+ @fixed = conf["fixed"]
23
18
  @source_repos = conf["source_repos"]
24
19
  @security_messages = {}
25
20
  @email_username = conf["email_username"]
@@ -2,13 +2,7 @@ module GemsStatus
2
2
 
3
3
  class PrintGemVersions
4
4
  def initialize(conf)
5
- Utils::check_parameters('PrintGemVersions', conf, ["licenses"])
6
- begin
7
- @licenses = YAML::load(File::open(conf["licenses"]))
8
- rescue
9
- Utils::log_error("?", "There was a problem opening #{conf["licenses"]}")
10
- @licenses = []
11
- end
5
+ @licenses = Utils::known_licenses
12
6
  end
13
7
 
14
8
  def check?(gem)
@@ -11,37 +11,15 @@ module GemsStatus
11
11
  @dependencies = dependencies
12
12
  end
13
13
 
14
- #TODO: write a test for this
15
- def depends?(gem)
16
- if !@dependencies
17
- Utils::log_error(@name, "trying to get depends on a gem that has no info on dependencies #{@name} depends #{gem.name}")
18
- return false
19
- end
20
- @dependencies.each do |dep|
21
- return true if dep.name == gem.name
22
- end
23
- return false
14
+ def from_git?
15
+ return @gems_url && @gems_url.start_with?("git://")
24
16
  end
25
17
 
26
- #TODO: write a test for this
27
- def merge_deps(gem)
28
- if !@dependencies || !gem.dependencies
29
- Utils::log_error(@name, "trying to merge depends on a gem that has no info on dependencies #{@name} merge #{gem.name}")
30
- return false
31
- end
32
- changes = false
33
- gem.dependencies.each do |dep|
34
- if !@dependencies.include?(dep)
35
- changes = true
36
- @dependencies << dep
37
- Utils::log_debug("adding #{dep} to dependencies")
38
- end
18
+ def license
19
+ if from_git?
20
+ return nil
39
21
  end
40
- return changes
41
- end
42
-
43
- def from_git?
44
- return @gems_url && @gems_url.start_with?("git://")
22
+ Utils::download_license(@name, @version, @gems_url)
45
23
  end
46
24
 
47
25
  def date
@@ -1,23 +1,18 @@
1
1
  require "gems-status/gem_simple"
2
2
  require "gems-status/gems_command"
3
- require "gems-status/html_view"
3
+ require "gems-status/text_view"
4
4
 
5
5
  module GemsStatus
6
6
 
7
7
  class GemsCompositeCommand < GemsCommand
8
- attr_accessor :results, :checker_results
8
+ attr_accessor :results, :checker_results, :command
9
9
 
10
- def initialize(target)
11
- @commands = []
10
+ def initialize
11
+ @command = []
12
12
  @checkers = []
13
13
  @checker_results = {}
14
14
  @comments = {}
15
- @results = {}
16
- @target = target
17
- end
18
-
19
- def add_command(command)
20
- @commands << command
15
+ @results = []
21
16
  end
22
17
 
23
18
  def add_checker(check_object)
@@ -25,88 +20,38 @@ module GemsStatus
25
20
  end
26
21
 
27
22
  def execute
28
- threads = []
29
- if !@commands then
30
- return
31
- end
32
- @commands.each do |command|
33
- threads << Thread.new { command.execute }
34
- end
35
- threads.each { |aThread| aThread.join }
36
- @commands.each do |command|
37
- @results[command.ident] = command.result
38
- end
23
+ return unless @command
24
+ @command.execute
25
+ @results << @command.result
39
26
  @checkers.each do |check_object|
40
27
  Utils::log_debug "checking #{check_object.class.name}"
41
- @results[@target].sort.each do |k, gems|
42
- gems.each do |gem|
28
+ @results.each do |gems|
29
+ gems.each do |name, gem|
43
30
  if !check_object.check?(gem)
44
- @checker_results[k] = {} unless @checker_results[k]
45
- @checker_results[gem.name][check_object.class.name] = "
46
- <br/>#{gem.name} #{gem.version} #{gem.origin}: <br/>
47
- #{check_object.description} "
31
+ @checker_results[name] = {} unless @checker_results[name]
32
+ @checker_results[gem.name][check_object.class.name] = "#{check_object.description}"
48
33
  end
49
34
  end
50
35
  end
51
36
  end
52
37
  end
53
38
 
54
- def common_key?(k)
55
- if !are_there_results?
56
- return false
57
- end
58
- @results.each do |key, result|
59
- if !result[k] then
60
- return false
61
- end
62
- end
63
- return true
64
- end
65
-
66
39
  def add_comments(comments)
67
40
  @comments = comments
68
41
  end
69
42
 
70
43
  def are_there_results?
71
- if !@results or @results.empty?
72
- return false
73
- end
74
- if !@results.has_key?(@target)
75
- return false
76
- end
77
- if @results.length<2
78
- return false
79
- end
80
- return true
44
+ return @results && !@results.empty?
81
45
  end
82
46
 
83
47
  def print
84
- html_view = HTMLView.new
85
- html_view.print_head
86
- ids = []
87
- @commands.each { |c| ids << c.ident }
88
- html_view.print_description(ids)
89
- if !are_there_results?
90
- return
91
- end
92
- @results[@target].sort.each do |k,v|
93
- if !common_key?(k) then
94
- Utils::log_error(k, "#{k} in #{@target} but not found in all the sources!")
95
- end
96
- if @checker_results[k]
97
- checker_results = @checker_results[k]
98
- else
99
- checker_results = nil
100
- end
101
- if @comments[k]
102
- comments = @comments[k]
103
- else
104
- comments = nil
105
- end
106
- html_view.print_results(k, @results, @target, checker_results, comments)
107
- @comments.delete(k)
108
- end
109
- html_view.print_tail(@checker_results, @comments)
48
+ return if !are_there_results?
49
+ view = TextView.new
50
+ view.print_head
51
+ ids = @command.filename
52
+ view.print_description(ids)
53
+ view.print_results(@results, @checker_results, @comments)
54
+ view.print_tail
110
55
  end
111
56
  end
112
57
  end
@@ -1,3 +1 @@
1
- require "gems-status/sources/obs_gems"
2
1
  require "gems-status/sources/lockfile_gems"
3
- require "gems-status/sources/ruby_gems_gems"
@@ -11,13 +11,13 @@ require "gems-status/utils"
11
11
  module GemsStatus
12
12
 
13
13
  class LockfileGems < GemsCommand
14
+ attr_reader :filename
14
15
  def initialize(conf)
15
- Utils::check_parameters('LockfileGems', conf, ["id", "filenames", "gems_url", "upstream_url"])
16
- @filenames = conf['filenames']
16
+ Utils::check_parameters('LockfileGems', conf, ["id", "filename", "gems_url"])
17
+ @filename = conf['filename']
17
18
  @gems_url = conf['gems_url']
18
19
  @result = {}
19
20
  @ident = conf['id']
20
- @upstream_url = conf['upstream_url']
21
21
  end
22
22
 
23
23
  def get_data(dirname, filename)
@@ -45,47 +45,30 @@ module GemsStatus
45
45
  return changes
46
46
  end
47
47
 
48
- def update_dependencies
49
- changes = false
50
- @result.each do |k, gems|
51
- gems.each do |gem|
52
- changes = update_gem_dependencies(gem) || changes
53
- end
54
- end
55
- update_dependencies if changes
56
- end
57
-
58
48
  def execute
59
- @filenames.each do |filename|
60
- Utils::log_debug "reading #{filename}"
61
- Dir.chdir(File.dirname(filename)) do
62
- file_data = get_data(File::dirname(filename), File::basename(filename))
63
- if file_data.empty?
64
- Utils::log_error("?", "file empty #{filename}")
65
- next
66
- end
67
- lockfile = Bundler::LockfileParser.new(file_data)
68
- lockfile.specs.each do |spec|
69
- name = spec.name
70
- version = Gem::Version.create(spec.version)
71
- dependencies = spec.dependencies
72
- Utils::log_debug "dependencies for #{name} #{dependencies}"
73
- if spec.source.class.name == "Bundler::Source::Git"
74
- Utils::log_debug "this comes from git #{name} #{version}"
75
- gems_url = spec.source.uri
76
- else
77
- gems_url = @gems_url
78
- end
79
- @result[name] = [] if !@result[name]
80
- @result[name] << RubyGemsGems_GemSimple.new(name, version , '', filename,
81
- gems_url, dependencies)
82
- @result[name] << RubyGemsGems_GemSimple.new(name, version , '', @upstream_url,
83
- @upstream_url, dependencies)
49
+ Utils::log_debug "reading #{@filename}"
50
+ Dir.chdir(File.dirname(@filename)) do
51
+ file_data = get_data(File::dirname(@filename), File::basename(@filename))
52
+ if file_data.empty?
53
+ Utils::log_error("?", "file empty #{@filename}")
54
+ next
55
+ end
56
+ lockfile = Bundler::LockfileParser.new(file_data)
57
+ lockfile.specs.each do |spec|
58
+ name = spec.name
59
+ version = Gem::Version.create(spec.version)
60
+ dependencies = spec.dependencies
61
+ Utils::log_debug "dependencies for #{name} #{dependencies}"
62
+ if spec.source.class.name == "Bundler::Source::Git"
63
+ Utils::log_debug "this comes from git #{name} #{version}"
64
+ gems_url = spec.source.uri
65
+ else
66
+ gems_url = @gems_url
84
67
  end
68
+ @result[name] = RubyGemsGems_GemSimple.new(name, version , '', @filename,
69
+ gems_url, dependencies)
85
70
  end
86
- update_dependencies
87
71
  end
88
72
  end
89
-
90
73
  end
91
74
  end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'gems-status/gems_status_metadata'
3
+ require 'gems-status/utils'
4
+
5
+ module GemsStatus
6
+
7
+ class TextView
8
+
9
+ def print_description(app)
10
+ puts "gems-status report for #{app}"
11
+ puts "---"
12
+ end
13
+
14
+ def print_results(results, checker_results, comments)
15
+ results.each do |result|
16
+ result.each do |_, gem|
17
+ puts "#{gem.name}: #{gem.version} #{gem.license}"
18
+ next unless checker_results[gem.name]
19
+ checker_results[gem.name].each do |_, msg|
20
+ puts "#{msg}"
21
+ end
22
+ puts "#{comments[gem.name]}" if comments[gem.name]
23
+ puts ""
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ def print_head
30
+ end
31
+
32
+ def print_tail
33
+ puts "---"
34
+ date = Time.now.strftime('%a %b %d %H:%M:%S %Z %Y')
35
+ puts "run by https://github.com/jordimassaguerpla/gems-status"
36
+ puts "#{date} - version: #{GemsStatus::VERSION}"
37
+ end
38
+
39
+ end
40
+ end