packages feed

nuxeo 0.2.0.3 → 0.3.0.0

raw patch · 4 files changed

+110/−56 lines, 4 filesdep +nuxeodep +optparse-applicativedep ~basenew-component:exe:nuxeo

Dependencies added: nuxeo, optparse-applicative

Dependency ranges changed: base

Files

− ChangeLog.md
@@ -1,5 +0,0 @@-# Revision history for nuxeo--## 0.1.0.0 -- YYYY-mm-dd--* First version. Released on an unsuspecting world.
+ app/Main.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import qualified Data.Text as Text+import qualified Data.Text.IO as TIO+import           Nuxeo.Log+import           Options.Applicative++data NuxeoCli = NuxeoCli { cliLogFile :: String }++args :: Parser NuxeoCli+args = NuxeoCli+       <$> strOption (long "log" <> help "Log file")++-- | Exemple to extract errors from Nuxeo log+nuxeocli :: NuxeoCli -> IO()+nuxeocli (NuxeoCli logFile) = (filter (\l -> nuxeoLogEntryType l == Error) <$> parseNuxeoLog logFile)+                              >>= mapM_ (\t -> TIO.putStrLn $+                                          Text.replicate 10 "=" <> "\n"+                                          <> Text.replicate 5 " " <> (Text.pack $ show $ nuxeoLogEntryDthr t)+                                          <> "\n" <> Text.replicate 10 "=" <> "\n"+                                          <> (Text.pack $ show $ nuxeoLogEntryType t)+                                          <> " - "+                                          <> nuxeoLogEntryAction t+                                          <> "\n\n"+                                          <> nuxeoLogEntryLog t+                                        )++main :: IO()+main = nuxeocli =<< execParser opts+  where+    opts = info (args <**> helper)+      (fullDesc+        <> progDesc "Nuxeo CLI"+        <> header "nuxeo - nuxeo cli tools"+      )
nuxeo.cabal view
@@ -1,37 +1,54 @@--- Initial nuxeo.cabal generated by cabal init.  For further documentation,---  see http://haskell.org/cabal/users-guide/+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 5cd9160f3e03d7882de953ffc6fbd27d624d06a39721394671a747afdbe4c317 -name:                nuxeo-version:             0.2.0.3-synopsis:            Nuxeo-description:         Nuxeo-license:             BSD3-license-file:        LICENSE-author:              Alexandre Peyroux-maintainer:          alex@xn--wxa.email--- copyright:-bug-reports:         https://github.com/apeyroux/nuxeo/issues-category:            System-build-type:          Simple-extra-source-files:  ChangeLog.md-cabal-version:       >=1.10+name:           nuxeo+version:        0.3.0.0+description:    Nuxeo tools+category:       System+homepage:       https://github.com/apeyroux/nuxeo#readme+bug-reports:    https://github.com/apeyroux/nuxeo/issues+author:         Alexandre Peyroux+maintainer:     alex@xn--wxa.email+license:        BSD3+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10  source-repository head-                  type:     git-                  location: https://github.com/apeyroux/nuxeo.git-                     +  type: git+  location: https://github.com/apeyroux/nuxeo+ library-  -- exposed-modules:-  -- other-modules:-  -- other-extensions:-  exposed-modules:     Nuxeo.Log-  ghc-options:         -Wall-  build-depends:       base >= 4.6 && < 5-                     , attoparsec-                     , bytestring-                     , conduit-                     , conduit-extra-                     , text-                     , time-  hs-source-dirs:      src-  default-language:    Haskell2010+  exposed-modules:+      Nuxeo.Log+  other-modules:+      Paths_nuxeo+  hs-source-dirs:+      src+  ghc-options: -Wall+  build-depends:+      attoparsec+    , base >=4.5 && <4.7+    , bytestring+    , conduit+    , conduit-extra+    , text+    , time+  default-language: Haskell2010++executable nuxeo+  main-is: Main.hs+  other-modules:+      Paths_nuxeo+  hs-source-dirs:+      app+  ghc-options: -Wall+  build-depends:+      base >=4.5 && <4.7+    , nuxeo+    , optparse-applicative+    , text+  default-language: Haskell2010
src/Nuxeo/Log.hs view
@@ -1,8 +1,7 @@ {-# LANGUAGE OverloadedStrings #-}  module Nuxeo.Log (-  NuxeoLog, -  NuxeoLogVerbose+  NuxeoLog   , NuxeoLogType (..)   , NuxeoLogEntry (..)   , parseNuxeoLog@@ -17,8 +16,6 @@ import qualified Data.Text as T import           Data.Time -type NuxeoLogVerbose = Bool- data NuxeoLogType = Debug | Error | Warning | Info deriving (Show, Read, Eq)  data NuxeoLogEntry = NuxeoLogEntry {@@ -34,25 +31,34 @@ -- | Parse Nuxeo server.log -- -- @--- logs <- parseNuxeoLog v "/opt/nuxeo-data/log/server.log"--- filter (\l -> (nuxeoLogEntryType l == Error)---            || (nuxeoLogEntryType l == Warning)) logs+-- parseNuxeoLog "./server.log"+--   >>= return . filter (\l -> nuxeoLogEntryType l == Error)+--   >>= mapM_ (\t ->+--                 putStrLn $ (show $ nuxeoLogEntryType t)+--                 <>  " "+--                 <> (Text.unpack $ nuxeoLogEntryAction t)+--                 <> " "+--                 <> (Text.unpack $ nuxeoLogEntryLog t)+--             ) -- @-parseNuxeoLog :: NuxeoLogVerbose -> FilePath -> IO NuxeoLog-parseNuxeoLog v logpath = runConduitRes $ sourceFile logpath .| sinkParser (nuxeoLogParser v)+parseNuxeoLog :: FilePath -> IO NuxeoLog+parseNuxeoLog logpath = runConduitRes $ sourceFile logpath .| sinkParser nuxeoLogParser -nuxeoLogParser :: NuxeoLogVerbose -> Parser NuxeoLog-nuxeoLogParser v = many $ (nuxeoLogEntryParser v <* endOfLine)+nuxeoLogParser :: Parser NuxeoLog+nuxeoLogParser = many $ (nuxeoLogEntryParser <* endOfLine) -nuxeoLogEntryParser :: NuxeoLogVerbose -> Parser NuxeoLogEntry-nuxeoLogEntryParser v = do+nuxeoLogEntryParser :: Parser NuxeoLogEntry+nuxeoLogEntryParser = do   ptime <- timeParser   ptype <- space *> nuxeoTypeLogParser   psection <- space *> nuxeoLogEntrySectionParser   paction <- space *> nuxeoLogEntryActionParser-  pnuxeolog <- case v of-    True -> space *> manyTill' anyChar (try $ lookAhead $ char '\n' *> timeParser)-    False -> space *> manyTill' anyChar (try $ lookAhead $ char '\n')+  pnuxeolog <- space *> manyTill' anyChar (try $ lookAhead $ (char '\n'+                                                               *> timeParser+                                                               *> space+                                                               *> nuxeoTypeLogParser+                                                               *> space+                                                               *> nuxeoLogEntryActionParser))   return $ NuxeoLogEntry ptime ptype psection paction (T.pack pnuxeolog)  nuxeoTypeLogParser :: Parser NuxeoLogType@@ -78,8 +84,7 @@   h  <- char ' ' *> count 2 digit   m  <- char ':' *> count 2 digit   s  <- char ':' *> count 2 digit-        *> char ','-        *> count 3 digit+  _  <- char ',' *> count 3 digit   return $     LocalTime { localDay = fromGregorian (read y) (read mm) (read d)               , localTimeOfDay = TimeOfDay (read h) (read m) (read s)