-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiocondaDirectorySearch.cs
More file actions
72 lines (55 loc) · 2.13 KB
/
BiocondaDirectorySearch.cs
File metadata and controls
72 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using YamlDotNet.Serialization;
using System.Collections;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace UnsupportedPackageWriter
{
class BiocondaDirectorySearch
{
public BiocondaDirectorySearch()
{
}
public List<JObject> LookThroughYaml(string path)
{
int exceptionCounter = 0;
List<JObject> convertedYamlList = new List<JObject>();
try
{
//these two for loops searches through every meta.yaml file
foreach(string recipe in Directory.GetDirectories(path)){
foreach(string yamlFile in Directory.GetFiles(recipe, "meta.yaml"))
{
//This section we convert yaml into json and skip the yaml file with bad syntax
try {
string yamlText = File.ReadAllText(yamlFile);
var deserializer = new Deserializer();
var yamlObject = deserializer.Deserialize(new StringReader(yamlText));
StringBuilder sb = new StringBuilder();
var serializer = new JsonSerializer();
using(StringWriter sw = new StringWriter(sb))
using (JsonWriter jw = new JsonTextWriter(sw))
{
serializer.Serialize(jw, yamlObject);
}
JObject convertedYaml = JObject.Parse(sb.ToString());
convertedYamlList.Add(convertedYaml);
}
catch(Exception e)
{
exceptionCounter++;
}
}
}
}
catch (IOException e)
{
Console.Out.WriteLine(e);
}
return convertedYamlList;
}
}
}