deriving_license 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -6,69 +6,89 @@ Finds the license agreements for all gems in your Gemfile. This is achieved by r
6
6
  Strategies:
7
7
  * from\_gem\_specification
8
8
  * from\_license\_file (not yet implemented)
9
- * from\_scraping\_homepage (not yet implemented)
9
+ * from\_scraping\_homepage
10
10
  * from\_parsing\_readme (not yet implemented)
11
11
 
12
12
  Example output:
13
13
 
14
- $ deriving_license ~/Code/rails-sample-app/Gemfile
14
+ $ deriving_license ../bc/A-A/Gemfile
15
15
  Determining license for rails:
16
16
  Trying from_gem_specification strategy...FAILED
17
+ Trying from_scraping_homepage strategy...SUCCESS
17
18
  Determining license for adt:
18
19
  Trying from_gem_specification strategy...FAILED
20
+ Trying from_scraping_homepage strategy...FAILED
19
21
  Determining license for app_constants:
20
22
  Trying from_gem_specification strategy...FAILED
23
+ Trying from_scraping_homepage strategy...SUCCESS
21
24
  Determining license for bcrypt-ruby:
22
25
  Trying from_gem_specification strategy...FAILED
26
+ Trying from_scraping_homepage strategy...FAILED
23
27
  Determining license for bootstrap-sass:
24
28
  Trying from_gem_specification strategy...FAILED
29
+ Trying from_scraping_homepage strategy...FAILED
25
30
  Determining license for jquery-rails:
26
31
  Trying from_gem_specification strategy...SUCCESS
27
32
  Determining license for json:
28
33
  Trying from_gem_specification strategy...SUCCESS
29
34
  Determining license for nokogiri:
30
35
  Trying from_gem_specification strategy...FAILED
36
+ Trying from_scraping_homepage strategy...SUCCESS
31
37
  Determining license for pg:
32
38
  Trying from_gem_specification strategy...SUCCESS
33
39
  Determining license for quiet_assets:
34
40
  Trying from_gem_specification strategy...FAILED
41
+ Trying from_scraping_homepage strategy...SUCCESS
35
42
  Determining license for rack-protection:
36
43
  Trying from_gem_specification strategy...FAILED
44
+ Trying from_scraping_homepage strategy...FAILED
37
45
  Determining license for symmetric-encryption:
38
46
  Trying from_gem_specification strategy...FAILED
47
+ Trying from_scraping_homepage strategy...SUCCESS
39
48
  Determining license for newrelic_rpm:
40
49
  Trying from_gem_specification strategy...FAILED
50
+ Trying from_scraping_homepage strategy...SUCCESS
41
51
  Determining license for uglifier:
42
52
  Trying from_gem_specification strategy...SUCCESS
43
53
  Determining license for sass-rails:
44
54
  Trying from_gem_specification strategy...FAILED
55
+ Trying from_scraping_homepage strategy...FAILED
45
56
  Determining license for coffee-rails:
46
57
  Trying from_gem_specification strategy...FAILED
58
+ Trying from_scraping_homepage strategy...FAILED
47
59
  Determining license for rspec-rails:
48
60
  Trying from_gem_specification strategy...SUCCESS
49
61
  Determining license for capybara:
50
62
  Trying from_gem_specification strategy...FAILED
63
+ Trying from_scraping_homepage strategy...SUCCESS
51
64
  Determining license for factory_girl_rails:
52
65
  Trying from_gem_specification strategy...FAILED
66
+ Trying from_scraping_homepage strategy...SUCCESS
53
67
  Determining license for faker:
54
68
  Trying from_gem_specification strategy...FAILED
69
+ Trying from_scraping_homepage strategy...SUCCESS
55
70
  Determining license for better_errors:
56
71
  Trying from_gem_specification strategy...SUCCESS
57
72
  Determining license for binding_of_caller:
58
73
  Trying from_gem_specification strategy...FAILED
74
+ Trying from_scraping_homepage strategy...SUCCESS
59
75
  Determining license for debugger:
60
76
  Trying from_gem_specification strategy...SUCCESS
61
77
  Determining license for simplecov:
62
78
  Trying from_gem_specification strategy...FAILED
79
+ Trying from_scraping_homepage strategy...SUCCESS
63
80
  Determining license for ci_reporter:
64
81
  Trying from_gem_specification strategy...FAILED
82
+ Trying from_scraping_homepage strategy...SUCCESS
65
83
  Determining license for sqlite3:
66
84
  Trying from_gem_specification strategy...FAILED
85
+ Trying from_scraping_homepage strategy...FAILED
67
86
  Determining license for mysql2:
68
87
  Trying from_gem_specification strategy...FAILED
88
+ Trying from_scraping_homepage strategy...SUCCESS
69
89
 
70
90
  Detected 4 known licenses:
71
- MIT: Expat License (4 instances)[http://directory.fsf.org/wiki/License:Expat]
72
- Ruby: Ruby License (2 instances)[http://www.ruby-lang.org/en/about/license.txt]
91
+ MIT: Expat License (12 instances)[http://directory.fsf.org/wiki/License:Expat]
92
+ Ruby: Ruby License (6 instances)[http://www.ruby-lang.org/en/about/license.txt]
73
93
  BSD: FreeBSD Copyright (2 instances)[http://www.freebsd.org/copyright/freebsd-license.html]
74
- GPL: GNU General Public License (1 instance)[http://en.wikipedia.org/wiki/GNU_General_Public_License]
94
+ GPL: GNU General Public License (2 instances)[http://en.wikipedia.org/wiki/GNU_General_Public_License]
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'deriving_license'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.summary = "Deriving Licence finds the license agreements for all gems in your Gemfile"
5
5
  s.description = "Deriving Licence finds the license agreements for all gems in your Gemfile if included in your project, or in a Gemfile passed to the included binary"
6
6
  s.authors = ["Tom Allen"]
@@ -15,4 +15,5 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_runtime_dependency "gemnasium-parser"
17
17
  s.add_runtime_dependency "safe_yaml"
18
+ s.add_runtime_dependency "curb"
18
19
  end
@@ -1,7 +1,7 @@
1
1
  require "gemnasium/parser"
2
2
  require "bundler"
3
3
  require "safe_yaml"
4
- require "open-uri"
4
+ require "curb"
5
5
 
6
6
  class DerivingLicense
7
7
 
@@ -33,6 +33,8 @@ class DerivingLicense
33
33
  "from_gem_specification",
34
34
  "from_scraping_homepage"
35
35
  ]
36
+
37
+ @@specs_cache = {} # Cache of gem specifications previously fetched.
36
38
 
37
39
  def self.run(path=nil)
38
40
  unless path
@@ -97,12 +99,16 @@ class DerivingLicense
97
99
  end
98
100
 
99
101
  def self.get_gem_spec(dep)
102
+ # Check spec cache first.
103
+ @spec = @@specs_cache[dep]
104
+ return @spec if @spec
100
105
  # See if the gem is installed locally, and if not add -r to call
101
106
  Bundler.with_clean_env do # This gets out of the bundler context.
102
107
  remote = /#{dep}/.match( `gem list #{dep}` ) ? "" : "-r "
103
108
  yaml = `gem specification #{remote}#{dep} --yaml`
104
109
  @spec = YAML.load(yaml, :safe => true)
105
110
  end
111
+ @@specs_cache[dep] = @spec # Cache it.
106
112
  @spec
107
113
  end
108
114
 
@@ -121,11 +127,15 @@ class DerivingLicense
121
127
  def self.from_scraping_homepage(dep)
122
128
  spec = get_gem_spec(dep)
123
129
  licenses = []
124
- unless spec["homepage"]
125
- []
130
+ unless spec["homepage"] and !spec["homepage"].empty?
131
+ return []
132
+ end
133
+ begin
134
+ content = Curl::Easy.perform(spec["homepage"]){|easy| easy.follow_location = true; easy.max_redirects=nil}.body_str
135
+ rescue
136
+ return []
126
137
  end
127
- content = open(spec["homepage"])
128
- content.each_line do |l|
138
+ content.split('\n').each do |l|
129
139
  if /license/.match(l)
130
140
  # Found the word "license", so now look for known license names.
131
141
  (@@license_details.keys + @@license_aliases.keys).each do |n|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deriving_license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: curb
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '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'
46
62
  description: Deriving Licence finds the license agreements for all gems in your Gemfile
47
63
  if included in your project, or in a Gemfile passed to the included binary
48
64
  email: tom@jugglethis.net