git.iko.soy/typeable/pandoc
on master help sign in
Create reference files from unpacked archives with helper program
commitd744b83b61bc635419339b73b687b9280ee757fc authorNikolay Yakimov <root@livid.pp.ru> dateWed 18 Mar 2015, 22:33 (12 years ago) parent1710c4b
3 files changed+56−5
Setup.hs+21−5 data/make-reference-files.hs+26 pandoc.cabal+9
Setup.hs+21−5
@@ -22,7 +22,10 @@ import Distribution.PackageDescription (PackageDescription(..), Executable(..))
2222import System.Process ( rawSystem )
2323import System.FilePath ( (</>) )
2424import System.Directory ( findExecutable )
25−import Distribution.Simple.Utils (info)
25+import Distribution.Simple.Utils (info, rawSystemExit)
26+import Distribution.Simple.Setup
27+import Distribution.Simple.LocalBuildInfo
28+import Distribution.Verbosity
2629
2730main :: IO ()
2831main = defaultMainWithHooks $ simpleUserHooks {
@@ -30,12 +33,15 @@ main = defaultMainWithHooks $ simpleUserHooks {
3033 hookedPreProcessors = [ppBlobSuffixHandler]
3134 -- ensure that make-pandoc-man-pages doesn't get installed to bindir
3235 , copyHook = \pkgdescr ->
33− (copyHook simpleUserHooks) pkgdescr{ executables =
34− [x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
36+ copyHook simpleUserHooks pkgdescr{ executables =
37+ [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
3538 , instHook = \pkgdescr ->
36− (instHook simpleUserHooks) pkgdescr{ executables =
37− [x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
39+ instHook simpleUserHooks pkgdescr{ executables =
40+ [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
41+ , postBuild = makeReferenceFiles
3842 }
43+ where
44+ noInstall = ["make-pandoc-man-pages","make-reference-files"]
3945
4046ppBlobSuffixHandler :: PPSuffixHandler
4147ppBlobSuffixHandler = ("hsb", \_ _ ->
@@ -49,3 +55,13 @@ ppBlobSuffixHandler = ("hsb", \_ _ ->
4955 Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
5056 return ()
5157 })
58+
59+makeReferenceFiles :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
60+makeReferenceFiles _ bf _ LocalBuildInfo{buildDir=buildDir}
61+ = mapM_
62+ (rawSystemExit verbosity progPath . return)
63+ referenceFormats
64+ where
65+ verbosity = fromFlagOrDefault normal $ buildVerbosity bf
66+ progPath = buildDir </> "make-reference-files" </> "make-reference-files"
67+ referenceFormats = ["docx", "odt"]
data/make-reference-files.hsnew file+26
@@ -0,0 +1,26 @@
1+import System.Environment
2+import System.Directory
3+import Codec.Archive.Zip
4+import qualified Data.ByteString.Lazy as BS
5+import qualified Control.Exception as E
6+import System.IO.Error (isDoesNotExistError)
7+
8+mkzip :: String -> IO ()
9+mkzip fmt = do
10+ let dir = "data/"++fmt
11+ output = "data/reference."++fmt
12+ cd <- getCurrentDirectory
13+ setCurrentDirectory dir
14+ archive <- addFilesToArchive [OptRecursive] emptyArchive ["."]
15+ setCurrentDirectory cd
16+ removeIfExists output
17+ BS.writeFile output $ fromArchive archive
18+
19+removeIfExists :: FilePath -> IO ()
20+removeIfExists fileName = removeFile fileName `E.catch` handleExists
21+ where handleExists e
22+ | isDoesNotExistError e = return ()
23+ | otherwise = E.throwIO e
24+
25+main :: IO ()
26+main = getArgs >>= mkzip . (!!0)
pandoc.cabal+9
@@ -418,6 +418,15 @@ Executable make-pandoc-man-pages
418418 else
419419 Buildable: False
420420
421+Executable make-reference-files
422+ Main-Is: make-reference-files.hs
423+ Hs-Source-Dirs: data
424+ Build-Depends: zip-archive >= 0.2.3.4 && < 0.3,
425+ base >= 4.2 && < 5,
426+ directory >= 1 && < 1.3,
427+ bytestring >= 0.9 && < 0.11
428+ Default-Language: Haskell2010
429+
421430Test-Suite test-pandoc
422431 Type: exitcode-stdio-1.0
423432 Main-Is: test-pandoc.hs