Commit 25a87138 authored by Enrique García Cota's avatar Enrique García Cota

started creating the licenses auto-updater

parent 77747418
def create_license(name, identifier, url, version_identifier, date, version_url)
license = License.new(:name => name, :identifier => identifier, :url => url)
version = license.versions.build(:identifier => version_identifier, :date => date, :url => version_url)
license.save
end
namespace :licenses do
desc "creates default licenses, imports them, and removes the license custom field from ohwr"
task :all => [:destroy_all, :create]
desc "destroys all licenses"
task :destroy_all => :environment do
License.destroy_all
LicenseVersion.destroy_all
Project.all.each do |p|
p.license = nil
p.save
end
end
desc "creates default licenses"
task :create => :environment do
create_license("GPL", "gpl", "http://www.gnu.org/copyleft/gpl.html", "v3.0", Date.new(2009, 6,29), "http://www.gnu.org/copyleft/gpl.html")
create_license("LGPL", "lgpl", "http://www.gnu.org/licenses/lgpl.html", "v3.0", Date.new(2009, 6, 29), "http://www.gnu.org/licenses/lgpl.html")
create_license("TAPR OHL", "tapr-ohl", "http://www.tapr.org/OHL", "v1.0", Date.new(2007, 5, 25), "http://www.tapr.org/TAPR_Open_Hardware_License_v1.0.txt")
create_license("CERN OHL", "cern-ohl", nil, "v1.1", Date.new(2011,7,8), nil)
end
desc "associates projects to the licenses they belong to" do
["GPL", "LGPL", "TAPR OHL", "CERN OHL"].each do |license_name|
license = License.find_by_name(license_name)
license_version = license.license_versions.first
Project.with_custom_fields(:License => license_name).each do |p|
p.license = license.version
p.save
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment