Commit d5c278cf authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add Utils module, tidy imports

parent 1517ab38
......@@ -4,17 +4,13 @@ import Distribution.Compat.ReadP (ReadP, readP_to_S, pfail, get, look, choice, (
import Distribution.Package (PackageIdentifier(..), parsePackageId)
import Distribution.ParseUtils
(Field(..), FieldDescr(..), ParseResult(..), PError
, field, liftField, readFields
, showDependency, parseDependency
, field, liftField, readFields, parseDependency
, warning, lineNo, locatedErrorMsg)
import Distribution.Version (Version(..), Dependency(..), VersionRange(..))
import Control.Exception
import Control.Monad (foldM, liftM, guard)
import Control.Monad (foldM, liftM)
import Data.Char (isSpace, toLower)
import Data.List (intersperse)
import Data.Maybe (listToMaybe)
import System.IO.Error (isDoesNotExistError)
import Text.PrettyPrint.HughesPJ (Doc, render, vcat, text, (<>), (<+>))
......
module Hackage.Utils where
import Distribution.ParseUtils (showDependency)
import Distribution.Version (Dependency(..))
import Control.Exception
import Control.Monad (guard)
import qualified Data.Char as Char (toLower)
import Data.List (intersperse)
import System.IO.Error (isDoesNotExistError)
readFileIfExists :: FilePath -> IO (Maybe String)
readFileIfExists path =
catchJust fileNotFoundExceptions
(fmap Just (readFile path))
(\_ -> return Nothing)
fileNotFoundExceptions :: Exception -> Maybe IOError
fileNotFoundExceptions e =
ioErrors e >>= \ioe -> guard (isDoesNotExistError ioe) >> return ioe
showDependencies :: [Dependency] -> String
showDependencies = concat . intersperse ", " . map (show . showDependency)
equating :: Eq a => (b -> a) -> b -> b -> Bool
equating p x y = p x == p y
comparing :: Ord a => (b -> a) -> b -> b -> Ordering
comparing p x y = p x `compare` p y
lowercase :: String -> String
lowercase = map Char.toLower
......@@ -42,6 +42,7 @@ Executable cabal
Hackage.Info
Hackage.Install
Hackage.List
Hackage.ParseUtils
Hackage.Setup
Hackage.Tar
Hackage.Types
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment