Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 40 lines (32 sloc) 1.194 kB
3d054de @trofi Added forgotten Util.hs for 'repository location discovery' patch
trofi authored
1 {-|
2 Author : Sergei Trofimovich <slyfox@inbox.ru>
3 Stability : experimental
4 Portability : haskell98
5
6 Ungrouped utilitary stuff lays here until someone finds better place for it :]
7 -}
8
9 module Util
10 ( run_cmd -- :: String -> IO (Maybe String)
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
11 , split -- :: (a -> Bool) -> [a] -> [[a]]
3d054de @trofi Added forgotten Util.hs for 'repository location discovery' patch
trofi authored
12 ) where
13
14 import System.IO
15 import System.Process
e203713 @trofi added support for nonstandard PORTDIR(emerge) location::gentoo(paludis)
trofi authored
16 import System.Exit (ExitCode(..))
3d054de @trofi Added forgotten Util.hs for 'repository location discovery' patch
trofi authored
17
18 -- 'run_cmd' executes command and returns it's standard output
19 -- as 'String'.
20
21 run_cmd :: String -> IO (Maybe String)
e203713 @trofi added support for nonstandard PORTDIR(emerge) location::gentoo(paludis)
trofi authored
22 run_cmd cmd = do (hI, hO, hE, hProcess) <- runInteractiveCommand cmd
23 hClose hI
3d054de @trofi Added forgotten Util.hs for 'repository location discovery' patch
trofi authored
24 output <- hGetContents hO
e203713 @trofi added support for nonstandard PORTDIR(emerge) location::gentoo(paludis)
trofi authored
25 errors <- hGetContents hE -- TODO: propagate error to caller
26 length output `seq` hClose hO
27 length errors `seq` hClose hE
28
29 exitCode <- waitForProcess hProcess
30 return $ if (output == "" || exitCode /= ExitSuccess)
3d054de @trofi Added forgotten Util.hs for 'repository location discovery' patch
trofi authored
31 then Nothing
32 else Just output
30c4943 @trofi Main.hs: add support for forcing certain flags in .cabal file
trofi authored
33
34 split :: Eq a => (a -> Bool) -> [a] -> [[a]]
35 split _ [] = []
36 split p xs =
37 case break p xs of
38 (l, []) -> [l]
39 (l, _:r) -> l: split p r
Something went wrong with that request. Please try again.