Skip to content

Commit

Permalink
kpkg: feat: add vertical summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Oct 6, 2023
1 parent 2039a0e commit 14bb266
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
58 changes: 46 additions & 12 deletions kpkg/modules/commonTasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions kpkg/modules/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions man/kpkg.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 14bb266

Please sign in to comment.