Created
January 13, 2019 19:46
-
-
Save dariusz-wozniak/8b0b8e30bb95f8935e76edd93dc491a2 to your computer and use it in GitHub Desktop.
π« Summarize Chocolatey upgrade log
This file contains hidden or 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
using System; | |
using System.IO; | |
public class SummarizeChocoUpgradeLog | |
{ | |
private static char s = ';'; | |
public static void FilterAndWrite(string logSummary, string logToWrite) | |
{ | |
var linesToWrite = new List<string>(); | |
string[] lines = File.ReadAllLines(logSummary); | |
bool forceToAddLine = false; | |
string date = string.Empty; | |
string app = string.Empty; | |
string summary = string.Empty; | |
foreach(var line in lines) | |
{ | |
if (line.StartsWith("Choco short log for")) | |
{ | |
date = line.Substring(22, 19).Replace(" ", "T"); | |
} | |
if (line.StartsWith("Upgraded:")) | |
{ | |
forceToAddLine = true; | |
} | |
if (line.StartsWith(" - ") && forceToAddLine) | |
{ | |
summary = date + s + line.Split(' ')[2] + s + line.Split(' ')[3]; | |
} | |
if (string.IsNullOrWhiteSpace(line)) | |
{ | |
forceToAddLine = false; | |
} | |
if (forceToAddLine) | |
{ | |
if (line.StartsWith(" - ")) linesToWrite.Add(summary); | |
} | |
} | |
File.WriteAllLines(logToWrite, linesToWrite); | |
} | |
} | |
Console.WriteLine("Executing SummarizeChocoUpgradeLog script..."); | |
Console.WriteLine("Reading from: " + Env.ScriptArgs[0]); | |
Console.WriteLine("Writing to: " + Env.ScriptArgs[1]); | |
SummarizeChocoUpgradeLog.FilterAndWrite(Env.ScriptArgs[0], Env.ScriptArgs[1]); | |
Console.WriteLine("The script SummarizeChocoUpgradeLog has been finished successfully"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment