-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRioProcessing.cs
More file actions
84 lines (71 loc) · 2.59 KB
/
Copy pathRioProcessing.cs
File metadata and controls
84 lines (71 loc) · 2.59 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
73
74
75
76
77
78
79
80
81
82
83
84
using Raphdf201.FileUtils;
using static TechLogManager.Utils;
namespace TechLogManager;
public static class RioProcessing
{
public static async Task<List<LogEntry>> GetLogs(ClientManager conn)
{
string? f1;
string? f2;
try
{
var results = await conn.RunCommandsAsync(
"find /home/lvuser/logs -name '*.wpilog' 2>/dev/null || true",
"find /U/logs -name '*.wpilog' 2>/dev/null || true"
);
f1 = results[0];
f2 = results[1];
}
catch (Exception ex)
{
Log($"Error finding log files: {ex.Message}");
return [];
}
if (f1.IsWhiteSpace()) f1 = null;
if (f2.IsWhiteSpace()) f2 = null;
if (f1 == null && f2 == null)
{
Log("No RoboRIO log files found");
return [];
}
var files = f1 == null
? f2!.Split("\n").ToList() // f1 is null
: f2 == null
? f1.Split("\n").ToList() // f2 is null
: f1.Split("\n").Concat(f2.Split("\n")).ToList(); // none is null
files = files.Where(f => !string.IsNullOrWhiteSpace(f) && !f.StartsWith("FRC_TBD")).ToList();
if (files.Count == 0)
{
Log("No valid RoboRIO log files found");
return [];
}
files.Sort((a, b) =>
string.Compare(File.GetName(a), File.GetName(b), StringComparison.OrdinalIgnoreCase));
Log($"Found {files.Count} RoboRIO log file(s)");
return files.Select(file => new LogEntry(file.GetFileName()!, LogSource.RoboRio, async (dest, action) =>
{
if (action.IsDownload())
{
var result = await conn.DownloadScpAsync(file, dest
.Combine("wpilog").CreateDirectory().Combine(file.GetFileName()!));
Log(result);
}
if (action.IsDelete())
{
var result = await conn.RunCommandAsync($"rm -f {file}");
Log(result);
}
}))
.OrderByDescending(e => e.Name).ToList();
}
public static async Task DownloadAll(string dest, ClientManager conn)
{
dest = dest.Combine("wpilog").CreateDirectory();
await conn.DownloadScpAsync("/U/logs/*", dest);
await conn.DownloadScpAsync("/home/lvuser/logs/*", dest);
}
public static async Task DeleteAll(ClientManager conn)
{
await conn.RunCommandsAsync("rm -rf /U/logs/*", "rm -rf /home/lvuser/logs/*");
}
}