[Pkg-haskell-commits] [package-plan] 01/05: update-suggestions.hs: Suggests minor updates

Joachim Breitner nomeata at moszumanska.debian.org
Sat May 31 21:35:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

nomeata pushed a commit to branch master
in repository package-plan.

commit 7979e7d37c34017e2873a6400c798502ce320f4d
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Sat May 31 23:03:31 2014 +0200

    update-suggestions.hs: Suggests minor updates
    
    This script detects all upgradeable packages that leave the first three
    versions alone. These are likely bugfixes and/or dependency adjustments,
    and usually worth aiming for.
---
 update-suggestions.hs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/update-suggestions.hs b/update-suggestions.hs
new file mode 100644
index 0000000..0b0599c
--- /dev/null
+++ b/update-suggestions.hs
@@ -0,0 +1,92 @@
+{-# LANGUAGE RecordWildCards #-}
+
+import qualified Data.Map as M
+import qualified Codec.Archive.Tar as Tar
+import Codec.Archive.Tar.Entry
+import qualified Data.ByteString.Lazy as BS
+import Text.Parsec
+import Text.Parsec.String
+import Control.Monad
+import Data.List
+import Data.Functor
+import System.Directory
+import Text.Printf
+
+type Package = String
+type Version = [Integer]
+
+readCabalVersions :: IO (M.Map Package [Version])
+readCabalVersions = do
+    dotCabal <- getAppUserDataDirectory "cabal"
+    let tarfilename = dotCabal ++ "/packages/hackage.haskell.org/00-index.tar"
+    raw <- BS.readFile tarfilename
+    return $
+        M.fromListWith (++) $
+        map (\(p,v) -> (p,[v])) $
+        map parseEntry $
+        filter (not . ignoredEntry) $
+        Tar.foldEntries (:) [] (error "invalid tar") (Tar.read raw)
+  where
+    ignoredEntry :: Entry -> Bool
+    ignoredEntry (Entry {..}) = fromTarPath entryTarPath `elem` ["preferred-versions"]
+
+    parseEntry :: Entry -> (Package, Version)
+    parseEntry (Entry {..}) = (p, v)
+      where
+        (p,v) = either (error.show) id $ parse pathParser "tar path" (fromTarPath entryTarPath)
+
+    pathParser = do
+        p <- manyTill anyChar (char '/')
+        v <- versionNumber
+        char '/'
+        p' <- manyTill anyChar (char '.')
+        guard (p == p')
+        string "cabal"
+        eof
+        return (p,v)
+
+readPackagePlan :: IO (M.Map Package Version)
+readPackagePlan = do
+    raw <- readFile "packages.txt"
+    return $ M.fromList $ either (error.show) id $ parse packagePlanParser "packages.txt"  raw
+  where
+    packagePlanParser = between (return ()) eof $ line `sepEndBy` newline
+    line = do
+        p <- packageName
+        char ' '
+        v <- versionNumber
+        manyTill anyChar (lookAhead newline)
+        return (p,v)
+
+    packageName = many (alphaNum <|> char '-')
+
+versionNumber :: Parser [Integer]
+versionNumber = (read <$> many1 digit) `sepBy` char '.'
+
+showVersionNumber :: Version -> String
+showVersionNumber = concat . intersperse "." . map show
+
+candidate :: Version -> Version -> Bool
+candidate p v = take 3 p == take 3 v && v > p
+
+hdiffLink :: Package -> Version -> Version -> String
+hdiffLink p v1 v2 =
+    printf "http://hdiff.luite.com/cgit/%s/diff/?id=%s&id2=%s"
+        p (showVersionNumber v2) (showVersionNumber v1)
+
+main :: IO ()
+main = do
+    versions <- readCabalVersions
+    packagePlan <- readPackagePlan
+    forM_ (M.toList packagePlan) $ \(pkg, plan) ->
+        case filter (candidate plan) <$> M.lookup pkg versions of
+            Nothing -> return ()
+            Just [] -> return ()
+            Just better -> do
+                let best = maximum better
+                putStrLn $ printf "%s %s -> %s (%s)"
+                    pkg
+                    (showVersionNumber plan)
+                    (showVersionNumber best)
+                    (hdiffLink pkg plan best)
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-haskell/package-plan.git



More information about the Pkg-haskell-commits mailing list