[Pkg-haskell-commits] [package-plan] 02/05: Parse cabal --list

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 bde4c7680ee4ce317bf83800880ccde019f2822f
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Sat May 31 23:08:38 2014 +0200

    Parse cabal --list
    
    instead of parsing the 00-list.tar file. Slower, but more proper.
---
 update-suggestions.hs | 43 ++++++++++---------------------------------
 1 file changed, 10 insertions(+), 33 deletions(-)

diff --git a/update-suggestions.hs b/update-suggestions.hs
index 0b0599c..e04b0ef 100644
--- a/update-suggestions.hs
+++ b/update-suggestions.hs
@@ -1,15 +1,10 @@
-{-# 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 System.Process
 import Text.Printf
 
 type Package = String
@@ -17,40 +12,21 @@ 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
+    raw <- readProcess "cabal" ["list", "--simple-output"] ""
     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)
+        either (error.show) id $
+        parse packagePlanParser "cabal list"  raw
 
 readPackagePlan :: IO (M.Map Package Version)
 readPackagePlan = do
     raw <- readFile "packages.txt"
     return $ M.fromList $ either (error.show) id $ parse packagePlanParser "packages.txt"  raw
+
+packagePlanParser :: Parser [(Package, Version)]
+packagePlanParser = between (return ()) eof $ line `sepEndBy` newline
   where
-    packagePlanParser = between (return ()) eof $ line `sepEndBy` newline
     line = do
         p <- packageName
         char ' '
@@ -58,9 +34,10 @@ readPackagePlan = do
         manyTill anyChar (lookAhead newline)
         return (p,v)
 
-    packageName = many (alphaNum <|> char '-')
+packageName :: Parser Package
+packageName = many (alphaNum <|> char '-')
 
-versionNumber :: Parser [Integer]
+versionNumber :: Parser Version
 versionNumber = (read <$> many1 digit) `sepBy` char '.'
 
 showVersionNumber :: Version -> String

-- 
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