Skip to content

Commit

Permalink
Merge pull request #1305 from KSP-CKAN/topic/update_ks_transformer
Browse files Browse the repository at this point in the history
Update KerbalStuff Transformer
  • Loading branch information
RichardLake committed Jul 17, 2015
2 parents f773bf6 + 709acec commit dfe7cbd
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Netkan/Transformers/KerbalstuffTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit dfe7cbd

Please sign in to comment.