From 14bb266bd9450e89e47d0e08e20379e603a6f4fd Mon Sep 17 00:00:00 2001 From: Kreato Date: Sat, 7 Oct 2023 00:29:41 +0300 Subject: [PATCH] kpkg: feat: add vertical summaries --- kpkg/modules/commonTasks.nim | 58 ++++++++++++++++++++++++++++-------- kpkg/modules/config.nim | 1 + man/kpkg.conf.5.md | 2 ++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/kpkg/modules/commonTasks.nim b/kpkg/modules/commonTasks.nim index 688fe915..72cc59ca 100644 --- a/kpkg/modules/commonTasks.nim +++ b/kpkg/modules/commonTasks.nim @@ -21,24 +21,58 @@ proc appendInternal(f: string, t: string): string = else: return t&" "&f +proc appenderInternal(r: string, a: string, b: string, c = "", removeInt = 0): string = + # Appends spaces so it looks nicer. + var final = r + + for i in 1 .. 40 - (a.len + b.len + c.len - removeInt): + final = final&" " + + return final + + proc printPackagesPrompt*(packages: string, yes: bool, no: bool) = ## Prints the packages summary prompt. var finalPkgs: string var pkgLen: int + + if parseBool(getConfigValue("Options", "verticalSummary")): + pkgLen = packages.split(" ").len + echo "Packages ("&($pkgLen)&") New Version\n" + for i in packages.split(" "): + let pkgRepo = findPkgRepo(i) + let upstreamRunf = parseRunfile(pkgRepo&"/"&i) + var r = lastPathPart(pkgRepo)&"/"&i + if fileExists("/var/cache/kpkg/installed/"&i&"/run"): + let localRunf = parseRunfile("/var/cache/kpkg/installed/"&i) + if localRunf.versionString != upstreamRunf.versionString: + r = r&"-"&localRunf.versionString + r = appenderInternal(r, i, lastPathPart(pkgRepo), localRunf.versionString) + r = r&upstreamRunf.versionString + else: + r = r&"-"&localRunf.versionString + r = appenderInternal(r, i, lastPathPart(pkgRepo), localRunf.versionString) + r = r&"up-to-date" + else: + r = appenderInternal(r, i, "", lastPathPart(pkgRepo), 1) + r = r&upstreamRunf.versionString + + echo r + + else: + for i in packages.split(" "): + inc(pkgLen) + var upstreamRunf: runFile + let pkgRepo = findPkgRepo(i) + if fileExists("/var/cache/kpkg/installed/"&i&"/run") and pkgRepo != "": + upstreamRunf = parseRunfile(pkgRepo&"/"&i) + if parseRunfile("/var/cache/kpkg/installed/"&i).versionString != upstreamRunf.versionString: + finalPkgs = appendInternal(i&" -> ".green&upstreamRunf.versionString, finalPkgs) + continue - for i in packages.split(" "): - inc(pkgLen) - var upstreamRunf: runFile - let pkgRepo = findPkgRepo(i) - if fileExists("/var/cache/kpkg/installed/"&i&"/run") and pkgRepo != "": - upstreamRunf = parseRunfile(pkgRepo&"/"&i) - if parseRunfile("/var/cache/kpkg/installed/"&i).versionString != upstreamRunf.versionString: - finalPkgs = appendInternal(i&" -> ".green&upstreamRunf.versionString, finalPkgs) - continue - - finalPkgs = appendInternal(i, finalPkgs) + finalPkgs = appendInternal(i, finalPkgs) - echo "Packages ("&($pkgLen)&"): "&finalPkgs + echo "Packages ("&($pkgLen)&"): "&finalPkgs var output: string diff --git a/kpkg/modules/config.nim b/kpkg/modules/config.nim index 73020641..9f4ef0e0 100644 --- a/kpkg/modules/config.nim +++ b/kpkg/modules/config.nim @@ -24,6 +24,7 @@ proc initializeConfig*(): Config = config.setSectionKey("Options", "cc", "gcc") # GCC works the best right now config.setSectionKey("Options", "cxx", "g++") # GCC works the best right now config.setSectionKey("Options", "ccache", "false") + config.setSectionKey("Options", "verticalSummary", "false") # [Repositories] config.setSectionKey("Repositories", "repoDirs", diff --git a/man/kpkg.conf.5.md b/man/kpkg.conf.5.md index 2aa6cd3d..5fdff161 100644 --- a/man/kpkg.conf.5.md +++ b/man/kpkg.conf.5.md @@ -15,6 +15,7 @@ The default configuration file currently looks like this; cc=gcc cxx=g++ ccache=false +verticalSummary=false [Repositories] repoDirs=/etc/kpkg/repos/main /etc/kpkg/repos/lockin @@ -34,6 +35,7 @@ buildByDefault=yes * ccache: Boolean to enable ccache. Defaults to `false`. Will only have an effect if ccache is installed. * cxxflags: Sets the CXXFLAGS environment variable on build. Defaults to nothing. * cflags: Sets the CFLAGS environment variable on build. Defaults to nothing. +* verticalSummary: Boolean to enable vertical summaries. Defaults to `false`. ## REPOSITORIES * repoDirs: Repository directories. Must line up with repoLinks. Seperate by space.