Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (48 sloc) 1.839 kb
2c9ea10 @kolmodin Add partial parsing of metadata.xml
kolmodin authored
1 module Portage.Metadata
2 ( Metadata(..)
b37fb95 @kolmodin Add metadata to Overlay data type
kolmodin authored
3 , metadataFromFile
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
4 , makeDefaultMetadata
2c9ea10 @kolmodin Add partial parsing of metadata.xml
kolmodin authored
5 ) where
6
7 import qualified Data.ByteString as B
8
9 import Control.Applicative
10
11 import Text.XML.Light
12
13 data Metadata = Metadata
14 { metadataHerds :: [String]
15 -- , metadataMaintainers :: [String],
16 -- , metadataUseFlags :: [(String,String)]
17 } deriving (Show)
18
b37fb95 @kolmodin Add metadata to Overlay data type
kolmodin authored
19 metadataFromFile :: FilePath -> IO (Maybe Metadata)
20 metadataFromFile fp = do
2c9ea10 @kolmodin Add partial parsing of metadata.xml
kolmodin authored
21 doc <- parseXMLDoc <$> B.readFile fp
22 return (doc >>= parseMetadata)
23
24 parseMetadata :: Element -> Maybe Metadata
25 parseMetadata xml = do
26 let herds = map strContent (findChildren (unqual "herd") xml)
27 return Metadata
28 {
29 metadataHerds = herds
30 }
59858eb @trofi Added 'metadata.xml' autogeneration for packages where it does not ex…
trofi authored
31
32 -- don't use Text.XML.Light as we like our own pretty printer
33 makeDefaultMetadata :: String -> String
34 makeDefaultMetadata long_description =
35 unlines [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
36 , "<!DOCTYPE pkgmetadata SYSTEM \"http://www.gentoo.org/dtd/metadata.dtd\">"
37 , "<pkgmetadata>"
38 , "\t<herd>haskell</herd>"
39 , "\t<maintainer>"
40 , "\t\t<email>haskell@gentoo.org</email>"
41 , "\t</maintainer>"
42 , (init {- strip trailing newline-}
43 . unlines
44 . map (\l -> if l `elem` ["<longdescription>", "</longdescription>"]
45 then "\t" ++ l -- leading/trailing lines
46 else "\t\t" ++ l -- description itself
47 )
48 . lines
49 . showElement
50 . unode "longdescription"
51 . ("\n" ++) -- prepend newline to separate form <longdescription>
52 . (++ "\n") -- append newline
53 ) long_description
54 , "</pkgmetadata>"
55 ]
Something went wrong with that request. Please try again.