forked from KSP-CKAN/CKAN
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filters. Deprecate bundles and install options.
Updates the spec, the schema, and the code. Includes tests. Closes KSP-CKAN#113 (deprecate things). Closes KSP-CKAN#129 (add filter keywords). This will require an update to CKAN-meta, which I've already got ready.
- Loading branch information
Showing
10 changed files
with
145 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Text.RegularExpressions; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
|
||
namespace CKAN | ||
{ | ||
public class ModuleInstallDescriptor | ||
{ | ||
public /* required */ string file; | ||
public /* required */ string install_to; | ||
|
||
[JsonConverter(typeof (JsonSingleOrArrayConverter<string>))] | ||
public List<string> filter; | ||
|
||
[JsonConverter(typeof (JsonSingleOrArrayConverter<string>))] | ||
public List<string> filter_regexp; | ||
|
||
[OnDeserialized] | ||
internal void DeSerialisationFixes(StreamingContext like_i_could_care) | ||
{ | ||
// Make sure our required fields exist. | ||
if (file == null || install_to == null) | ||
{ | ||
throw new BadMetadataKraken(null, "Install stanzas must have a file and install_to"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the path provided should be installed by this stanza. | ||
/// </summary> | ||
public bool IsWanted(string path) | ||
{ | ||
// Make sure our path always uses slashes we expect. | ||
string normalised_path = path.Replace('\\', '/'); | ||
|
||
// Make sure our internal state is consistent. Is there a better way of doing this? | ||
filter = filter ?? new List<string> (); | ||
filter_regexp = filter_regexp ?? new List<string> (); | ||
|
||
// We want everthing that matches our 'file', either as an exact match, | ||
// or as a path leading up to it. | ||
string wanted_filter = "^" + Regex.Escape(this.file) + "(/|$)"; | ||
|
||
// If it doesn't match our install path, ignore it. | ||
if (! Regex.IsMatch(normalised_path, wanted_filter)) | ||
{ | ||
return false; | ||
} | ||
|
||
// Skip the file if it's a ckan file, these should never be copied to GameData. | ||
if (Regex.IsMatch(normalised_path, ".ckan$", RegexOptions.IgnoreCase)) | ||
{ | ||
return false; | ||
} | ||
|
||
// Get all our path segments. If our filter matches of any them, skip. | ||
// All these comparisons are case insensitive. | ||
var path_segments = new List<string>(normalised_path.ToLower().Split('/')); | ||
|
||
foreach (string filter_text in this.filter) | ||
{ | ||
if (path_segments.Contains(filter_text.ToLower())) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// Finally, check our filter regexpes. | ||
foreach (string regexp in this.filter_regexp) | ||
{ | ||
if (Regex.IsMatch(normalised_path, regexp)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// I guess we want this file after all. ;) | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"spec_version" : 1, | ||
"$kref" : "#/ckan/github/NathanKell/RealSolarSystem", | ||
"name" : "Custom Biomes (Real Solar System data)", | ||
"identifier" : "CustomBiomesRSS", | ||
"abstract" : "Custom biomes for the Real Solar System", | ||
"license" : "CC-BY-NC-SA", | ||
"release_status" : "stable", | ||
"ksp_version" : "any", | ||
"depends" : [ | ||
{ "name" : "RealSolarSystem" }, | ||
{ "name" : "CustomBiomes" } | ||
], | ||
"provides" : [ "CustomBiomesData" ], | ||
"conflicts" : [ { "name" : "CustomBiomesData" } ], | ||
"resources" : { | ||
"homepage" : "http://forum.kerbalspaceprogram.com/threads/55145", | ||
}, | ||
"install" : [ | ||
{ | ||
"file" : "CustomBiomes", | ||
"install_to" : "GameData", | ||
"comment" : "This regexp only installs PluginData, and nothing else", | ||
"filter_regexp" : "^(?!CustomBiomes/PluginData/)" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"spec_version" : 1, | ||
"name" : "Deadly Reentry Continued", | ||
"abstract" : "Makes re-entry much more dangerous", | ||
"identifier" : "DeadlyReentry", | ||
"$kref" : "#/ckan/github/NathanKell/DeadlyReentry", | ||
"license" : "CC-BY-SA", | ||
"release_status" : "stable", | ||
"ksp_version" : "0.25", | ||
"resources" : { | ||
"homepage" : "http://forum.kerbalspaceprogram.com/threads/54954", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.