report_error )
import TSN.DbImport ( DbImport(..), ImportResult(..) )
import qualified TSN.XML.AutoRacingSchedule as AutoRacingSchedule (
+ dtd,
pickle_message )
-import qualified TSN.XML.Heartbeat as Heartbeat ( verify )
-import qualified TSN.XML.Injuries as Injuries ( pickle_message )
-import qualified TSN.XML.InjuriesDetail as InjuriesDetail ( pickle_message )
-import qualified TSN.XML.News as News ( pickle_message )
-import qualified TSN.XML.Odds as Odds ( pickle_message )
-import qualified TSN.XML.Scores as Scores ( pickle_message )
-import qualified TSN.XML.Weather as Weather ( pickle_message )
+import qualified TSN.XML.Heartbeat as Heartbeat ( dtd, verify )
+import qualified TSN.XML.Injuries as Injuries ( dtd, pickle_message )
+import qualified TSN.XML.InjuriesDetail as InjuriesDetail (
+ dtd,
+ pickle_message )
+import qualified TSN.XML.News as News ( dtd, pickle_message )
+import qualified TSN.XML.Odds as Odds ( dtd, pickle_message )
+import qualified TSN.XML.Scores as Scores ( dtd, pickle_message )
+import qualified TSN.XML.Weather as Weather ( dtd, pickle_message )
import Xml ( DtdName(..), parse_opts )
import_with_dtd (DtdName dtd,xml)
-- We special-case the heartbeat so it doesn't have to run in
-- the database monad.
- | dtd == "Heartbeat.dtd" = Heartbeat.verify xml
+ | dtd == Heartbeat.dtd = Heartbeat.verify xml
| otherwise =
-- We need NoMonomorphismRestriction here.
if backend cfg == Postgres
else withSqliteConn cs $ runDbConn importer
where
-- | Pull the real connection String out of the configuration.
+ --
cs :: String
cs = get_connection_string $ connection_string cfg
-- | Convenience; we use this everywhere below in 'importer'.
+ --
migrate_and_import m = dbmigrate m >> dbimport m
importer
- | dtd == "Auto_Racing_Schedule_XML.dtd" = do
+ | dtd == AutoRacingSchedule.dtd = do
let m = unpickleDoc AutoRacingSchedule.pickle_message xml
- let errmsg = "Could not unpickle Auto_Racing_Schedule_XML."
maybe (return $ ImportFailed errmsg) migrate_and_import m
- | dtd == "injuriesxml.dtd" = do
+ | dtd == Injuries.dtd = do
let m = unpickleDoc Injuries.pickle_message xml
- let errmsg = "Could not unpickle injuriesxml."
maybe (return $ ImportFailed errmsg) migrate_and_import m
- | dtd == "Injuries_Detail_XML.dtd" = do
+ | dtd == InjuriesDetail.dtd = do
let m = unpickleDoc InjuriesDetail.pickle_message xml
- let errmsg = "Could not unpickle Injuries_Detail_XML."
maybe (return $ ImportFailed errmsg) migrate_and_import m
- | dtd == "newsxml.dtd" = do
+ | dtd == News.dtd = do
let m = unpickleDoc News.pickle_message xml
- let errmsg = "Could not unpickle newsxml."
maybe (return $ ImportFailed errmsg) migrate_and_import m
- | dtd == "Odds_XML.dtd" = do
+ | dtd == Odds.dtd = do
let m = unpickleDoc Odds.pickle_message xml
- let errmsg = "Could not unpickle Odds_XML."
maybe (return $ ImportFailed errmsg) migrate_and_import m
- | dtd == "weatherxml.dtd" = do
+ | dtd == Scores.dtd = do
+ let m = unpickleDoc Scores.pickle_message xml
+ maybe (return $ ImportFailed errmsg) migrate_and_import m
+
+ | dtd == Weather.dtd = do
let m = unpickleDoc Weather.pickle_message xml
- let errmsg = "Could not unpickle weatherxml."
maybe (return $ ImportFailed errmsg) migrate_and_import m
| otherwise = do
"Unrecognized DTD in " ++ path ++ ": " ++ dtd ++ "."
return $ ImportUnsupported infomsg
+ where
+ errmsg = "Could not unpickle " ++ dtd ++ "."
+
-- | Entry point of the program. It twiddles some knobs for
-- configuration options and then calls 'import_file' on each XML