2017-03-05 17:40:46 -05:00
|
|
|
#!/usr/bin/env ruby
|
2017-11-19 13:49:31 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-05 17:40:46 -05:00
|
|
|
require 'jekyll'
|
2017-11-19 13:49:31 -08:00
|
|
|
require 'tmpdir'
|
|
|
|
|
|
|
|
tmp_dir = Dir.mktmpdir
|
|
|
|
git_cmd = "git clone --depth=1 'https://github.com/spdx/license-list-data.git' #{tmp_dir}"
|
|
|
|
system(git_cmd)
|
2017-11-19 17:25:29 -08:00
|
|
|
text_dir = File.join(tmp_dir, 'text')
|
2017-03-05 17:40:46 -05:00
|
|
|
|
2017-11-19 13:49:31 -08:00
|
|
|
site_path = File.expand_path('../', File.dirname(__FILE__))
|
|
|
|
config = Jekyll.configuration('source' => site_path)
|
2017-03-05 17:40:46 -05:00
|
|
|
site = Jekyll::Site.new(config)
|
|
|
|
site.read
|
|
|
|
site.collections['licenses'].docs.each do |license|
|
2017-11-20 10:21:45 -08:00
|
|
|
license_key = license.data['spdx-id'].downcase
|
2018-08-11 14:04:32 -07:00
|
|
|
puts "Updating the #{license_key}..."
|
|
|
|
only = (license_key.include? 'gpl') ? '-only' : ''
|
|
|
|
text_file = File.join(text_dir, "#{license.data['spdx-id']}#{only}.txt")
|
|
|
|
spdx_text = File.read(text_file)
|
2017-11-20 10:21:45 -08:00
|
|
|
|
2017-11-20 12:19:13 -08:00
|
|
|
if license_key == 'afl-3.0'
|
|
|
|
# https://github.com/spdx/license-list/pull/20
|
|
|
|
spdx_text = spdx_text.gsub(/^ 4\)/, '4)')
|
|
|
|
elsif ['bsd-2-clause', 'bsd-3-clause'].include? license_key
|
2017-11-20 10:21:45 -08:00
|
|
|
spdx_text = spdx_text.gsub(/<year>/, '[year]')
|
|
|
|
spdx_text = spdx_text.gsub(/<owner>/, '[fullname]')
|
|
|
|
elsif license_key == 'bsd-3-clause-clear'
|
|
|
|
spdx_text = spdx_text.gsub(/\[xxxx\]-\[xxxx\]/, '[year]')
|
2017-11-20 12:19:13 -08:00
|
|
|
spdx_text = spdx_text.sub(/\[Owner Organization\]/, '[fullname]')
|
|
|
|
spdx_text = spdx_text.sub(/\[Owner Organization\]/, 'the copyright holder')
|
2017-11-20 10:21:45 -08:00
|
|
|
elsif license_key == 'isc'
|
|
|
|
spdx_text = spdx_text.gsub(/Copyright.*Consortium/m, 'Copyright (c) [year], [fullname]')
|
|
|
|
elsif license_key == 'mit'
|
|
|
|
spdx_text = spdx_text.gsub(/<year>/, '[year]')
|
|
|
|
spdx_text = spdx_text.gsub(/<copyright holders>/, '[fullname]')
|
|
|
|
elsif license_key == 'ncsa'
|
|
|
|
spdx_text = spdx_text.gsub(/<Year>/, '[year]')
|
|
|
|
spdx_text = spdx_text.gsub(/<Owner Organization Name>/, '[fullname]')
|
|
|
|
spdx_text = spdx_text.gsub(/<Name of Development Group>/, '[fullname]')
|
|
|
|
spdx_text = spdx_text.gsub(/<Name of Institution>/, '[project]')
|
|
|
|
spdx_text = spdx_text.gsub(%r{<URL for Development Group/Institution>}, '[project_url]')
|
|
|
|
spdx_text = spdx_text.gsub(/<Name of Development Group, Name of Institution>/, '[fullname], [project]')
|
|
|
|
end
|
|
|
|
|
2017-11-19 17:25:29 -08:00
|
|
|
license_text = ''
|
2017-03-05 17:40:46 -05:00
|
|
|
|
2017-11-19 17:25:29 -08:00
|
|
|
spdx_text.lines.each do |line|
|
2017-11-20 10:57:52 -08:00
|
|
|
if line.length > 78
|
2017-11-19 17:25:29 -08:00
|
|
|
indented_line = line.match(/\A(\s*)(.*)/)
|
|
|
|
line_indent = indented_line[1]
|
2017-11-20 11:57:08 -08:00
|
|
|
line_text = indented_line[2] .gsub(/\s+/, ' ')
|
2017-11-19 17:25:29 -08:00
|
|
|
text_width = 78 - line_indent.length
|
2017-11-20 10:57:52 -08:00
|
|
|
line = line_text.gsub(/(.{1,#{text_width}})(\s+|\Z)/, "#{line_indent}\\1\n")
|
2017-11-19 17:25:29 -08:00
|
|
|
end
|
2017-11-20 10:57:52 -08:00
|
|
|
license_text += line
|
2017-11-19 17:25:29 -08:00
|
|
|
end
|
2017-03-05 17:40:46 -05:00
|
|
|
raw_content = File.read(license.path)
|
|
|
|
matches = raw_content.match Jekyll::Document::YAML_FRONT_MATTER_REGEXP
|
|
|
|
|
|
|
|
output = matches[1]
|
|
|
|
output << "---\n\n"
|
2017-11-20 10:57:52 -08:00
|
|
|
output << license_text.gsub(/\s+$/m, "\n")
|
2017-03-05 17:40:46 -05:00
|
|
|
|
|
|
|
File.write(license.path, output)
|
|
|
|
end
|