debian-3.35: utils/Report.hs
{-# OPTIONS_GHC -fglasgow-exts #-}
module Main where
import Control.Monad
import Data.List
import Debian.Apt.Methods
import Debian.Report
import Debian.Sources
import Extra.Exit
import System.Environment
import Text.XML.HaXml
import Text.XML.HaXml.Pretty (document)
import Text.PrettyPrint.HughesPJ
import System.IO
-- * main
main :: IO ()
main =
do (sourcesAFP, sourcesBFP) <- parseArgs
let arch = "i386" -- not actually used for anything right now, could be when binary package list is enabled
cacheDir = "." -- FIXME: replace with tempdir later
sourcesA <- liftM parseSourcesList $ readFile sourcesAFP
sourcesB <- liftM parseSourcesList $ readFile sourcesBFP
trumpMap <- trumped (fetch emptyFetchCallbacks []) cacheDir arch sourcesA sourcesB
print (showXML "trump.xsl" (trumpedXML trumpMap))
where
showXML :: String -> CFilter -> Doc
showXML styleSheet = document . mkDocument styleSheet . cfilterToElem
-- cliff says this is broken with regards to cdata
cfilterToElem :: CFilter -> Element
cfilterToElem f = case f (CString False "") of
[CElem e] -> xmlEscape stdXmlEscaper e
[] -> error "RSS produced no output"
_ -> error "RSS produced more than one output"
-- <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
mkDocument :: String -> Element -> Document
mkDocument styleSheet elem =
let xmlDecl = XMLDecl "1.0" (Just (EncodingDecl "utf-8")) (Just True)
prolog = Prolog (Just xmlDecl) [] Nothing [PI ("xml-stylesheet","type=\"text/xsl\" href=\""++styleSheet++"\"")]
symTable = []
in
Document prolog [] elem []
-- * command-line helper functions
helpText :: String -> Doc
helpText progName =
(text "Usage:" <+> text progName <+> text "<old sources.list>" <+> text "<new sources.list>"$+$
text [] $+$
(fsep $ map text $ words $ "Find all the packages referenced by the second sources.list which trump packages find in the first sources.list.")
)
parseArgs :: IO (String, String)
parseArgs =
do args <- getArgs
case args of
[dista, distb] -> return (dista, distb)
_ -> exitWithHelp helpText