Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (45 sloc) 1.722 kB
module Portage.Metadata
( Metadata(..)
, metadataFromFile
, makeDefaultMetadata
) where
import qualified Data.ByteString as B
import Control.Applicative
import Text.XML.Light
data Metadata = Metadata
{ metadataHerds :: [String]
-- , metadataMaintainers :: [String],
-- , metadataUseFlags :: [(String,String)]
} deriving (Show)
metadataFromFile :: FilePath -> IO (Maybe Metadata)
metadataFromFile fp = do
doc <- parseXMLDoc <$> B.readFile fp
return (doc >>= parseMetadata)
parseMetadata :: Element -> Maybe Metadata
parseMetadata xml = do
let herds = map strContent (findChildren (unqual "herd") xml)
return Metadata
{
metadataHerds = herds
}
-- don't use Text.XML.Light as we like our own pretty printer
makeDefaultMetadata :: String -> String
makeDefaultMetadata long_description =
unlines [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
, "<!DOCTYPE pkgmetadata SYSTEM \"http://www.gentoo.org/dtd/metadata.dtd\">"
, "<pkgmetadata>"
, "\t<herd>haskell</herd>"
, (init {- strip trailing newline-}
. unlines
. map (\l -> if l `elem` ["<longdescription>", "</longdescription>"]
then "\t" ++ l -- leading/trailing lines
else "\t\t" ++ l -- description itself
)
. lines
. showElement
. unode "longdescription"
. ("\n" ++) -- prepend newline to separate form <longdescription>
. (++ "\n") -- append newline
) long_description
, "</pkgmetadata>"
]
Jump to Line
Something went wrong with that request. Please try again.