import Development.Hake import Development.Hake.FunSetIO import System.Cmd (rawSystem) import System.IO (stdout, hFlush) import System.Directory (setCurrentDirectory) import Text.RegexPR (getbrsRegexPR) targets = [ index, tutorial ] getV :: String -> String -> String getV k = (!! 1) . getbrsRegexPR ("(?i)^" ++ k ++ "\\s*:\\s*(\\S+)\\s*$") index = "index.xhtml" projName = "ehaskell" indexDepFiles = [ "version_file", "XMLTools.hs" ] tutorial = "short_tutorial.xhtml" tutorialDepFiles = [ "XMLTools.hs", "short_tutorial/contents" ] main = do addrs <- readFile "../address_file" let address = getV "address" addrs directory = getV "document_directory" addrs user_name = getV "user" addrs my_home_version <- fmap (getV "version") $ readFile "../ehaskell.cabal" let ehsTgz = "../dist/ehaskell-" ++ my_home_version ++ ".tar.gz" hake $ [ dflt $ targets ++ [ "short_tutorial" ] , rule "" ".ehs" $ \t (s:_) -> rawSystemE [ "ehs", s, "-o", t ] , file [ "upload" ] (targets ++ [ ehsTgz ] ++ [ "short_tutorial_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" ] , task "short_tutorial" $ do putStrLn "cd short_tutorial" setCurrentDirectory "short_tutorial" rawSystemE [ "hake" ] setCurrentDirectory ".." return ExitSuccess , task "short_tutorial_upload" $ do putStrLn "cd short_tutorial" setCurrentDirectory "short_tutorial" rawSystemE [ "hake", "upload" ] setCurrentDirectory ".." return ExitSuccess ] `addDeps` [ (index, ehsTgz:indexDepFiles) , (tutorial, tutorialDepFiles) ] getPsswd :: IO String getPsswd = do putStr "Passwd: " hFlush stdout rawSystem "stty" [ "-echo" ] pass <- getLine rawSystem "stty" [ "echo" ] putStrLn "" return pass