comparison tests/test_resources.nim @ 438:1ab09f8cc68d

did: refactor and improve packaging API
author Sam <sam@basx.dev>
date Wed, 14 Feb 2024 21:58:43 +0700
parents 5f6d3511ef79
children 114f395b9144
comparison
equal deleted inserted replaced
437:e75c6da1d261 438:1ab09f8cc68d
1 import std/os
1 import std/streams 2 import std/streams
3 import std/strformat
4 import std/strutils
2 5
3 import semicongine 6 import semicongine
4 7
8 proc list_all_mods_all_files() =
9 for package in packages():
10 echo &"Files in package {package}:"
11 for i in walkResources(package = package):
12 echo " ", i, ": ", i.loadResource(package = package).readAll().len
13
14 proc print_ls(dir, package: string, indent = 2) =
15 for i in dir.ls(package = package):
16 if i.kind == pcDir:
17 echo "".align(indent), i.path, "/"
18 print_ls(dir.joinPath(i.path), package = package, indent = indent + 2)
19 else:
20 echo "".align(indent), i.path, ": ", dir.joinPath(i.path).loadResource(package = package).readAll().len
21
22 proc list_files() =
23 for package in packages():
24 echo &"Recursive walk of package {package}: "
25 print_ls("", package = package)
26
27
5 proc main() = 28 proc main() =
6 echo "Mods available: ", modList() 29 echo "Packages available: ", packages()
7 for modName in modList(): 30 list_all_mods_all_files()
8 echo modName, ":" 31 list_files()
9 selectedMod = modName
10 for i in walkResources():
11 echo " ", i, ": ", loadResource(i).readAll().len
12 32
13 when isMainModule: 33 when isMainModule:
14 main() 34 main()