module System.Rpm.Xml ( executeRpm2Xml ) where
import System.Exit
import System.Process
type QueryTag = String
type QueryTags = [QueryTag]
type Xml = String
executeRpm2Xml :: FilePath
-> IO (Maybe String)
executeRpm2Xml file = do
(statusCode, out, _ ) <- readProcessWithExitCode "rpm" ["-qp", "--qf", queryString queryTags, file] ""
case statusCode of
ExitSuccess -> return (Just $ (wrapRpmXml .tail . init) out)
_ -> return Nothing
queryTags :: QueryTags
queryTags = [ "NAME"
, "BUILDHOST"
, "BUILDTIME"
, "DESCRIPTION"
, "RELEASE"
, "VERSION"
, "SIZE"
, "SUMMARY"
, "URL"
, "ARCH"
, "ARCHIVESIZE"]
queryString :: QueryTags -> String
queryString = quote . concatMap (\x -> "[%{" ++ x ++ ":xml}]")
where quote :: String -> String
quote xs = "\"" ++ xs ++ "\""
wrapRpmXml :: Xml -> Xml
wrapRpmXml xml = "<rpm>" ++ xml ++ "</rpm>"