Skip to content

Commit

Permalink
Merge pull request #26 from bung87/pretty
Browse files Browse the repository at this point in the history
code formatting via nimpretty
  • Loading branch information
juancarlospaco authored Dec 25, 2023
2 parents 7bc11d1 + 7a279ca commit 8e5db60
Show file tree
Hide file tree
Showing 16 changed files with 3,168 additions and 3,003 deletions.
4 changes: 2 additions & 2 deletions scripts/disk_usage.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import strformat
import psutil

proc main() =
var n: int = max(mapIt(psutil.disk_partitions(all=false), len(it.device)))
var n: int = max(mapIt(psutil.disk_partitions(all = false), len(it.device)))

echo(&"""{alignString("Device", n)} {"Total":>10} {"Used":>10} """ &
&"""{"Free":>10} {"Use":>5}% {"Type":>9} Mount""")
for part in psutil.disk_partitions(all=false):
for part in psutil.disk_partitions(all = false):
when defined(windows):
if "cdrom" in part.opts or part.fstype == "":
# skip cd-rom drives with no disk in it; they may raise
Expand Down
20 changes: 10 additions & 10 deletions scripts/free.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import strformat
import psutil

proc main() =
let virt = psutil.virtual_memory()
let swap = psutil.swap_memory()
echo(&"""{"total":>17} {"used":>10} {"free":>10} {"shared":>10} """ &
&"""{"buffers":>10} {"cache":>10}""")
echo(&"Mem: {int(virt.total / 1024):>12} {int(virt.used / 1024):>10} " &
&"{int(virt.free / 1024):>10} {int(virt.shared / 1024):>10} " &
&"{int(virt.buffers / 1024):>10} {int(virt.cached / 1024):>10}")
echo(&"Swap: {int(swap.total / 1024):>11} {int(swap.used / 1024):>10} " &
&"{int(swap.free / 1024):>10} ")
let virt = psutil.virtual_memory()
let swap = psutil.swap_memory()
echo(&"""{"total":>17} {"used":>10} {"free":>10} {"shared":>10} """ &
&"""{"buffers":>10} {"cache":>10}""")
echo(&"Mem: {int(virt.total / 1024):>12} {int(virt.used / 1024):>10} " &
&"{int(virt.free / 1024):>10} {int(virt.shared / 1024):>10} " &
&"{int(virt.buffers / 1024):>10} {int(virt.cached / 1024):>10}")
echo(&"Swap: {int(swap.total / 1024):>11} {int(swap.used / 1024):>10} " &
&"{int(swap.free / 1024):>10} ")

when isMainModule:
main()
main()
65 changes: 33 additions & 32 deletions scripts/ifconfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import sequtils
import tables
when defined(posix):
import posix
import posix
else:
import winlean
import winlean

import stringinterpolation

Expand All @@ -57,37 +57,38 @@ var duplex_map = {


proc main() =
let stats = psutil.net_if_stats()
let io_counters = psutil.per_nic_net_io_counters()
let stats = psutil.net_if_stats()
let io_counters = psutil.per_nic_net_io_counters()

for nic, addrs in psutil.net_if_addrs():
echo("%s:".format(nic))
if nic in stats:
let st = stats[nic]
stdout.write(" stats : ")
echo("speed=%sMB, duplex=%s, mtu=%s, up=%s".format(
st.speed, duplex_map[st.duplex], st.mtu,
if st.isup: "yes" else: "no"))
if nic in io_counters:
let io = io_counters[nic]
stdout.write(" incoming : ")
echo("bytes=%s, pkts=%s, errs=%s, drops=%s".format(
io.bytes_recv, io.packets_recv, io.errin, io.dropin))
stdout.write(" outgoing : ")
echo("bytes=%s, pkts=%s, errs=%s, drops=%s".format(
io.bytes_sent, io.packets_sent, io.errout, io.dropout))
for addr in addrs:
if addr.address != nil:
stdout.write( " %-4s".format(af_map.mgetOrPut(addr.family.cint, $addr.family)) )
echo(" address : %s".format(addr.address))
if addr.broadcast != nil:
echo(" broadcast : %s".format(addr.broadcast))
if addr.netmask != nil:
echo(" netmask : %s".format(addr.netmask))
if addr.ptp != nil:
echo(" p2p : %s".format(addr.ptp))
echo("")
for nic, addrs in psutil.net_if_addrs():
echo("%s:".format(nic))
if nic in stats:
let st = stats[nic]
stdout.write(" stats : ")
echo("speed=%sMB, duplex=%s, mtu=%s, up=%s".format(
st.speed, duplex_map[st.duplex], st.mtu,
if st.isup: "yes" else: "no"))
if nic in io_counters:
let io = io_counters[nic]
stdout.write(" incoming : ")
echo("bytes=%s, pkts=%s, errs=%s, drops=%s".format(
io.bytes_recv, io.packets_recv, io.errin, io.dropin))
stdout.write(" outgoing : ")
echo("bytes=%s, pkts=%s, errs=%s, drops=%s".format(
io.bytes_sent, io.packets_sent, io.errout, io.dropout))
for addr in addrs:
if addr.address != nil:
stdout.write(" %-4s".format(af_map.mgetOrPut(addr.family.cint,
$addr.family)))
echo(" address : %s".format(addr.address))
if addr.broadcast != nil:
echo(" broadcast : %s".format(addr.broadcast))
if addr.netmask != nil:
echo(" netmask : %s".format(addr.netmask))
if addr.ptp != nil:
echo(" p2p : %s".format(addr.ptp))
echo("")


when isMainModule:
main()
main()
2 changes: 1 addition & 1 deletion scripts/meminfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import strutils
import strformat
import psutil

proc pprint_object[T]( obj: T ): void =
proc pprint_object[T](obj: T): void =
var n: string
var v: float
for name, value in obj.fieldPairs:
Expand Down
Loading

0 comments on commit 8e5db60

Please sign in to comment.