Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
// optionalAttrs isLinux {
folder-size-metrics = pkgs.callPackage ./folder-size-metrics { };
}
// optionalAttrs (system == "x86_64-linux") rec {
// optionalAttrs (system == "x86_64-linux") {
mcl = pkgs.callPackage ./mcl {
buildDubPackage = inputs'.dlang-nix.legacyPackages.buildDubPackage.override {
dCompiler = inputs'.dlang-nix.packages."ldc-binary-1_38_0";
Expand Down
26 changes: 14 additions & 12 deletions packages/mcl/src/src/mcl/commands/host_info.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import mcl.utils.process : execute, isRoot;
import mcl.utils.number : humanReadableSize;
import mcl.utils.array : uniqIfSame;
import mcl.utils.nix : Literal;
import mcl.utils.coda;
import mcl.utils.coda : CodaApiClient, RowValues, CodaCell;

// enum InfoFormat
// {
Expand All @@ -40,7 +40,6 @@ struct Params
{
}
}
Params params;

string[string] cpuinfo;

Expand All @@ -67,15 +66,15 @@ string[string] getProcInfo(string fileOrData, bool file = true)

export void host_info()
{
params = parseEnv!Params;
const Params params = parseEnv!Params;

Info info = getInfo();
Info info = params.getInfo();

writeln(info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes));

}

Info getInfo()
Info getInfo(Params params)
{

cpuinfo = getProcInfo("/proc/cpuinfo");
Expand All @@ -96,6 +95,7 @@ Info getInfo()
info.hardwareInfo.graphicsProcessorInfo = getGraphicsProcessorInfo();

if (params.codaApiToken) {
writeln("Coda API token specified -> uploading");
auto docId = "0rz18jyJ1M";
auto hostTableId = "grid-b3MAjem325";
auto cpuTableId = "grid-mCI3x3nEIE";
Expand All @@ -113,7 +113,7 @@ Info getInfo()
CodaCell("JSON", info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
]);

coda.updateOrInsertRow(docId, hostTableId, hostValues);
coda.upsertRow(docId, hostTableId, hostValues);

auto cpuValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
Expand All @@ -122,7 +122,7 @@ Info getInfo()
CodaCell("Architecture", info.hardwareInfo.processorInfo.architectureInfo.architecture),
CodaCell("Flags", info.hardwareInfo.processorInfo.architectureInfo.flags),
]);
coda.updateOrInsertRow(docId, cpuTableId, cpuValues);
coda.upsertRow(docId, cpuTableId, cpuValues);

auto memoryValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
Expand All @@ -134,7 +134,7 @@ Info getInfo()
CodaCell("Total", info.hardwareInfo.memoryInfo.total),
CodaCell("Speed", info.hardwareInfo.memoryInfo.speed),
]);
coda.updateOrInsertRow(docId, memoryTableId, memoryValues);
coda.upsertRow(docId, memoryTableId, memoryValues);

auto motherboardValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
Expand All @@ -147,15 +147,15 @@ Info getInfo()
CodaCell("BIOS Release", info.hardwareInfo.motherboardInfo.biosInfo.release),
CodaCell("BIOS Date", info.hardwareInfo.motherboardInfo.biosInfo.date)
]);
coda.updateOrInsertRow(docId, motherboardTableId, motherboardValues);
coda.upsertRow(docId, motherboardTableId, motherboardValues);

auto gpuValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Vendor", info.hardwareInfo.graphicsProcessorInfo.vendor),
CodaCell("Model", info.hardwareInfo.graphicsProcessorInfo.model),
CodaCell("VRam", info.hardwareInfo.graphicsProcessorInfo.vram)
]);
coda.updateOrInsertRow(docId, gpuTableId, gpuValues);
coda.upsertRow(docId, gpuTableId, gpuValues);

auto osValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
Expand All @@ -164,16 +164,18 @@ Info getInfo()
CodaCell("Kernel", info.softwareInfo.operatingSystemInfo.kernel),
CodaCell("Kernel Version", info.softwareInfo.operatingSystemInfo.kernelVersion)
]);
coda.updateOrInsertRow(docId, osTableId, osValues);
coda.upsertRow(docId, osTableId, osValues);

auto storageValues = RowValues([
CodaCell("Host Name", info.softwareInfo.hostname),
CodaCell("Count", info.hardwareInfo.storageInfo.devices.length.to!string),
CodaCell("Total", info.hardwareInfo.storageInfo.total),
CodaCell("JSON", info.hardwareInfo.storageInfo.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes))
]);
coda.updateOrInsertRow(docId, storageTableId, storageValues);
coda.upsertRow(docId, storageTableId, storageValues);
}
else
writeln("No Coda API token specified -> not uploading");

return info;
}
Expand Down
19 changes: 7 additions & 12 deletions packages/mcl/src/src/mcl/utils/coda.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import std.stdio : writeln, writefln;
import std.algorithm : map, filter, find;
import std.exception : assertThrown;
import std.sumtype : SumType;
import std.array : join;
import core.thread;

struct CodaApiClient
Expand Down Expand Up @@ -438,8 +439,6 @@ struct CodaApiClient
req["keyColumns"] = JSONValue(keyColumns.toJSON);
return post!InsertRowsReturn(url, req, false).addedRowIds;
}
alias upsertRows = insertRows;


// Can't be implemented because of the lack of support for a body in DELETE requests
// void deleteRows(string documentId, string tableId, string[] rowIds)
Expand Down Expand Up @@ -496,7 +495,7 @@ struct CodaApiClient
string id;
}

string updateRow(string documentId, string tableId, string rowId, RowValues row)
string updateRow(string documentId, string tableId, string rowId, RowValues row, string[] keyColumns = [])
{
string url = "/docs/%s/tables/%s/rows/%s".format(documentId, tableId, rowId);
JSONValue req = JSONValue(
Expand Down Expand Up @@ -527,15 +526,11 @@ struct CodaApiClient
coda.deleteRow("dEJJPwdxcw", tables[0].id, resp[0]);
}

void updateOrInsertRow(string docId, string tableId, RowValues values) {
auto table = listRows(docId, tableId);
auto rows = find!(row => row.name == values.cells[0].value)(table);
if (rows.length > 0) {
updateRow(docId, tableId, rows[0].id, values);
}
else {
insertRows(docId, tableId, [values]);
}
void upsertRow(string docId, string tableId, RowValues values, string[] keyColumns = ["name"]) {
insertRows(docId, tableId, [values], keyColumns);
}
void upsertRows(string docId, string tableId, RowValues[] values, string[] keyColumns = ["name"]) {
insertRows(docId, tableId, values, keyColumns);
}
struct PushButtonResponse {
string requestId;
Expand Down
1 change: 0 additions & 1 deletion packages/mcl/src/src/mcl/utils/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ T execute(T = string)(string[] args, bool printCommand = true, bool returnErr =
import std.array : join;
import std.algorithm : map;
import std.conv : to;
import std.stdio : writeln;

auto cmd = args.map!escapeShellCommand.join(" ");

Expand Down