license_scout 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ca7856e42ab2d7004c0e839c6ca76d8469fc1a576bcec0fdb2531e047c7ae8
4
- data.tar.gz: dc19f95eaabff06016349cbfedfe786ffe4a44495f3fefc7bdf585aa9212d7c1
3
+ metadata.gz: 4f4c5bbed2fd2e2af64f8340ebb749ddd4769c5272160d96c945993c4ecd68cf
4
+ data.tar.gz: 858f07c4c6a5c158298f69da7c19bc58c4b316e29d5da0bfd85111ce9716669f
5
5
  SHA512:
6
- metadata.gz: df5e1640eeddbac7d2e36ee9ce3ead1195facf295e366e49a86e526150c7018ffd7e606d8d107286c932a63f0c6715e22776ba71d06d635c8182db0d117d6e21
7
- data.tar.gz: 503398a3e3f5e82481502fbc8e2debf31be840def48592d928bd7fa96aa26415495b1b2e27c7c5ffd0b968b352cb3e821080dcbad0d0c3947e4ea199c892d5a3
6
+ metadata.gz: 772a4366a8b3d14e344c1bdc7968ecb6063118c0a233c532c42c5e5f476d92110fb305bd9682504863b6cd6d27bec7b8870db9454187f920305451a0366a9297
7
+ data.tar.gz: be2e31e7763fc433c5ccf07778158d8d1877f9c3ff857b6148fa2f9137641bf005d5ab0c1373bae3927281eb15903e9f988efbb76ff92a71a5d5fa5760c4fc33
data/README.md CHANGED
@@ -179,6 +179,22 @@ license_content | A URL to a file where the raw text of the license can be downl
179
179
 
