packages feed

graph-trace-viz 0.1.0.0 → 0.1.1.0

raw patch · 2 files changed

+46/−27 lines, 2 files

Files

app/Main.hs view
@@ -22,38 +22,49 @@ main = do   args <- getArgs -  traceFiles <- case args of-    [] -> do-      contents <- Dir.listDirectory =<< Dir.getCurrentDirectory-      let isTraceFile = (".trace" `List.isSuffixOf`)-      pure $ filter isTraceFile contents-    xs -> pure xs+  let isFlag arg = "--" `List.isPrefixOf` arg+      (flags, fileArgs) = span isFlag args+      nexusFlag = "--nexus" `List.elem` flags+      helpCommand = "--help" `List.elem` flags -  for_ traceFiles $ \traceFile -> do-    logContents-      <- either (\err -> fail $ "Failed parsing trace file: " <> err) id-       . Dot.parseLogEntries-     <$> BSL.readFile traceFile+  if helpCommand+  then putStrLn helpText+  else do+    traceFiles <- case fileArgs of+      [] -> do+        contents <- Dir.listDirectory =<< Dir.getCurrentDirectory+        let isTraceFile = (".trace" `List.isSuffixOf`)+        pure $ filter isTraceFile contents+      xs -> pure xs -    let dotFileContent = Dot.graphToDot $ Dot.buildGraph logContents-        fileName = (<> ".html")-                 $ if ".trace" `List.isSuffixOf` traceFile-                      then reverse . drop 6 $ reverse traceFile-                      else traceFile+    for_ traceFiles $ \traceFile -> do+      logContents+        <- either (\err -> fail $ "Failed parsing trace file: " <> err) id+         . Dot.parseLogEntries+       <$> BSL.readFile traceFile -        htmlHeader = $(embedFile "extras/header.html")-        htmlFooter = $(embedFile "extras/footer.html")+      let tree = Dot.buildTree logContents+          dotFileContent+            | nexusFlag = Dot.graphToDot (Dot.buildNexus tree)+            | otherwise = Dot.graphToDot tree+          fileName = (<> ".html")+                   $ if ".trace" `List.isSuffixOf` traceFile+                        then reverse . drop 6 $ reverse traceFile+                        else traceFile -    dotExists <- isJust <$> Dir.findExecutable "dot"-    unless dotExists $ die "Error! Graphviz is not installed or not accessible"+          htmlHeader = $(embedFile "extras/header.html")+          htmlFooter = $(embedFile "extras/footer.html") -    withFile fileName WriteMode $ \h -> do-      hSetBinaryMode h True-      hSetBuffering h (BlockBuffering Nothing)-      BS.hPut h htmlHeader-      writeSvg h dotFileContent-      BS.hPut h htmlFooter+      dotExists <- isJust <$> Dir.findExecutable "dot"+      unless dotExists $ die "Error! Graphviz is not installed or not accessible" +      withFile fileName WriteMode $ \h -> do+        hSetBinaryMode h True+        hSetBuffering h (BlockBuffering Nothing)+        BS.hPut h htmlHeader+        writeSvg h dotFileContent+        BS.hPut h htmlFooter+ -- | Invoke @dot@ to produce an svg document and write to the file handle writeSvg :: Handle -> BSB.Builder -> IO () writeSvg htmlFile dotContent =@@ -74,3 +85,11 @@       hClose stdOut     go _ _ _ _ = pure () +helpText :: String+helpText = unlines+  [ "Command line utility for rendering trace files generated by the \+    \graph-trace plugin into an interactive HTML document."+  , ""+  , "Flags:"+  , " --nexus     Causes two or more identical nodes to be merged into one"+  ]
graph-trace-viz.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               graph-trace-viz-version:            0.1.0.0+version:            0.1.1.0  synopsis:   Converts a graph-trace log into an HTML document