1 module Main (main) where
4 import qualified Data.ByteString.Lazy as Lazy
7 import Distribution.Package
8 import Distribution.PackageDescription
9 import Distribution.Query
11 import System.Directory
12 import System.FilePath
13 import System.FilePath.Glob
14 import Text.ParserCombinators.ReadP
17 indexURL = "http://hackage.haskell.org/packages/archive/00-index.tar.gz"
20 pkgsrcPath = "/usr/pkgsrc" -- FIXME!
23 main = do appDir <- getAppUserDataDirectory "pkg-find-outdated-cabal"
24 createDirectoryIfMissing False appDir
26 let indexFile = appDir </> "00-index.tar.gz"
28 putStrLn "Downloading the Hackage index..."
31 runIO ("wget", ["-N", indexURL])
35 indexBin <- Lazy.readFile indexFile
36 let runQuery q = queryIndex q indexBin
38 makefiles <- namesMatching (pkgsrcPath </> "*" </> "*" </> "Makefile")
39 scanPkgs runQuery makefiles
41 scanPkgs :: (Query -> [PackageDescription]) -> [FilePath] -> IO ()
42 scanPkgs runQuery = mapM_ scanPkg
44 scanPkg :: FilePath -> IO ()
46 = do isCabalPkg <- run ("fgrep", ["-q", "mk/haskell.mk", makPath])
50 checkPkg :: FilePath -> IO ()
52 = do mak <- readFile makPath
53 case grep "DISTNAME=" (lines mak) of
54 [l] -> do let line = (trd ' ' . trd '\t') l
55 distname = cut 1 '=' line
56 pkgName = extractPkgName distname
57 pkgVer = extractPkgVersion distname
58 pkgId = PackageIdentifier pkgName pkgVer
59 putStrLn (distname ++ ": " ++ show pkgId)
62 extractPkgName :: String -> PackageName
63 extractPkgName = PackageName . head . split "-"
65 extractPkgVersion :: String -> Version
66 extractPkgVersion = take' . readP_to_S parseVersion . last . split "-"
68 take' ((v, ""):_ ) = v
69 take' (_ :xs) = take' xs