deriving_license 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/deriving_license +3 -1
- data/deriving_license.gemspec +1 -1
- data/lib/deriving_license.rb +45 -2
- metadata +1 -1
data/bin/deriving_license
CHANGED
data/deriving_license.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'deriving_license'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.3'
|
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"]
|
data/lib/deriving_license.rb
CHANGED
@@ -2,6 +2,24 @@ require "gemnasium/parser"
|
|
2
2
|
require "bundler"
|
3
3
|
|
4
4
|
class DerivingLicense
|
5
|
+
|
6
|
+
attr_reader :license_details, :license_aliases
|
7
|
+
|
8
|
+
# TODO: Scrape http://www.gnu.org/licenses/license-list.html#SoftwareLicenses
|
9
|
+
# and auto-magically generate these details.
|
10
|
+
@@license_details = {
|
11
|
+
# key -> hash of (Name, Link, [Tags]), where tags is an array that may include [:gpl_compatible, :copyleft_compatible, :has_restrictions]
|
12
|
+
"GPL" => {name:"GNU General Public License",link:"http://en.wikipedia.org/wiki/GNU_General_Public_License",tags:[:gpl_compatible, :copyleft_compatible, :has_restrictions]},
|
13
|
+
"MIT" => {name:"Expat License",link:"http://directory.fsf.org/wiki/License:Expat",tags:[:gpl_compatible, :has_restrictions]},
|
14
|
+
"BSD" => {name:"FreeBSD Copyright",link:"http://www.freebsd.org/copyright/freebsd-license.html",tags:[:gpl_compatible, :copyleft_compatible, :has_restrictions]}
|
15
|
+
}
|
16
|
+
|
17
|
+
@@license_aliases = {
|
18
|
+
# hash of names to keys of the license in the master list.
|
19
|
+
"FreeBSD" => "BSD",
|
20
|
+
"Expat" => "MIT"
|
21
|
+
}
|
22
|
+
|
5
23
|
def self.run(path=nil)
|
6
24
|
unless path
|
7
25
|
raise ArgumentError.new("Path to Gemfile or Gemspec required")
|
@@ -24,12 +42,37 @@ class DerivingLicense
|
|
24
42
|
# See if it's installed locally, and if not add -r to call
|
25
43
|
Bundler.with_clean_env do # This gets out of the bundler context.
|
26
44
|
remote = /#{d.name}/.match( `BUNDLE_GEMFILE=#{path}; gem list #{d.name}` ) ? "" : "-r "
|
27
|
-
print "Determining license for #{d.name}#{remote.empty? ? "" : " (remote call required)"}..."
|
45
|
+
print "Determining license for #{d.name}#{remote.empty? ? "" : " (remote call required)"}..."
|
28
46
|
@spec = eval `gem specification #{remote}#{d.name} --ruby`
|
29
47
|
end
|
30
|
-
print "
|
48
|
+
print "#{@spec.licenses.empty? ? "UNKNOWN" : "SUCCESS"}\n"
|
31
49
|
@spec.licenses.each{ |l| licenses[l]+=1 }
|
32
50
|
end
|
33
51
|
licenses
|
34
52
|
end
|
53
|
+
|
54
|
+
def self.describe(licenses)
|
55
|
+
# Print link to description of each license type, then attempt to determine
|
56
|
+
# whether any notable restrictions apply (e.g. you can't sell this project,
|
57
|
+
# you must include a copy of the GPL, etc)
|
58
|
+
unknowns = []
|
59
|
+
output = []
|
60
|
+
licenses.each do |l|
|
61
|
+
instances = "(#{l.last} instance#{l.last == 1 ? "" : "s"})"
|
62
|
+
key = @@license_aliases[l.first]
|
63
|
+
key ||= l.first
|
64
|
+
if @@license_details[key]
|
65
|
+
output << "#{key}: #{@@license_details[key][:name]} #{instances}[#{@@license_details[key][:link]}]"
|
66
|
+
else
|
67
|
+
unknowns << key
|
68
|
+
end
|
69
|
+
end
|
70
|
+
unless output.empty?
|
71
|
+
puts "Detected #{output.count} known license#{output.count==1 ? "" : "s"}:"
|
72
|
+
output.each{|o| puts o}
|
73
|
+
end
|
74
|
+
unless unknowns.empty?
|
75
|
+
puts "There #{unknowns.count==1 ? "is" : "are"} also #{unknowns.count} unknown license#{unknowns.count==1 ? "" : "s"}: #{unknowns.join(', ')}"
|
76
|
+
end
|
77
|
+
end
|
35
78
|
end
|