From 709acece2b1f516eeeffab10f01942b49cb8c830 Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Thu, 16 Jul 2015 14:17:30 -0400 Subject: [PATCH] Update KerbalStuff transformer --- Netkan/Transformers/KerbalstuffTransformer.cs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Netkan/Transformers/KerbalstuffTransformer.cs b/Netkan/Transformers/KerbalstuffTransformer.cs index 8092dd92da..5a58b58a32 100644 --- a/Netkan/Transformers/KerbalstuffTransformer.cs +++ b/Netkan/Transformers/KerbalstuffTransformer.cs @@ -48,9 +48,31 @@ public Metadata Transform(Metadata metadata) json.SafeAdd("abstract", ksMod.short_description); json.SafeAdd("version", latestVersion.friendly_version.ToString()); json.SafeAdd("author", ksMod.author); - json.SafeAdd("license", ksMod.license); json.SafeAdd("download", latestVersion.download_path.OriginalString); - json.SafeAdd("x_screenshot", Escape(ksMod.background)); + + // KS provides users with the following default selection of licenses. Let's convert them to CKAN + // compatible license strings if possible. + // + // "MIT" - OK + // "BSD" - Specific version is indeterminate + // "GPLv2" - Becomes "GPL-2.0" + // "GPLv3" - Becomes "GPL-3.0" + // "LGPL" - Specific version is indeterminate + + var ksLicense = ksMod.license.Trim(); + + switch (ksLicense) + { + case "GPLv2": + json.SafeAdd("license", "GPL-2.0"); + break; + case "GPLv3": + json.SafeAdd("license", "GPL-3.0"); + break; + default: + json.SafeAdd("license", ksLicense); + break; + } // Make sure resources exist. if (json["resources"] == null) @@ -64,6 +86,11 @@ public Metadata Transform(Metadata metadata) resourcesJson.SafeAdd("repository", Escape(ksMod.source_code)); resourcesJson.SafeAdd("kerbalstuff", ksMod.GetPageUrl().OriginalString); + if (ksMod.background != null) + { + resourcesJson.SafeAdd("x_screenshot", Escape(ksMod.background)); + } + Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); return new Metadata(json);