@@ -30,7 +30,7 @@ Functions for producing an ODT file from OpenDocument XML.
31module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
31module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
32import Text.Pandoc.Shared ( contentsOf )
32import Text.Pandoc.Shared ( contentsOf )
33−import Data.Maybe ( fromJust )
33+import Data.Maybe ( fromJust, isJust )
34import Data.List ( partition, intersperse )
34import Data.List ( partition, intersperse )
35import Prelude hiding ( writeFile, readFile )
35import Prelude hiding ( writeFile, readFile )
36import System.IO.UTF8
36import System.IO.UTF8
@@ -44,6 +44,7 @@ import Text.XML.Light.Cursor
44import Text.Pandoc.Shared ( withTempDir )
44import Text.Pandoc.Shared ( withTempDir )
45import Network.URI ( isURI )
45import Network.URI ( isURI )
46import qualified Data.ByteString.Char8 as B ( writeFile, pack )
46import qualified Data.ByteString.Char8 as B ( writeFile, pack )
47+import Control.Monad ( unless )
48-- | Produce an ODT file from OpenDocument XML.
49-- | Produce an ODT file from OpenDocument XML.
49saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
50saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
@@ -53,11 +54,8 @@ saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
53saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
54saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
54 let zipCmd = "zip"
55 let zipCmd = "zip"
55 -- check for zip in path:
56 -- check for zip in path:
56− maybeZipPath <- findExecutable zipCmd
57+ findExecutable zipCmd >>= \v -> unless (isJust v) $ error $ "The '" ++ zipCmd ++
57− let zipPath = case maybeZipPath of
59− Nothing -> error $ "The '" ++ zipCmd ++ "' command, which is needed to build an ODT file, " ++
58+ "' command, which is needed to build an ODT file, was not found.\n" ++
60− "was not found.\n" ++
61 "It can be obtained from http://www.info-zip.org/Zip.html\n" ++
59 "It can be obtained from http://www.info-zip.org/Zip.html\n" ++
62 "Debian (and Debian-based) linux: apt-get install zip\n" ++
60 "Debian (and Debian-based) linux: apt-get install zip\n" ++
63 "Windows: See http://gnuwin32.sourceforge.net/packages/zip.htm"
61 "Windows: See http://gnuwin32.sourceforge.net/packages/zip.htm"
@@ -70,7 +68,7 @@ saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
70 writeFile (tempDir </> "content.xml") xml'
68 writeFile (tempDir </> "content.xml") xml'
71 oldDir <- getCurrentDirectory
69 oldDir <- getCurrentDirectory
72 setCurrentDirectory tempDir
70 setCurrentDirectory tempDir
73− let zipCmdLine = zipPath ++ " -9 -q -r " ++ tempODT ++ " " ++ "content.xml Pictures"
71+ let zipCmdLine = "zip -9 -q -r " ++ tempODT ++ " " ++ "content.xml Pictures"
74 ec <- runCommand zipCmdLine >>= waitForProcess -- this requires compilation with -threaded
72 ec <- runCommand zipCmdLine >>= waitForProcess -- this requires compilation with -threaded
75 setCurrentDirectory oldDir
73 setCurrentDirectory oldDir
76 case ec of
74 case ec of