mirror of
https://github.com/daylinmorgan/oizys.git
synced 2025-02-02 15:04:18 -06:00
make utils narinfo more helpful
This commit is contained in:
parent
eb8ec7dabf
commit
46b1a2cdc5
2 changed files with 30 additions and 10 deletions
|
@ -185,6 +185,8 @@ hwylCli:
|
||||||
? "url of nix binary cache, can be repeated"
|
? "url of nix binary cache, can be repeated"
|
||||||
T seq[string]
|
T seq[string]
|
||||||
run:
|
run:
|
||||||
|
if installables.len == 0:
|
||||||
|
fatalQuit "expected at least one positional argument"
|
||||||
checkForCache(installables, cache)
|
checkForCache(installables, cache)
|
||||||
|
|
||||||
[lock]
|
[lock]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import std/[strformat, strutils, osproc, sugar, httpclient]
|
import std/[strformat, strutils, osproc, sugar, httpclient, terminal, wordwrap]
|
||||||
import hwylterm
|
import hwylterm
|
||||||
import ./[nix, exec,logging]
|
import ./[nix, exec, logging, context]
|
||||||
|
|
||||||
|
|
||||||
# TODO: refactor runCmdCaptWithSpinner so it works in getBuildHash
|
# TODO: refactor runCmdCaptWithSpinner so it works in getBuildHash
|
||||||
|
@ -44,18 +44,21 @@ proc getCaches(): seq[string] =
|
||||||
fatalQuit "error running `nix config show`"
|
fatalQuit "error running `nix config show`"
|
||||||
|
|
||||||
|
|
||||||
|
proc hasNarinfo*(cache: string, path: string): tuple[exists:bool, narinfo:string] =
|
||||||
|
|
||||||
proc hasNarinfo*(cache: string, path: string): bool =
|
|
||||||
debug fmt"checking {cache} for {path}"
|
debug fmt"checking {cache} for {path}"
|
||||||
let
|
let
|
||||||
hash = narHash(path)
|
hash = narHash(path)
|
||||||
url = cache & "/" & hash & ".narinfo"
|
url = cache & "/" & hash & ".narinfo"
|
||||||
|
|
||||||
|
var client = newHttpClient()
|
||||||
try:
|
try:
|
||||||
let client = newHttpClient()
|
let res = client.get(url)
|
||||||
result = client.head(url).code == Http200
|
result.exists = res.code == Http200
|
||||||
except:
|
result.narinfo = res.body.strip()
|
||||||
result = false
|
# if result and getVerbosity() > 0:
|
||||||
|
# info "narinfo:\n" & indent(res.body.strip(),2)
|
||||||
|
finally:
|
||||||
|
client.close()
|
||||||
|
|
||||||
proc prettyDerivation(path: string): BbString =
|
proc prettyDerivation(path: string): BbString =
|
||||||
let drv = path.toDerivation()
|
let drv = path.toDerivation()
|
||||||
|
@ -64,6 +67,19 @@ proc prettyDerivation(path: string): BbString =
|
||||||
result.add " "
|
result.add " "
|
||||||
result.add drv.hash.bb("faint")
|
result.add drv.hash.bb("faint")
|
||||||
|
|
||||||
|
proc showNarInfo(s: string): BbString =
|
||||||
|
let maxWidth = terminalWidth()
|
||||||
|
result.add "narinfo:"
|
||||||
|
for line in s.splitLines():
|
||||||
|
let
|
||||||
|
ss = line.split(": ", maxsplit = 1)
|
||||||
|
(k, v) = (ss[0], ss[1])
|
||||||
|
result.add bbfmt("\n[b]{k}[/]: ")
|
||||||
|
if (len(v) - len(k) + 2) > maxWidth:
|
||||||
|
result.add "\n " & wrapWords(v, maxLineWidth = maxWidth - 2, newLine="\n ")
|
||||||
|
else:
|
||||||
|
result.add v
|
||||||
|
|
||||||
proc checkForCache*(installables: seq[string], caches: seq[string]) =
|
proc checkForCache*(installables: seq[string], caches: seq[string]) =
|
||||||
let caches =
|
let caches =
|
||||||
if caches.len > 0: caches
|
if caches.len > 0: caches
|
||||||
|
@ -77,10 +93,12 @@ proc checkForCache*(installables: seq[string], caches: seq[string]) =
|
||||||
for name, path in outs:
|
for name, path in outs:
|
||||||
var found = false
|
var found = false
|
||||||
for cache in caches:
|
for cache in caches:
|
||||||
if hasNarinfo(cache, path):
|
let (exists, narinfo) = hasNarinfo(cache, path)
|
||||||
|
if exists:
|
||||||
found = true
|
found = true
|
||||||
info prettyDerivation(path)
|
info prettyDerivation(path)
|
||||||
info fmt"exists in {cache}"
|
info fmt"exists in {cache}"
|
||||||
|
debug showNarinfo(narinfo)
|
||||||
break
|
break
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
|
|
Loading…
Reference in a new issue