nod 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/Nod.rb +79 -0
- data/lib/nod/bundle_parser.rb +18 -0
- data/lib/nod/gem_savvy.rb +48 -0
- data/lib/nod/git_cloner.rb +21 -0
- data/lib/nod/license_hunch.rb +30 -0
- metadata +112 -0
data/lib/Nod.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nod/gem_savvy'
|
3
|
+
require 'nod/git_cloner'
|
4
|
+
require 'nod/license_hunch'
|
5
|
+
require 'nod/bundle_parser'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
class Nod
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@basedir = './tmp/git_repos'
|
12
|
+
@git_cloner = GitCloner.new('./tmp/filling-in')
|
13
|
+
@gem_savvy = GemSavvy.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_license_report_for_gem(name)
|
17
|
+
# puts "processing gem #{name}"
|
18
|
+
url = @gem_savvy.git_clone_url name
|
19
|
+
report = {}
|
20
|
+
|
21
|
+
if !url.nil?
|
22
|
+
tmp_dir = "#{@basedir}/#{name}"
|
23
|
+
successful_clone = @git_cloner.clone_url url, tmp_dir
|
24
|
+
if successful_clone && File.exists?(tmp_dir)
|
25
|
+
files_in_repo = Dir.entries(tmp_dir)
|
26
|
+
licenses = files_in_repo.select { |file_name| file_name if file_name =~ /license/i }
|
27
|
+
# puts "licenses is #{licenses}"
|
28
|
+
if !licenses.nil? && licenses.size > 0
|
29
|
+
license_type = LicenseHunch.determine_license_from_file licenses[0], File.expand_path(File.dirname(__FILE__) + "/../#{tmp_dir}")
|
30
|
+
report = {:gem_name => name, :gem_home_page => @gem_savvy.gem_home(name), :gem_source_url => url, :gem_license => license_type}
|
31
|
+
else
|
32
|
+
# puts "no license found for #{@gem_savvy.info_for(name)}"
|
33
|
+
readme = files_in_repo.select { |file_name| file_name if file_name =~ /readme/i }
|
34
|
+
if !readme.nil? && readme.size > 0
|
35
|
+
# puts "\n\ngoing readme route with #{readme}"
|
36
|
+
license_type = LicenseHunch.determine_license_from_file readme[0], File.expand_path(File.dirname(__FILE__) + "/../#{tmp_dir}")
|
37
|
+
# puts "got? #{license_type}"
|
38
|
+
report = {:gem_name => name, :gem_home_page => @gem_savvy.gem_home(name), :gem_source_url => url, :gem_license => license_type}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
else
|
42
|
+
# TODO handle this
|
43
|
+
puts "in else? file didn't exist? gem is #{name}"
|
44
|
+
end #file exists
|
45
|
+
else
|
46
|
+
info = @gem_savvy.info_for(name)
|
47
|
+
# puts "info for #{name} is #{info}"
|
48
|
+
report = {:gem_name => name, :gem_home_page => info['homepage_uri'], :gem_source_url => info['source_code_uri'], :gem_license => 'Cannot determine'}
|
49
|
+
end
|
50
|
+
# puts "returning report for gem #{name} -> #{report}"
|
51
|
+
return report
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_licenses_for(gemfile_path)
|
55
|
+
parser = BundleParser.new(gemfile_path)
|
56
|
+
all_names = parser.gem_names
|
57
|
+
report = []
|
58
|
+
|
59
|
+
all_names.each { | name | report << get_license_report_for_gem(name) }
|
60
|
+
return report
|
61
|
+
end
|
62
|
+
# parse gemfile
|
63
|
+
# for each gem
|
64
|
+
# get source url
|
65
|
+
# if url is git hub
|
66
|
+
# clone
|
67
|
+
# find license file
|
68
|
+
# determine MIT, Apache, etc
|
69
|
+
# if not source URL
|
70
|
+
# check description
|
71
|
+
# if not in description
|
72
|
+
# get home page for rubyforge
|
73
|
+
# parse home page and look for license
|
74
|
+
|
75
|
+
|
76
|
+
# return a report -- it is an [] full of {}s
|
77
|
+
# { :name => 'gem name', :url => 'url', :license => 'MIT|Apache|unknown' }
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
class BundleParser
|
5
|
+
|
6
|
+
def initialize(gemfile_path)
|
7
|
+
@lockfile = Bundler::LockfileParser.new(Bundler.read_file(gemfile_path))
|
8
|
+
end
|
9
|
+
|
10
|
+
def gem_names
|
11
|
+
names = []
|
12
|
+
@lockfile.specs.each do |s|
|
13
|
+
names << s.name
|
14
|
+
end
|
15
|
+
names
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'gems'
|
4
|
+
# see https://gist.github.com/1722530
|
5
|
+
|
6
|
+
class GemSavvy
|
7
|
+
|
8
|
+
# def initialize(gemfile_path)
|
9
|
+
# @lockfile = Bundler::LockfileParser.new(Bundler.read_file(gemfile_path))
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# def names
|
13
|
+
# names = []
|
14
|
+
# @lockfile.specs.each do |s|
|
15
|
+
# names << s.name
|
16
|
+
# end
|
17
|
+
# names
|
18
|
+
# end
|
19
|
+
|
20
|
+
def info_for(gem_name)
|
21
|
+
Gems.info gem_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def gem_home(gem_name)
|
25
|
+
info = info_for gem_name
|
26
|
+
info['homepage_uri']
|
27
|
+
end
|
28
|
+
|
29
|
+
def gem_source_home(gem_name)
|
30
|
+
info = info_for gem_name
|
31
|
+
info['source_code_uri']
|
32
|
+
end
|
33
|
+
|
34
|
+
def git_clone_url(gem_name)
|
35
|
+
http_url = gem_home gem_name
|
36
|
+
if !http_url.nil? && http_url.include?('github.com')
|
37
|
+
"#{http_url.gsub('http://', 'git://')}.git"
|
38
|
+
else
|
39
|
+
http_url = gem_source_home gem_name
|
40
|
+
if !http_url.nil? && http_url.include?('github.com')
|
41
|
+
"#{http_url.gsub('http://', 'git://')}.git"
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'grit'
|
3
|
+
|
4
|
+
class GitCloner
|
5
|
+
|
6
|
+
def initialize(tmp_dir)
|
7
|
+
@tmp_dir = tmp_dir
|
8
|
+
@gritty = Grit::Git.new(tmp_dir)
|
9
|
+
end
|
10
|
+
|
11
|
+
def clone_url(url, to_url)
|
12
|
+
begin
|
13
|
+
@gritty.clone({:quiet => false, :verbose => true, :progress => true}, url, to_url)
|
14
|
+
true
|
15
|
+
rescue
|
16
|
+
puts "couldn't clone #{url}"
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
class LicenseHunch
|
4
|
+
|
5
|
+
def self.determine_license_from_file(license_name, base_path)
|
6
|
+
|
7
|
+
if license_name.downcase.include?('mit')
|
8
|
+
return 'MIT'
|
9
|
+
end
|
10
|
+
|
11
|
+
file_path = "#{base_path}/#{license_name}"
|
12
|
+
is_mit_lic = false
|
13
|
+
File.open(file_path, 'r').each_line do | line |
|
14
|
+
return 'MIT' if line =~ /MIT License/i
|
15
|
+
end
|
16
|
+
|
17
|
+
all_text = File.open(file_path).read.gsub(/\n/,' ')
|
18
|
+
|
19
|
+
phrase_1 = "to deal in the Software without restriction"
|
20
|
+
phrase_2 = "Permission is hereby granted, free of charge, to any person obtaining"
|
21
|
+
phrase_3 = "use, copy, modify, merge, publish"
|
22
|
+
phrase_4 = "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY"
|
23
|
+
phrase_5 = "distribute, sublicense"
|
24
|
+
return 'MIT' if (all_text =~ /#{phrase_1}/i && all_text =~ /#{phrase_2}/i && all_text =~ /#{phrase_3}/i && all_text =~ /#{phrase_4}/ && all_text =~ /#{phrase_5}/ )
|
25
|
+
|
26
|
+
return 'Unknown'
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Glover
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-08-28 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.21
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: gems
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.7.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: grit
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.9.2
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: nokogiri
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.5.5
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
70
|
+
description: Gem reports on gemfile licenses
|
71
|
+
email: ajglover@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files: []
|
77
|
+
|
78
|
+
files:
|
79
|
+
- lib/Nod.rb
|
80
|
+
- lib/nod/gem_savvy.rb
|
81
|
+
- lib/nod/git_cloner.rb
|
82
|
+
- lib/nod/license_hunch.rb
|
83
|
+
- lib/nod/bundle_parser.rb
|
84
|
+
homepage: https://github.com/aglover/green_light
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.15
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Green Light OSS baby
|
111
|
+
test_files: []
|
112
|
+
|