From 410939d68779352f4a858071349ac776dd32a804 Mon Sep 17 00:00:00 2001 From: PHO Date: Fri, 2 Oct 2009 10:32:06 +0900 Subject: [PATCH] It's now working! --- Main.hs | 52 ++++++++++++++++++++++++----------- pkg-find-outdated-cabal.cabal | 2 +- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Main.hs b/Main.hs index abbbaeb..13bc948 100644 --- a/Main.hs +++ b/Main.hs @@ -1,7 +1,9 @@ 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 @@ -17,7 +19,7 @@ indexURL :: String 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" @@ -32,7 +34,7 @@ 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") @@ -43,21 +45,38 @@ scanPkgs runQuery = mapM_ scanPkg 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 "-" @@ -67,3 +86,4 @@ extractPkgVersion = take' . readP_to_S parseVersion . last . split "-" where take' ((v, ""):_ ) = v take' (_ :xs) = take' xs + take' [] = error "Unparsable version" diff --git a/pkg-find-outdated-cabal.cabal b/pkg-find-outdated-cabal.cabal index 6effb39..4cad8a9 100644 --- a/pkg-find-outdated-cabal.cabal +++ b/pkg-find-outdated-cabal.cabal @@ -19,7 +19,7 @@ Source-Repository head Executable pkg-find-outdated-cabal Build-Depends: Cabal, FileManip, HSH, MissingH, base >= 4 && < 5, bytestring, - cabal-query, directory, filepath + cabal-query, directory, filepath, zlib Main-Is: Main.hs ghc-options: -- 2.40.0