Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 39 lines (33 sloc) 1.271 kb
ae70834 @dmpots Stop using template haskell for config finder
authored
1 module FindConfig(findLocalConfigs, localConfigsFileName) where
2 import Data.List
3 import System.Directory
4 import System.FilePath
5 import System.IO
6
7 findLocalConfigs :: FilePath -> IO ()
8 findLocalConfigs cDir = do
9 fs <- getDirectoryContents cDir
10 putStr "\nLooking for local configuration modules... "
11 let modNames = map dropExtension $ filter (".hs" `isSuffixOf`) fs
12 let imports = map importStmt $ modNames
13 let modules = map importAs $ modNames
14 putStrLn $ "found ("++ (show.length$ modNames)++")"
15 writeToFile (localConfigsFileName cDir) (imports ++ [modulesList modules])
16 where
17 importStmt m = "import qualified "++m++" as " ++importAs m
18 writeToFile fName contents = do
19 h <- openFile fName WriteMode
20 putStrLn $ " writing config manifest to " ++ fName
21 --putStrLn $ unlines contents
22 hPutStr h (unlines contents)
23 hClose h
24
25 modulesList :: [String] -> String
26 modulesList mods = typ ++ lst
27 where
28 typ = "localConfigs :: [RunConfig]\n"
29 lst = "localConfigs = [" ++ (join ", " cfgs) ++ "]"
30 cfgs = map (++".config") mods
31 join s = concat . intersperse s
32
33 importAs :: String -> String
34 importAs modName = modName++"_Config"
35
36 localConfigsFileName :: FilePath -> FilePath
37 localConfigsFileName baseDir = baseDir </> "LocalConfigs.txt"
38
Something went wrong with that request. Please try again.