WIP: Refactor for Nim 2.x
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
## =========
|
||||
##
|
||||
## Little tool to extract expected information from log streams.
|
||||
import json, logging, ncurses, os, osproc, sequtils, streams, strutils, threadpool
|
||||
import nre except toSeq
|
||||
import std/[json, logging, os, osproc, sequtils, streams, strutils]
|
||||
import std/nre except toSeq
|
||||
import docopt, malebolgia, ncurses
|
||||
|
||||
import private/ncurses_ext
|
||||
|
||||
@@ -15,6 +16,16 @@ type
|
||||
pattern: Regex
|
||||
expected, found: bool
|
||||
|
||||
SourceKind = enum skStdIn, skFile, skCmd
|
||||
InSource = object
|
||||
case kind: SourceKind
|
||||
of skStdIn:
|
||||
discard
|
||||
of skFile:
|
||||
filename: string
|
||||
of skCmd:
|
||||
cmdInvocation: string
|
||||
|
||||
let expPattern = re"^-([eE])([^;]+);(.+)$"
|
||||
|
||||
var msgChannel: Channel[string]
|
||||
@@ -24,15 +35,16 @@ proc exitErr(msg: string): void =
|
||||
quit(QuitFailure)
|
||||
|
||||
proc readStream(stream: Stream): void =
|
||||
var line = TaintedString""
|
||||
var line: string
|
||||
try:
|
||||
while stream.readLine(line): msgChannel.send(line)
|
||||
except: discard ""
|
||||
|
||||
when isMainModule:
|
||||
var cmdProc: Process
|
||||
var inStream: Stream
|
||||
var source = InSource(kind: skStdIn)
|
||||
var outFile: File
|
||||
var threadMaster = createMaster()
|
||||
|
||||
try:
|
||||
let VERSION = "0.2.0"
|
||||
@@ -113,10 +125,10 @@ Expectations JSON definitions follow this format:
|
||||
elif arg.startsWith("-i"):
|
||||
let filename = arg[2..^1]
|
||||
try:
|
||||
if not existsFile(filename):
|
||||
if not fileExists(filename):
|
||||
exitErr "no such file (" & filename & ")"
|
||||
|
||||
inStream = newFileStream(filename)
|
||||
source = InSource(kind: skFile, filename: filename)
|
||||
except:
|
||||
exitErr "could not open file (" & filename & "):\t\n" &
|
||||
getCurrentExceptionMsg()
|
||||
@@ -157,7 +169,7 @@ Expectations JSON definitions follow this format:
|
||||
inStream = cmdProc.outputStream
|
||||
|
||||
open(msgChannel)
|
||||
spawn readStream(inStream)
|
||||
threadMaster.spawn readStream(inStream)
|
||||
|
||||
# Init ncurses
|
||||
let stdscr = initscr()
|
||||
@@ -272,5 +284,6 @@ Expectations JSON definitions follow this format:
|
||||
if not inStream.isNil: close(inStream)
|
||||
if not outFile.isNil: close(outFile)
|
||||
|
||||
threadMaster.cancel()
|
||||
close(msgChannel)
|
||||
endwin()
|
||||
|
||||
@@ -8,5 +8,4 @@ bin = @["log_happy"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires @["nim >= 0.16.1", "docopt >= 0.6.4", "ncurses"]
|
||||
|
||||
requires @["nim >= 0.16.1", "docopt >= 0.6.4", "ncurses", "malebolgia >= 1.3.2"]
|
||||
|
||||
Reference in New Issue
Block a user