Skip to content

Instantly share code, notes, and snippets.

@mainej
Last active October 7, 2020 16:35
Show Gist options
  • Save mainej/48ac616844505d50f510 to your computer and use it in GitHub Desktop.
Save mainej/48ac616844505d50f510 to your computer and use it in GitHub Desktop.
How to extract detailed data from license_finder. Beware of caveats.
#!/usr/bin/env ruby
require 'license_finder'
# See lib/license_finder/core.rb for more configuration options.
# A quiet logger is required when running reports...
lf = LicenseFinder::Core.new(logger: { quiet: true })
# Groups of packages
lf.acknowledged # All (non-ignored) packages license_finder is tracking
lf.unapproved # The packages which have not been approved or whitelisted
lf.blacklisted # The packages which have been blacklisted
# Package details
lf.acknowledged.each do |package|
# Approvals
package.approved? # Whether the package has been approved manually or whitelisted
package.approved_manually?
package.whitelisted?
package.blacklisted?
# Licensing
package.licenses # The set of licenses, each of which has a name and url, which
# license_finder will report for this package.
package.activations # Additional information about how these licenses were chosen
# (from decision, from spec, from files, or none-found). See
# LicenseFinder::Licensing and LicenseFinder::Activation
package.license_files # The files that look like licenses, found in the package's
# directory. Caveat: if a package's licenses were specified by a decision or
# by the package's spec, the license_files will be ignored. That means,
# package.licenses may report different licenses than those found in
# license_files.
package.license_files.each do |file|
file.license # The license found in this file.
file.text # The text of the file. Sometimes this will be an entire README file,
# because license_finder has found the phrase "is released under the
# MIT license" in it.
end
package.licensing.activations_from_decisions # If license_finder only knew about decisions, what licenses would it report?
package.licensing.activations_from_spec # If license_finder only knew about package specs, what licenses would it report?
package.licensing.activations_from_files # If license_finder only knew about package files, what licenses would it report?
package.licensing.activations_from_files.each do |activation|
# Each activation groups together all files that point to the same license.
# Each file contains its #license and #text.
activation.license
activation.files
end
end
@timhughes
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment