lat 0.5 → 0.6
raw patch · 5 files changed
+83/−62 lines, 5 filesdep +ansi-wl-pprintdep +hsinidep −ConfigFiledep −MissingHdep −safedep ~HDBCdep ~HDBC-sqlite3dep ~HTTP
Dependencies added: ansi-wl-pprint, hsini
Dependencies removed: ConfigFile, MissingH, safe, wl-pprint
Dependency ranges changed: HDBC, HDBC-sqlite3, HTTP, base, cmdargs, directory, filepath, haskell98, haxr, mtl, old-locale, regex-compat, tagsoup, time
Files
- lat.cabal +19/−6
- src/Commands.hs +31/−28
- src/Filter.hs +15/−16
- src/RepEng.hs +17/−11
- src/Types.hs +1/−1
lat.cabal view
@@ -1,5 +1,5 @@ name : lat-version : 0.5+version : 0.6 license : GPL-3 author : Magnus Therning maintainer : magnus@therning.org@@ -28,8 +28,8 @@ extra-source-files : misc/zshcompletion._lat source-repository head- type : darcs- location : http://patch-tag.com/r/magnus/lat+ type : git+ location : https://github.com/magthe/lat.git executable lat hs-source-dirs : src@@ -46,9 +46,22 @@ Report Types build-depends :- base >=4 && <5, haskell98, safe, HDBC, HDBC-sqlite3, mtl, time,- directory, filepath, old-locale, regex-compat, tagsoup, ConfigFile,- haxr, MissingH, wl-pprint, cmdargs, HTTP+ base ==4.3.*,+ ansi-wl-pprint ==0.6.*,+ time ==1.2.*,+ hsini ==0.1.*,+ regex-compat ==0.93.*,+ filepath ==1.2.*,+ directory ==1.1.*,+ haskell98 ==1.1.*,+ HDBC-sqlite3 ==2.3.*,+ HDBC ==2.2.*,+ mtl ==2.0.*,+ haxr ==3000.8.*,+ tagsoup ==0.12.*,+ old-locale ==1.0.*,+ HTTP ==4000.1.*,+ cmdargs ==0.7.* ghc-options : -Wall -fno-warn-missing-signatures -fno-warn-name-shadowing -fno-warn-orphans
src/Commands.hs view
@@ -30,10 +30,8 @@ -- {{{1 doCommand doCommand = do home <- getAppUserDataDirectory "lat"- let allArgs = map (\ f -> f home) [_distroAddArgs, _distroListArgs, _vulnUpdateArgs, _vulnListArgs, _vulnReportArgs]- let ver = "lat " ++ (showVersion version) ++ " - Linux Alert Tracker"- ++ "\nCopyright 2010 Magnus Therning <magnus@therning.org>"- cmdArgs ver allArgs >>= _doCommand+ -- &= help "Linux Alert Tracker - track alerts on LWN.net" &= program "lat" &= summary ver+ cmdArgs (_allCmds home) >>= _doCommand _doCommand a@(CAT.DistroAdd {}) = D.distroAdd a _doCommand a@(CAT.DistroList {}) = D.distroList a@@ -42,39 +40,44 @@ _doCommand a@(CAT.VulnReport {}) = V.vulnReport a -- {{{1 Command line arg definitions-_configAttrib = text "Set dir for configuration" & empty "~/.lat" & typDir+_allCmds h = modes cmds &= help "Linux Alert Tracker - track alerts on LWN.net" &= program "lat" &= summary ver+ where+ cmds = map (\ f -> f h) [_distroAddArgs, _distroListArgs, _vulnUpdateArgs, _vulnListArgs, _vulnReportArgs]+ ver = "lat v" ++ (showVersion version) ++ " Copyright 2010 Magnus Therning <magnus@therning.org>" -_distroAddArgs h = mode CAT.DistroAdd+_configAttrib = help "Set dir for configuration" &= opt "~/.lat" &= typDir++_distroAddArgs h = CAT.DistroAdd { CAT.config = h &= _configAttrib- , CAT.name = def &= argPos 0 & typ "NAME"- , CAT.url = def &= argPos 1 & typ "URL"- } &= text "add a distribution"+ , CAT.name = def &= argPos 0 &= typ "NAME"+ , CAT.url = def &= argPos 1 &= typ "URL"+ } &= help "add a distribution" -_distroListArgs h = mode CAT.DistroList+_distroListArgs h = CAT.DistroList { CAT.config = h &= _configAttrib- } &= text "list distributions"+ } &= help "list distributions" -_vulnUpdateArgs h = mode CAT.VulnUpdate+_vulnUpdateArgs h = CAT.VulnUpdate { CAT.config = h &= _configAttrib- , CAT.dry = def &= text "Dry run"- } &= text "update the vulnerability database"+ , CAT.dry = def &= help "Dry run"+ } &= help "update the vulnerability database" -_vulnListArgs h = mode CAT.VulnList+_vulnListArgs h = CAT.VulnList { CAT.config = h &= _configAttrib- , CAT.typ = enum CAT.Unreported- [ CAT.Unreported &= text "List unreported issues (default)"- , CAT.Reported &= text "List reported issues"- , CAT.All &= text "List all issues"+ , CAT.typ = enum+ [ CAT.Unreported &= help "List unreported issues (default)"+ , CAT.Reported &= help "List reported issues"+ , CAT.All &= help "List all issues" ]- , CAT.size = enum CAT.Normal- [ CAT.Small &= text "Output format: small"- , CAT.Normal &= text "Output format: normal" & flag "n"- , CAT.Full &= text "Output format: full"+ , CAT.size = enum+ [ CAT.Small &= help "Output format: small"+ , CAT.Normal &= help "Output format: normal" &= name "n"+ , CAT.Full &= help "Output format: full" ]- , CAT.nofilter = def &= text "Filter off" & explicit & flag "nofilter"- } &= text "list known vulnerabilities"+ , CAT.nofilter = def &= help "Filter off" &= explicit &= name "nofilter"+ } &= help "list known vulnerabilities" -_vulnReportArgs h = mode CAT.VulnReport+_vulnReportArgs h = CAT.VulnReport { CAT.config = h &= _configAttrib- , CAT.nofilter = def &= text "Filter off" & explicit & flag "nofilter"- } &= text "report (process) vulnerabilities"+ , CAT.nofilter = def &= help "Filter off" &= explicit &= name "nofilter"+ } &= help "report (process) vulnerabilities"
src/Filter.hs view
@@ -16,17 +16,15 @@ module Filter where -import qualified Types as T--import Control.Monad.Error-import Data.ConfigFile-import Data.Either.Utils import Data.Maybe import System.Directory import System.FilePath import Text.Regex-import qualified Control.Exception as CE+import qualified Data.Ini as Ini+import qualified Data.Ini.Reader as IniR +import qualified Types as T+ filterAlerts :: [T.Alert] -> IO [T.Alert] filterAlerts as = do filters <- _getFilters@@ -44,20 +42,21 @@ in do cfg <- _getConfigFile- if (not $ has_section cfg "packages")+ if (not $ Ini.hasSection "packages" cfg) then return [] else do- let is = forceEither $ items cfg "packages"+ -- let is = forceEither $ items cfg "packages"+ let is = Ini.allItems "packages" cfg sequence $ map readRegexFile is --- _getConfigFile :: IO ConfigParser-_getConfigFile = let- gCF h = runErrorT $ join $ liftIO $ readfile emptyCP (h </> "lat.conf")- in do- home <- getAppUserDataDirectory "lat"- conf <- CE.catch (gCF home) (\ e -> return $ Left (OtherProblem "IO Error", show (e :: CE.SomeException)))- -- TODO: add some better error handling here, or at least reporting to the user- return $ either (const emptyCP) id conf+-- _getConfigFile :: IO Data.Ini.Types.Config+_getConfigFile = do+ home <- getAppUserDataDirectory "lat"+ confStr <- readFile $ home </> "lat.conf"+ let conf = IniR.parse confStr+ case conf of+ Left _ -> return Ini.emptyConfig+ Right c -> return c -- _doFilter :: [(String, [Regex])] -> [T.Alert] -> [T.Alert] _doFilter fs = filter (_isGoodalert fs)
src/RepEng.hs view
@@ -18,31 +18,36 @@ import Control.Monad.Error import Control.Exception as CE-import Data.ConfigFile-import Data.Either.Utils import Data.Maybe import Network.XmlRpc.Client import Network.XmlRpc.Internals import System.Directory import System.FilePath+import qualified Data.Ini as Ini+import qualified Data.Ini.Reader as IniR + import qualified AlertDB as ADB import qualified Types as T +-- stuff that should be removed at some point, leftovers from use of MissingH+fromRight (Right a) = a+fromRight _ = error "RepEng.fromRight: Left!"+ -- assoc of backend name and function (taking path to database and the alert) type Engine = (String, FilePath -> T.Alert -> IO ()) allEngines :: [Engine] allEngines = [ ("jira", _jiraReport)] -_getConfigFile :: IO ConfigParser-_getConfigFile = let- gCF h = runErrorT $ join $ liftIO $ readfile emptyCP (combine h "lat.conf")- in do- home <- getAppUserDataDirectory "lat"- conf <- CE.catch (gCF home) (\ e -> return $ Left (OtherProblem "IO Error", show (e :: CE.SomeException)))- -- TODO: add some better error handling here, or at least reporting to the user- return $ either (const emptyCP) id conf+-- _getConfigFile :: IO Data.Ini.Types.Config+_getConfigFile = do+ home <- getAppUserDataDirectory "lat"+ confStr <- readFile $ home </> "lat.conf"+ let conf = IniR.parse confStr+ case conf of+ Left _ -> return Ini.emptyConfig+ Right c -> return c data JiraConfig = JiraConfig { jiraURL :: String@@ -54,7 +59,8 @@ , jiraComponent :: String } deriving (Show) -_getWithDefault cfg section option def = either (const def) id (get cfg section option)+-- _getWithDefault cfg section option def = either (const def) id (get cfg section option)+_getWithDefault cfg section option def = maybe def id (Ini.getOption section option cfg) _getJiraConfig cfg = JiraConfig url user pwd project typ priority component where
src/Types.hs view
@@ -19,7 +19,7 @@ import Data.Maybe import Data.Time.Calendar --import Data.Time.Clock-import Text.PrettyPrint.Leijen+import Text.PrettyPrint.ANSI.Leijen data Distro = Distro { distroId :: Maybe Int -- ^ DB ID, automatically populated by the DB