packages feed

porte 0.0.3 → 0.0.4

raw patch · 5 files changed

+24/−27 lines, 5 filesdep +extensible-exceptionsdep ~basedep ~stringsearch

Dependencies added: extensible-exceptions

Dependency ranges changed: base, stringsearch

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (C) 2008 Samy Al Bahra+Copyright (C) 2008, 2010 Samy Al Bahra All rights reserved.  Redistribution and use in source and binary forms, with or without
Porte/Ports.hs view
@@ -1,19 +1,20 @@+{-# LANGUAGE ScopedTypeVariables #-}+ module Porte.Ports where-import Control.Exception+import Control.Exception.Extensible import Control.Monad-import Data.ByteString.Search.KnuthMorrisPratt-import qualified Data.ByteString.Lazy.Char8     as B-import qualified Data.ByteString.Char8          as C -import qualified Data.List                      as L-import qualified System.IO                      as I-import qualified System.Environment             as E+import qualified Data.ByteString.Lazy.Search.KMP as D+import qualified Data.ByteString.Lazy.Char8      as B+import qualified Data.ByteString.Char8           as C +import qualified Data.List                       as L+import qualified System.IO                       as I+import qualified System.Environment              as E  portsIndex = "/usr/ports/INDEX-8" portsPrefix = "/usr/ports/"  type Name = B.ByteString type DistributionName = B.ByteString -type Version = B.ByteString type Path = B.ByteString type Prefix = B.ByteString type Comment = B.ByteString@@ -31,7 +32,6 @@ data Port = Port {               name :: Name,               distributionName :: DistributionName,-              version :: Version,               path :: Path,               comment :: Comment,               descriptionPath :: DescriptionPath,@@ -48,7 +48,6 @@ toField :: String -> Maybe PortField toField "name" = Just name toField "package" = Just distributionName-toField "version" = Just version toField "distributionName" = Just distributionName toField "path" = Just path toField "comment" = Just comment@@ -61,9 +60,9 @@ search (x:xs) p =   search xs $ filter f p   where-  f p = case (matchSL (C.pack $ snd x) (fst x p)) of+  f p = case (D.indices (C.pack $ snd x) (fst x p)) of           [] -> False-          _  -> True +          _  -> True search _ p = p  find :: PortQuery -> [Port] -> [Port]@@ -77,8 +76,8 @@   do   o <- try $ (B.readFile . B.unpack . descriptionPath) p   case (o) of-    Left h  -> return Nothing      Right h -> return $ Just $ B.filter (/= '\n') h+    Left (e :: IOException) -> return Nothing   glue :: (Port -> [B.ByteString]) -> Port -> B.ByteString glue f p = B.concat $ L.intersperse (B.pack " ") (f p) @@ -104,7 +103,6 @@       extractDepends : _) =         Port (B.tail . B.dropWhile (/= '/') $ path')              (name)-             (last $ B.split '-' name)              (path')              (comment)              (pkgDescr)@@ -125,12 +123,13 @@  o <- try $ E.getEnv "INDEX"  case o of    Right h -> index $ Just h-   _       -> index $ Just portsIndex+   Left (e :: IOException) -> index $ Just portsIndex index (Just path) = do   o <- try $ B.readFile path   case o of     Right h -> return $ parseIndex h -    _       -> error $ "INDEX file (" ++ path ++ ") could not be opened"+    Left (e :: IOException) -> error $ show e ++ "\nporte: Consider setting the $INDEX " +++                                                    "environment variable correctly."  putPorts :: [PortField] -> [Port] -> IO () putPorts f = hPutPorts I.stdout f
Porte/Statistics.hs view
@@ -1,6 +1,5 @@ module Porte.Statistics where import qualified Data.ByteString.Lazy.Char8 as B-import qualified Porte.Ports                as P import qualified Data.Map                   as M  import qualified System.IO                  as I import Text.Printf(printf)@@ -9,11 +8,10 @@ type FieldFrequency = (B.ByteString, Int)   mapFrequency :: [B.ByteString] -> FrequencyMap -mapFrequency (x:xs) = M.insertWith' (+) x 1 $ mapFrequency xs-mapFrequency _ = M.empty+mapFrequency = foldr (\x -> M.insertWith' (+) x 1) M.empty -fieldsFrequency f r = M.assocs $ mapFrequency (concat $ map f r)-fieldFrequency f r = M.assocs $ mapFrequency (map f r)+fieldsFrequency f = M.assocs . mapFrequency . concat . map f +fieldFrequency f  = M.assocs . mapFrequency . map f  printFrequency :: FieldFrequency -> IO () printFrequency (a, b) = I.putStr (printf "%5d " b) >> B.putStrLn a 
Porte/Tool.hs view
@@ -7,10 +7,10 @@ import qualified Porte.Statistics as S import qualified System.IO        as I -version = "0.0.3"+version = "0.0.4"  -- Generic port print format-printFormat = [P.path, P.version, P.comment]+printFormat = [P.path, P.comment, P.website]  -- Exception raising toField toField :: String -> P.PortField
porte.cabal view
@@ -1,5 +1,5 @@ Name:                porte-Version:             0.0.3+Version:             0.0.4 Cabal-Version:       >= 1.2 Synopsis:            FreeBSD ports index search and analysis tool Description:         Porte provides a simple, fast and efficient interface to searching@@ -9,11 +9,11 @@ License:             BSD3 License-file:        LICENSE Author:              Samy Al Bahra-Maintainer:          sbahra@kerneled.org+Maintainer:          sbahra@repnop.org Build-Type:          Simple  Library-  Build-Depends:     base < 4, bytestring, containers, stringsearch+  Build-Depends:     base < 5, bytestring, containers, extensible-exceptions, stringsearch >= 0.3.0   Exposed-Modules:   Porte.Tool Porte.Statistics Porte.Ports  Executable porte