import Development.Hake import Development.Hake.FunSetIO import System.Directory (copyFile) import System.Cmd (rawSystem) import System.IO (stdout, hFlush) import Text.RegexPR (getbrsRegexPR) getV :: String -> String -> String getV k = (!! 1) . getbrsRegexPR ( "(?i)^" ++ k ++ "\\s*:\\s*(\\S+)\\s*$" ) targets = [ firstOfAll, explanation, firstSample ] samples = [ firstHelloEhs, secondHelloEhs, threeTimesSayAEhs ] firstOfAll = "first_of_all.xhtml" firstOfAllDepFiles = [ xmlTools ] firstSample = "simple_samples.xhtml" firstHelloEhs = "../samples/hello.ehs" secondHelloEhs = "../samples/hello2.ehs" threeTimesSayAEhs = "../samples/threeTimesSayA.ehs" firstSampleDepFiles = [ xmlTools, firstHelloEhs, secondHelloEhs, threeTimesSayAEhs ] explanation = "short_explanation.xhtml" explanationDepFiles = [ xmlTools ] xmlTools = "XMLTools.hs" projName = "ehaskell/short_tutorial/" main = do addrs <- readFile "../../address_file" let address = getV "address" addrs directory = getV "document_directory" addrs user_name = getV "user" addrs hake $ [ dflt targets , rule "" ".ehs" $ \t (s:_) -> rawSystemE [ "ehs", s, "-o", t ] , file [ xmlTools ] [ "../" ++ xmlTools ] $ \t (s:_) -> copyFile s t >> return ExitSuccess , file [ "upload" ] (targets ++ [ "samples_upload" ] ) $ \_ ss -> do newers <- getNewers "upload_done" ss psswd <- if null newers then return "" else getPsswd mapM (\s -> putStrLn ("uploading " ++ s) >> rawSystem "yjftp" [ "put", s, address ++ directory ++ "/" ++ projName ++ "/", user_name, "-p", psswd ]) newers rawSystemE [ "touch", "upload_done" ] , file [ "samples_upload" ] samples $ \_ ss -> do newers <- getNewers "upload_done" ss psswd <- if null newers then return "" else getPsswd mapM (\s -> putStrLn ("uploading " ++ s) >> rawSystem "yjftp" [ "put", s, address ++ directory ++ "/" ++ projName ++ "/samples/", user_name, "-p", psswd ]) newers rawSystemE [ "touch", "upload_done" ] ] `addDeps` [ (firstOfAll, firstOfAllDepFiles) , (firstSample, firstSampleDepFiles) ] getPsswd :: IO String getPsswd = do putStr "Passwd: " hFlush stdout rawSystem "stty" [ "-echo" ] pass <- getLine rawSystem "stty" [ "echo" ] putStrLn "" return pass