Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update KerbalStuff Transformer #1305

Merged
merged 1 commit into from
Jul 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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