module Main (main) where
+import qualified Codec.Compression.GZip as GZip
import Control.Monad
import qualified Data.ByteString.Lazy as Lazy
+import Data.List
import Data.List.Utils
import Data.Version
import Distribution.Package
indexURL = "http://hackage.haskell.org/packages/archive/00-index.tar.gz"
pkgsrcPath :: String
-pkgsrcPath = "/usr/pkgsrc" -- FIXME!
+pkgsrcPath = "/usr/pkgsrc"
main :: IO ()
main = do appDir <- getAppUserDataDirectory "pkg-find-outdated-cabal"
cd cwd
putStrLn "Done."
- indexBin <- Lazy.readFile indexFile
+ indexBin <- fmap GZip.decompress $ Lazy.readFile indexFile
let runQuery q = queryIndex q indexBin
makefiles <- namesMatching (pkgsrcPath </> "*" </> "*" </> "Makefile")
where
scanPkg :: FilePath -> IO ()
scanPkg makPath
- = do isCabalPkg <- run ("fgrep", ["-q", "mk/haskell.mk", makPath])
- when isCabalPkg
- $ checkPkg makPath
-
- checkPkg :: FilePath -> IO ()
- checkPkg makPath
= do mak <- readFile makPath
- case grep "DISTNAME=" (lines mak) of
- [l] -> do let line = (trd ' ' . trd '\t') l
- distname = cut 1 '=' line
- pkgName = extractPkgName distname
- pkgVer = extractPkgVersion distname
- pkgId = PackageIdentifier pkgName pkgVer
- putStrLn (distname ++ ": " ++ show pkgId)
- _ -> return ()
+ case grep "mk/haskell.mk" (lines mak) of
+ [] -> return ()
+ _ -> checkPkg mak
+
+ checkPkg :: String -> IO ()
+ checkPkg mak
+ = case grep "DISTNAME=" (lines mak) of
+ [l] -> let line = (trd ' ' . trd '\t') l
+ distname = cut 1 '=' line
+ name = extractPkgName distname
+ ver = extractPkgVersion distname
+ pkgId = PackageIdentifier name ver
+ query = Id (sameName pkgId) :& Id (newerVers pkgId)
+ in
+ case runQuery query of
+ [] -> putStrLn (distname ++ ": is the LATEST")
+ xs -> let sorted = sortBy cmpVers xs
+ latest = last sorted
+ lVer = (pkgVersion . package) latest
+ in
+ putStrLn (distname ++ ": has a newer version " ++ showVersion lVer)
+ _ -> return ()
+
+ sameName :: PackageIdentifier -> PackageIdentifier -> Bool
+ sameName a b = pkgName a == pkgName b
+
+ newerVers :: PackageIdentifier -> PackageIdentifier -> Bool
+ newerVers a b = pkgVersion a < pkgVersion b
+
+ cmpVers :: PackageDescription -> PackageDescription -> Ordering
+ cmpVers a b = (pkgVersion . package) a `compare` (pkgVersion . package) b
extractPkgName :: String -> PackageName
extractPkgName = PackageName . head . split "-"
where
take' ((v, ""):_ ) = v
take' (_ :xs) = take' xs
+ take' [] = error "Unparsable version"