import Control.Monad ( filterM ) import Data.Char ( toLower ) import Data.Either ( partitionEithers ) import Data.List ( sortBy ) import Data.Ord ( comparing ) import Data.Time ( defaultTimeLocale, formatTime, getCurrentTime , utcToLocalZonedTime ) import System.Directory ( doesDirectoryExist, getDirectoryContents ) import System.Environment ( getArgs ) import System.FilePath import System.IO ( stderr ) import Text.Printf ( hPrintf ) import Projmd.Config import Projmd.Project import Projmd.Template main :: IO () main = do confPath : templatePath : [] <- getArgs conf <- loadConfig confPath let darcsRepoDir' = darcsRepoDir conf dirs <- ((sortBy (comparing (map toLower))) . filter (notExcluded $ excludedProjects conf)) <$> (filterM (\d -> doesDirectoryExist $ darcsRepoDir' d) =<< getDirectoryContents darcsRepoDir') (errors, projects) <- partitionEithers <$> getProjects conf dirs mapM_ logM errors date <- dateFormat "%F %T %Z" templateString <- readFile templatePath let content = producePage templateString date projects putStrLn content notExcluded :: [FilePath] -> String -> Bool notExcluded exclusions dir = not . elem dir $ exclusions {- Get the current date/time as a string in the specified format For format string help, see man 3 strftime -} dateFormat :: String -> IO String dateFormat fmt = formatTime defaultTimeLocale fmt <$> (getCurrentTime >>= utcToLocalZonedTime) {- Output a message with datestamp -} logM :: String -> IO () logM msg = do tstamp <- dateFormat "%F %T" hPrintf stderr "%s> %s\n" tstamp msg