small updates

This commit is contained in:
Yann Esposito (Yogsototh) 2013-11-21 17:16:47 +01:00
parent 7ca9c497f4
commit 1076958f14
2 changed files with 36 additions and 28 deletions

View file

@ -19,14 +19,16 @@ Darwin)
hobbes "*.cabal" | relaunchCompilation hobbes "*.cabal" | relaunchCompilation
;; ;;
*) # On other Unixes *) # On other Unixes
currenttime=$(date +"%s") tmp=$(date +"%s")
t=$tmp
while true; do while true; do
tmp=$t
t=$(date +"%s")
for fic in {src,test}/**/*.hs(.) *.cabal; do for fic in {src,test}/**/*.hs(.) *.cabal; do
# note to use on OS X, use "stat -f %m $checkfile" instead # note to use on OS X, use "stat -f %m $checkfile" instead
modtime=$(stat --printf %Y $fic) modtime=$(stat --printf %Y $fic)
(( $modtime > $currenttime)) && print $fic (( $modtime > $tmp )) && print $fic
done done
currenttime=$(date +"%s")
sleep 1 sleep 1
done | relaunchCompilation done | relaunchCompilation
;; ;;

View file

@ -3,14 +3,14 @@ module Main where
-- Project name manipulation -- Project name manipulation
import Data.Char (toUpper,toLower,isLetter,isNumber) import Data.Char (toUpper,toLower,isLetter,isNumber)
import Data.List (intersperse,foldl') import Data.List (intersperse)
import Data.List.Split import Data.List.Split
-- Get current year for the License -- Get current year for the License
import Data.Time.Clock import Data.Time.Clock
import Data.Time.Calendar import Data.Time.Calendar
-- Console read write with colors -- Console read write with colors
import System.Console.ANSI import System.Console.ANSI
import System.IO (hFlush, stdout,hPutStrLn, stderr) import System.IO (hFlush, stdout)
-- Hastache -- Hastache
import Data.Data import Data.Data
import Text.Hastache import Text.Hastache
@ -27,6 +27,9 @@ import System.Random
--- Environment variable --- Environment variable
import System.Environment (getEnv) import System.Environment (getEnv)
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Control.Exception
import System.IO.Error
import Control.Monad (guard)
-- Get external file of package -- Get external file of package
import Paths_holy_project import Paths_holy_project
@ -58,18 +61,25 @@ holyError str = do
you "I don't know that!" you "I don't know that!"
putStrLn "[You are thrown over the edge into the volcano]" putStrLn "[You are thrown over the edge into the volcano]"
you "Auuuuuuuuuuuugh" you "Auuuuuuuuuuuugh"
hPutStrLn stderr ('\n':str) error ('\n':str)
ioassert :: Bool -> String -> IO () ioassert :: Bool -> String -> IO ()
ioassert True _ = return () ioassert True _ = return ()
ioassert False str = holyError str ioassert False str = holyError str
safeReadGitConfig :: IO LZ.ByteString
safeReadGitConfig = do
e <- tryJust (guard . isDoesNotExistError)
(do
home <- getEnv "HOME"
LZ.readFile $ home ++ "/.gitconfig" )
return $ either (const (LZ.empty)) id e
-- | Ask, questions and create the initial project -- | Ask, questions and create the initial project
main :: IO () main :: IO ()
main = do main = do
intro intro
home <- getEnv "HOME" gitconfig <- safeReadGitConfig
gitconfig <- readFile $ home ++ "/.gitconfig"
let (name,email) = getNameAndMail gitconfig let (name,email) = getNameAndMail gitconfig
project <- ask "project name" Nothing project <- ask "project name" Nothing
ioassert (checkProjectName project) ioassert (checkProjectName project)
@ -194,27 +204,23 @@ createProject p = do
_ <- system $ "./.cabal-sandbox/bin/test-" ++ (projectName p) _ <- system $ "./.cabal-sandbox/bin/test-" ++ (projectName p)
return () return ()
getNameAndMail :: String -> (Maybe String,Maybe String) getNameAndMail :: LZ.ByteString -> (Maybe String,Maybe String)
getNameAndMail gitConfigContent = (name,email) getNameAndMail gitConfigContent = (selectElem "name",selectElem "email")
where where
conflines :: [[String]] conflines :: [[LZ.ByteString]]
conflines = map words (lines gitConfigContent) conflines = map LZ.words (LZ.lines gitConfigContent)
name :: Maybe String selectElem :: String -> Maybe String
name = foldl' mMerge Nothing (map getName conflines) selectElem elm = msafeHead $
filter (/= Nothing)
(map (getElem elm) conflines)
email :: Maybe String msafeHead :: [Maybe a] -> Maybe a
email = foldl' mMerge Nothing (map getEmail conflines) msafeHead [] = Nothing
msafeHead (x:_) = x
getName :: [String] -> Maybe String getElem :: String -> [LZ.ByteString] -> Maybe String
getName ("name":"=":xs) = Just (concat (intersperse " " xs)) getElem el (n:e:xs) = if (n == (LZ.pack el)) && (e == (LZ.pack "="))
getName _ = Nothing then Just (LZ.unpack (LZ.unwords xs))
else Nothing
getEmail :: [String] -> Maybe String getElem _ _ = Nothing
getEmail ("email":"=":xs) = Just (concat (intersperse " " xs))
getEmail _ = Nothing
mMerge :: Maybe String -> Maybe String -> Maybe String
mMerge Nothing (Just x) = Just x
mMerge Nothing Nothing = Nothing
mMerge (Just x) _ = Just x