|
6 | 6 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | 7 | # file, You can obtain one at https://mozilla.org/MPL/2.0/. |
8 | 8 |
|
9 | | -import |
10 | | - std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times], |
11 | | - utils, |
12 | | - toml_serialization |
| 9 | +import std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times], utils |
13 | 10 |
|
14 | 11 | const |
15 | 12 | pkgCache* = "/var/cache/rad/pkg" |
@@ -37,7 +34,40 @@ proc parseInfo*(name: string): Package = |
37 | 34 | if not dirExists(path): |
38 | 35 | abort(&"""{"name":8}{&"\{name\} not found":48}""") |
39 | 36 |
|
40 | | - Toml.loadFile(path / "info", Package) |
| 37 | + for line in (path / "info").lines: |
| 38 | + let line = line.strip() |
| 39 | + |
| 40 | + if line.isEmptyOrWhitespace() or line.startsWith('#'): |
| 41 | + continue |
| 42 | + |
| 43 | + if line.contains("= \"") or line.contains(" =\"") or '=' notin line: |
| 44 | + abort(&"""{"name":8}{&"wrong format":48}""") |
| 45 | + |
| 46 | + let |
| 47 | + pair = line.split('=', 1) |
| 48 | + key = pair[0] |
| 49 | + var value = pair[1] |
| 50 | + |
| 51 | + if not (value.startsWith('"') and value.endsWith('"')): |
| 52 | + abort(&"""{"name":8}{&"wrong format":48}""") |
| 53 | + |
| 54 | + value = value.strip(chars = {'"'}) |
| 55 | + |
| 56 | + case key |
| 57 | + of "ver": |
| 58 | + result.ver = value |
| 59 | + of "url": |
| 60 | + result.url = value |
| 61 | + of "sum": |
| 62 | + result.sum = value |
| 63 | + of "bld": |
| 64 | + result.bld = value |
| 65 | + of "run": |
| 66 | + result.run = value |
| 67 | + of "opt": |
| 68 | + result.opt = value |
| 69 | + else: |
| 70 | + abort(&"""{"name":8}{&"wrong format":48}""") |
41 | 71 |
|
42 | 72 | proc printContent(idx: int, name, ver, cmd: string) = |
43 | 73 | echo &"""{idx + 1:<8}{name:24}{ver:24}{cmd:8}""" & now().format("hh:mm tt") |
|
0 commit comments