180
180
  In addition to including any files Licensee identified as potential license files (but couldn't identify), License Scout will also include the Fallback License you specified in the Dependency Manifest.
181
181
 
182
+ ## Exporting a Dependency Manifest to another format
183
+
184
+ By default, License Scout creates the Dependency Manifest as a JSON file. We do this because it provides a single document that can be easily processed into many different forms. License Scout has the ability to also export that JSON file into other formats.
185
+
186
+ ### Usage
187
+
188
+ ```
189
+ license_scout export [PATH_TO_JSON_FILE] --format FORMAT
190
+ ```
191
+ ### Support Formats
192
+
193
+ Format | Description
194
+ --- | ---
195
+ `csv` | Export the contents of the JSON file into a CSV.
196
+
197
+
182
198
  ## Configuration
183
199
 
184
200
  Value | Description | Default
@@ -19,6 +19,7 @@ require "zlib" # Temporarily require before rugged to fix https://github.com/pro
19
19
 
20
20
  require "mixlib/cli"
21
21
  require "license_scout/config"
22
+ require "license_scout/exporter"
22
23
  require "license_scout/collector"
23
24
  require "license_scout/reporter"
24
25
 
@@ -41,10 +42,17 @@ module LicenseScout
41
42
  description: "Comma-separated list of directories to scan",
42
43
  proc: Proc.new { |d| d.split(",") }
43
44
 
45
+ option :format,
46
+ long: "--format FORMAT",
47
+ description: "When exporting a Dependency Manifest, export to this format",
48
+ in: LicenseScout::Exporter.supported_formats
49
+
44
50
  option :log_level,
45
51
  short: "-l LEVEL",
46
52
  long: "--log-level LEVEL",
47
- description: "Set the log level (debug, info, warn, error, fatal)",
53
+ description: "Set the log level",
54
+ in: [:debug, :info, :warn, :error, :fatal],
55
+ default: :info,
48
56
  proc: Proc.new { |l| l.to_sym }
49
57
 
50
58
  option :only_show_failures,
@@ -94,11 +102,20 @@ module LicenseScout
94
102
 
95
103
  LicenseScout::Config.validate!
96
104
 
97
- collector = LicenseScout::Collector.new
98
- collector.collect
105
+ case cli_arguments[0]
106
+ when "export"
107
+ json_file = cli_arguments[1]
108
+ export_format = config[:format]
109
+
110
+ exporter = LicenseScout::Exporter.new(json_file, export_format)
111
+ exporter.export
112
+ else
113
+ collector = LicenseScout::Collector.new
114
+ collector.collect
99
115
 
100
- reporter = LicenseScout::Reporter.new(collector.dependencies)
101
- reporter.report
116
+ reporter = LicenseScout::Reporter.new(collector.dependencies)
117
+ reporter.report
118
+ end
102
119
  end
103
120
  end
104
121
  end
@@ -20,5 +20,6 @@ module LicenseScout
20
20
  class Error < RuntimeError; end
21
21
  class ConfigError < Error; end
22
22
  class MissingSourceDirectory < Error; end
23
+ class UnsupportedExporter < Error; end
23
24
  end
24
25
  end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Copyright:: Copyright 2016, Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "license_scout/exporter/csv"
19
+
20
+ module LicenseScout
21
+ class Exporter
22
+
23
+ attr_reader :json_file
24
+ attr_reader :export_format
25
+ attr_reader :exporter
26
+
27
+ def initialize(json_file, export_format)
28
+ @json_file = json_file
29
+ @export_format = export_format
30
+
31
+ @exporter = case export_format
32
+ when "csv"
33
+ LicenseScout::Exporter::CSV.new(json_file)
34
+ else
35
+ # We shouldn't ever hit this, because the CLI filters out unsupported formats. But just in case...
36
+ raise LicenseScout::Exceptions::UnsupportedExporter.new("'#{export_format}' is not a supported format. Please use one of the following: #{supported_formats.join(", ")}")
37
+ end
38
+ end
39
+
40
+ def self.supported_formats
41
+ [
42
+ "csv",
43
+ ]
44
+ end
45
+
46
+ def export
47
+ LicenseScout::Log.info("[exporter] Exporting #{json_file} to '#{export_format}'")
48
+ exporter.export
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright:: Copyright 2016, Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "csv"
19
+
20
+ module LicenseScout
21
+ class Exporter
22
+ class CSV
23
+
24
+ attr_reader :json
25
+ attr_reader :output_file
26
+
27
+ def initialize(json_file)
28
+ @json = FFI_Yajl::Parser.parse(File.read(json_file))
29
+ @output_file = json_file.gsub("json", "csv")
30
+ end
31
+
32
+ def export
33
+ headers = [
34
+ "Type",
35
+ "Name",
36
+ "Version",
37
+ "Has Exception",
38
+ "Exception Reason",
39
+ "License ID",
40
+ "License Source",
41
+ "License Content",
42
+ ]
43
+
44
+ ::CSV.open(output_file, "w+") do |csv|
45
+ csv << headers
46
+
47
+ json["dependencies"].each do |dependency|
48
+ type = dependency["type"]
49
+ name = dependency["name"]
50
+ version = dependency["version"]
51
+ has_exception = dependency["has_exception"]
52
+ exception_reason = dependency["exception_reason"]
53
+ licenses = dependency["licenses"]
54
+
55
+ licenses.each do |license|
56
+ id = license["id"]
57
+ source = license["source"]
58
+ content = license["content"]
59
+
60
+ csv << [
61
+ type,
62
+ name,
63
+ version,
64
+ (has_exception.nil? ? "Yes" : "No"),
65
+ (exception_reason.nil? ? "" : exception_reason),
66
+ id,
67
+ source,
68
+ content
69
+ ]
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -94,7 +94,6 @@ module LicenseScout
94
94
 
95
95
  def special_cases
96
96
  {
97
- # Pulled from http://search.cpan.org/~dagolden/CPAN-Meta-2.150010/lib/CPAN/Meta/Spec.pm#license
98
97
  "agpl_3" => "AGPL-3.0",
99
98
  "apache_1_1" => "Apache-1.1",
100
99
  "apache_2_0" => "Apache-2.0",
@@ -109,6 +108,8 @@ module LicenseScout
109
108
  "mit" => "MIT",
110
109
  "mozilla_1_0" => "MPL-1.0",
111
110
  "mozilla_1_1" => "MPL-1.1",
111
+ "mplv1.0" => "MPL-1.0",
112
+ "mplv1.1" => "MPL-1.1",
112
113
  "openssl" => "OpenSSL",
113
114
  "qpl_1_0" => "QPL-1.0",
114
115
  "perl" => "Artistic-1.0-Perl",
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module LicenseScout
19
- VERSION = "2.0.7"
19
+ VERSION = "2.0.9"
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serdar Sutay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-18 00:00:00.000000000 Z
12
+ date: 2018-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl
@@ -173,6 +173,8 @@ files:
173
173
  - lib/license_scout/dependency_manager/npm.rb
174
174
  - lib/license_scout/dependency_manager/rebar.rb
175
175
  - lib/license_scout/exceptions.rb
176
+ - lib/license_scout/exporter.rb
177
+ - lib/license_scout/exporter/csv.rb
176
178
  - lib/license_scout/license.rb
177
179
  - lib/license_scout/log.rb
178
180
  - lib/license_scout/reporter.rb