lib/min_sys.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
import tables, os, osproc, strutils import ../core/types, ../core/parser, ../core/interpreter, ../core/utils # OS proc sys_module*(i: In)= i.define("sys") .symbol("pwd") do (i: In): i.push newVal(getCurrentDir()) .symbol("cd") do (i: In): var f: MinValue i.reqString f f.strVal.setCurrentDir .symbol("ls") do (i: In): var a: MinValue i.reqString a var list = newSeq[MinValue](0) for i in walkDir(a.strVal): list.add newVal(i.path) i.push list.newVal .symbol("ls-r") do (i: In): var a: MinValue i.reqString a var list = newSeq[MinValue](0) for i in walkDirRec(a.strVal): list.add newVal(i) i.push list.newVal .symbol("system") do (i: In): var a: MinValue i.reqString a i.push execShellCmd(a.strVal).newVal .symbol("run") do (i: In): var a: MinValue i.reqString a let words = a.strVal.split(" ") let cmd = words[0] var args = newSeq[string](0) if words.len > 1: args = words[1..words.len-1] i.push execProcess(cmd, args, nil, {poUsePath}).newVal .symbol("getenv") do (i: In): var a: MinValue i.reqString a i.push a.strVal.getEnv.newVal .symbol("putenv") do (i: In): var key, value: MinValue i.reqTwoStrings key, value key.strVal.putEnv value.strVal .symbol("env?") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.existsEnv.newVal .symbol("which") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.findExe.newVal .symbol("os") do (i: In): i.push hostOS.newVal .symbol("cpu") do (i: In): i.push hostCPU.newVal .symbol("file?") do (i: In): var f: MinValue i.reqString f i.push f.strVal.fileExists.newVal .symbol("dir?") do (i: In): var f: MinValue i.reqString f i.push f.strVal.dirExists.newVal .symbol("rm") do (i: In): var f: MinValue i.reqString f f.strVal.removeFile .symbol("cp") do (i: In): var a, b: MinValue i.reqTwoStrings a, b copyFile b.strVal, a.strVal .symbol("mv") do (i: In): var a, b: MinValue i.reqTwoStrings a, b moveFile b.strVal, a.strVal .symbol("rmdir") do (i: In): var f: MinValue i.reqString f f.strVal.removeDir .symbol("mkdir") do (i: In): var f: MinValue i.reqString f f.strVal.createDir .symbol("sleep") do (i: In): var ms: MinValue i.reqInt ms sleep ms.intVal.int .symbol("chmod") do (i: In): var s, perms: MinValue i.reqStringAndNumber s, perms s.getString.setFilePermissions(perms.intVal.toFilePermissions) .symbol("symlink?") do (i: In): var s: MinValue i.reqStringLike s i.push s.getString.symlinkExists.newVal .symbol("symlink") do (i: In): var src, dest: MinValue i.reqTwoStrings dest, src src.getString.createSymlink dest.getString .symbol("hardlink") do (i: In): var src, dest: MinValue i.reqTwoStrings dest, src src.getString.createHardlink dest.getString .finalize() |