propellor-5.3.3: property-based host configuration management in haskell

Safe Haskell | None
Language | Haskell98

Propellor.Utilities

Description

Re-exports some of propellor's internal utility modules.

These are used in the implementation of propellor, including some of its properties. However, there is no API stability; any of these can change or be removed without a major version number increase.

Use outside propellor at your own risk.

Synopsis

- read :: Read a => String -> a
- head :: [a] -> a
- tail :: [a] -> [a]
- init :: [a] -> [a]
- last :: [a] -> a
- readish :: Read a => String -> Maybe a
- headMaybe :: [a] -> Maybe a
- lastMaybe :: [a] -> Maybe a
- beginning :: [a] -> [a]
- end :: [a] -> [a]
- data CreateProcess :: * = CreateProcess {
  - cmdspec :: CmdSpec
  - cwd :: Maybe FilePath
  - env :: Maybe [(String, String)]
  - std_in :: StdStream
  - std_out :: StdStream
  - std_err :: StdStream
  - close_fds :: Bool
  - create_group :: Bool
  - delegate_ctlc :: Bool
  - detach_console :: Bool
  - create_new_console :: Bool
  - new_session :: Bool
  - child_group :: Maybe GroupID
  - child_user :: Maybe UserID
  }
- data StdHandle
  - = StdinHandle
  - | StdoutHandle
  - | StderrHandle
- readProcess :: FilePath -> [String] -> IO String
- readProcess' :: CreateProcess -> IO String
- readProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> IO String
- writeReadProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> Maybe (Handle -> IO ()) -> Maybe (Handle -> IO ()) -> IO String
- forceSuccessProcess :: CreateProcess -> ProcessHandle -> IO ()
- forceSuccessProcess' :: CreateProcess -> ExitCode -> IO ()
- checkSuccessProcess :: ProcessHandle -> IO Bool
- ignoreFailureProcess :: ProcessHandle -> IO Bool
- createProcessSuccess :: CreateProcessRunner
- createProcessChecked :: (ProcessHandle -> IO b) -> CreateProcessRunner
- createBackgroundProcess :: CreateProcessRunner
- processTranscript :: String -> [String] -> Maybe String -> IO (String, Bool)
- processTranscript' :: CreateProcess -> Maybe String -> IO (String, Bool)
- withHandle :: StdHandle -> CreateProcessRunner -> CreateProcess -> (Handle -> IO a) -> IO a
- withIOHandles :: CreateProcessRunner -> CreateProcess -> ((Handle, Handle) -> IO a) -> IO a
- withOEHandles :: CreateProcessRunner -> CreateProcess -> ((Handle, Handle) -> IO a) -> IO a
- withQuietOutput :: CreateProcessRunner -> CreateProcess -> IO ()
- feedWithQuietOutput :: CreateProcessRunner -> CreateProcess -> (Handle -> IO a) -> IO a
- createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
- waitForProcess :: ProcessHandle -> IO ExitCode
- startInteractiveProcess :: FilePath -> [String] -> Maybe [(String, String)] -> IO (ProcessHandle, Handle, Handle)
- stdinHandle :: HandleExtractor
- stdoutHandle :: HandleExtractor
- stderrHandle :: HandleExtractor
- ioHandles :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> (Handle, Handle)
- processHandle :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> ProcessHandle
- devNull :: FilePath
- giveup :: [Char] -> a
- catchBoolIO :: MonadCatch m => m Bool -> m Bool
- catchMaybeIO :: MonadCatch m => m a -> m (Maybe a)
- catchDefaultIO :: MonadCatch m => a -> m a -> m a
- catchMsgIO :: MonadCatch m => m a -> m (Either String a)
- catchIO :: MonadCatch m => m a -> (IOException -> m a) -> m a
- tryIO :: MonadCatch m => m a -> m (Either IOException a)
- bracketIO :: (MonadMask m, MonadIO m) => IO v -> (v -> IO b) -> (v -> m a) -> m a
- catchNonAsync :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- tryNonAsync :: MonadCatch m => m a -> m (Either SomeException a)
- tryWhenExists :: MonadCatch m => m a -> m (Maybe a)
- catchIOErrorType :: MonadCatch m => IOErrorType -> (IOException -> m a) -> m a -> m a
- data IOErrorType :: *
  - = AlreadyExists
  - | NoSuchThing
  - | ResourceBusy
  - | ResourceExhausted
  - | EOF
  - | IllegalOperation
  - | PermissionDenied
  - | UserError
  - | UnsatisfiedConstraints
  - | SystemError
  - | ProtocolError
  - | OtherError
  - | InvalidArgument
  - | InappropriateType
  - | HardwareFault
  - | UnsupportedOperation
  - | TimeExpired
  - | ResourceVanished
  - | Interrupted
- catchPermissionDenied :: MonadCatch m => (IOException -> m a) -> m a -> m a
- getEnv :: String -> IO (Maybe String)
- getEnvDefault :: String -> String -> IO String
- getEnvironment :: IO [(String, String)]
- setEnv :: String -> String -> Bool -> IO ()
- unsetEnv :: String -> IO ()
- addEntry :: Eq k => k -> v -> [(k, v)] -> [(k, v)]
- addEntries :: Eq k => [(k, v)] -> [(k, v)] -> [(k, v)]
- delEntry :: Eq k => k -> [(k, v)] -> [(k, v)]
- dirCruft :: FilePath -> Bool
- fsCruft :: FilePath -> Bool
- dirContents :: FilePath -> IO [FilePath]
- dirContentsRecursive :: FilePath -> IO [FilePath]
- dirContentsRecursiveSkipping :: (FilePath -> Bool) -> Bool -> FilePath -> IO [FilePath]
- dirTreeRecursiveSkipping :: (FilePath -> Bool) -> FilePath -> IO [FilePath]
- moveFile :: FilePath -> FilePath -> IO ()
- nukeFile :: FilePath -> IO ()
- data DirectoryHandle = DirectoryHandle IsOpen DirStream
- type IsOpen = MVar ()
- openDirectory :: FilePath -> IO DirectoryHandle
- closeDirectory :: DirectoryHandle -> IO ()
- readDirectory :: DirectoryHandle -> IO (Maybe FilePath)
- isDirectoryEmpty :: FilePath -> IO Bool
- isUnpopulated :: FilePath -> IO Bool
- testDirectory :: FilePath -> (FilePath -> Bool) -> IO Bool
- type Template = String
- viaTmp :: (MonadMask m, MonadIO m) => (FilePath -> String -> m ()) -> FilePath -> String -> m ()
- withTmpFile :: (MonadIO m, MonadMask m) => Template -> (FilePath -> Handle -> m a) -> m a
- withTmpFileIn :: (MonadIO m, MonadMask m) => FilePath -> Template -> (FilePath -> Handle -> m a) -> m a
- withTmpDir :: (MonadMask m, MonadIO m) => Template -> (FilePath -> m a) -> m a
- withTmpDirIn :: (MonadMask m, MonadIO m) => FilePath -> Template -> (FilePath -> m a) -> m a
- removeTmpDir :: MonadIO m => FilePath -> m ()
- relatedTemplate :: FilePath -> FilePath
- firstM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
- getM :: Monad m => (a -> m (Maybe b)) -> [a] -> m (Maybe b)
- anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
- allM :: Monad m => (a -> m Bool) -> [a] -> m Bool
- untilTrue :: Monad m => [a] -> (a -> m Bool) -> m Bool
- ifM :: Monad m => m Bool -> (m a, m a) -> m a
- (<||>) :: Monad m => m Bool -> m Bool -> m Bool
- (<&&>) :: Monad m => m Bool -> m Bool -> m Bool
- observe :: Monad m => (a -> m b) -> m a -> m a
- after :: Monad m => m b -> m a -> m a
- noop :: Monad m => m ()
- hGetContentsStrict :: Handle -> IO String
- readFileStrict :: FilePath -> IO String
- separate :: (a -> Bool) -> [a] -> ([a], [a])
- firstLine :: String -> String
- segment :: (a -> Bool) -> [a] -> [[a]]
- prop_segment_regressionTest :: Bool
- segmentDelim :: (a -> Bool) -> [a] -> [[a]]
- massReplace :: [(String, String)] -> String -> String
- hGetSomeString :: Handle -> Int -> IO String
- reapZombies :: IO ()
- exitBool :: Bool -> IO a

# Documentation

read :: Read a => String -> a Source #

head :: [a] -> a Source #

tail :: [a] -> [a] Source #

init :: [a] -> [a] Source #

last :: [a] -> a Source #

readish :: Read a => String -> Maybe a Source #

headMaybe :: [a] -> Maybe a Source #

lastMaybe :: [a] -> Maybe a Source #

beginning :: [a] -> [a] Source #

end :: [a] -> [a] Source #

data CreateProcess :: * #

Constructors

CreateProcess |

Fields

- cmdspec :: CmdSpec
- cwd :: Maybe FilePath
- env :: Maybe [(String, String)]
- std_in :: StdStream
- std_out :: StdStream
- std_err :: StdStream
- close_fds :: Bool
- create_group :: Bool
- delegate_ctlc :: Bool
- detach_console :: Bool
- create_new_console :: Bool
- new_session :: Bool
- child_group :: Maybe GroupID
- child_user :: Maybe UserID

Instances

Eq CreateProcess |
Methods (==) :: CreateProcess -> CreateProcess -> Bool (/=) :: CreateProcess -> CreateProcess -> Bool
Show CreateProcess |
Methods showsPrec :: Int -> CreateProcess -> ShowS show :: CreateProcess -> String showList :: [CreateProcess] -> ShowS

data StdHandle Source #

Constructors

StdinHandle |
StdoutHandle |
StderrHandle |

Instances

Eq StdHandle Source # |
Methods (==) :: StdHandle -> StdHandle -> Bool (/=) :: StdHandle -> StdHandle -> Bool

readProcess :: FilePath -> [String] -> IO String Source #

Normally, when reading from a process, it does not need to be fed any standard input.

readProcess' :: CreateProcess -> IO String Source #

readProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> IO String Source #

writeReadProcessEnv :: FilePath -> [String] -> Maybe [(String, String)] -> Maybe (Handle -> IO ()) -> Maybe (Handle -> IO ()) -> IO String Source #

Runs an action to write to a process on its stdin, returns its output, and also allows specifying the environment.

forceSuccessProcess :: CreateProcess -> ProcessHandle -> IO () Source #

Waits for a ProcessHandle, and throws an IOError if the process did not exit successfully.

forceSuccessProcess' :: CreateProcess -> ExitCode -> IO () Source #

checkSuccessProcess :: ProcessHandle -> IO Bool Source #

Waits for a ProcessHandle and returns True if it exited successfully. Note that using this with createProcessChecked will throw away the Bool, and is only useful to ignore the exit code of a process, while still waiting for it. -}

ignoreFailureProcess :: ProcessHandle -> IO Bool Source #

createProcessSuccess :: CreateProcessRunner Source #

Runs createProcess, then an action on its handles, and then forceSuccessProcess.

createProcessChecked :: (ProcessHandle -> IO b) -> CreateProcessRunner Source #

Runs createProcess, then an action on its handles, and then a checker action on its exit code, which must wait for the process.

createBackgroundProcess :: CreateProcessRunner Source #

Leaves the process running, suitable for lazy streaming. Note: Zombies will result, and must be waited on.

processTranscript :: String -> [String] -> Maybe String -> IO (String, Bool) Source #

Runs a process, optionally feeding it some input, and returns a transcript combining its stdout and stderr, and whether it succeeded or failed.

processTranscript' :: CreateProcess -> Maybe String -> IO (String, Bool) Source #

withHandle :: StdHandle -> CreateProcessRunner -> CreateProcess -> (Handle -> IO a) -> IO a Source #

Runs a CreateProcessRunner, on a CreateProcess structure, that is adjusted to pipe only from/to a single StdHandle, and passes the resulting Handle to an action.

withIOHandles :: CreateProcessRunner -> CreateProcess -> ((Handle, Handle) -> IO a) -> IO a Source #

Like withHandle, but passes (stdin, stdout) handles to the action.

withOEHandles :: CreateProcessRunner -> CreateProcess -> ((Handle, Handle) -> IO a) -> IO a Source #

Like withHandle, but passes (stdout, stderr) handles to the action.

withQuietOutput :: CreateProcessRunner -> CreateProcess -> IO () Source #

Forces the CreateProcessRunner to run quietly; both stdout and stderr are discarded.

feedWithQuietOutput :: CreateProcessRunner -> CreateProcess -> (Handle -> IO a) -> IO a Source #

Stdout and stderr are discarded, while the process is fed stdin from the handle.

createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source #

Wrapper around `createProcess` that does debug logging.

waitForProcess :: ProcessHandle -> IO ExitCode Source #

Wrapper around `waitForProcess` that does debug logging.

startInteractiveProcess :: FilePath -> [String] -> Maybe [(String, String)] -> IO (ProcessHandle, Handle, Handle) Source #

Starts an interactive process. Unlike runInteractiveProcess in System.Process, stderr is inherited.

stdinHandle :: HandleExtractor Source #

stdoutHandle :: HandleExtractor Source #

stderrHandle :: HandleExtractor Source #

ioHandles :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> (Handle, Handle) Source #

processHandle :: (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) -> ProcessHandle Source #

devNull :: FilePath Source #

giveup :: [Char] -> a Source #

catchBoolIO :: MonadCatch m => m Bool -> m Bool Source #

catchMaybeIO :: MonadCatch m => m a -> m (Maybe a) Source #

catchDefaultIO :: MonadCatch m => a -> m a -> m a Source #

catchMsgIO :: MonadCatch m => m a -> m (Either String a) Source #

catchIO :: MonadCatch m => m a -> (IOException -> m a) -> m a Source #

tryIO :: MonadCatch m => m a -> m (Either IOException a) Source #

bracketIO :: (MonadMask m, MonadIO m) => IO v -> (v -> IO b) -> (v -> m a) -> m a Source #

catchNonAsync :: MonadCatch m => m a -> (SomeException -> m a) -> m a Source #

tryNonAsync :: MonadCatch m => m a -> m (Either SomeException a) Source #

tryWhenExists :: MonadCatch m => m a -> m (Maybe a) Source #

catchIOErrorType :: MonadCatch m => IOErrorType -> (IOException -> m a) -> m a -> m a Source #

data IOErrorType :: * #

Constructors

AlreadyExists |
NoSuchThing |
ResourceBusy |
ResourceExhausted |
EOF |
IllegalOperation |
PermissionDenied |
UserError |
UnsatisfiedConstraints |
SystemError |
ProtocolError |
OtherError |
InvalidArgument |
InappropriateType |
HardwareFault |
UnsupportedOperation |
TimeExpired |
ResourceVanished |
Interrupted |

Instances

Eq IOErrorType |
Methods (==) :: IOErrorType -> IOErrorType -> Bool (/=) :: IOErrorType -> IOErrorType -> Bool
Show IOErrorType |
Methods showsPrec :: Int -> IOErrorType -> ShowS show :: IOErrorType -> String showList :: [IOErrorType] -> ShowS

catchPermissionDenied :: MonadCatch m => (IOException -> m a) -> m a -> m a Source #

getEnv :: String -> IO (Maybe String) Source #

getEnvDefault :: String -> String -> IO String Source #

getEnvironment :: IO [(String, String)] Source #

setEnv :: String -> String -> Bool -> IO () Source #

unsetEnv :: String -> IO () Source #

addEntry :: Eq k => k -> v -> [(k, v)] -> [(k, v)] Source #

addEntries :: Eq k => [(k, v)] -> [(k, v)] -> [(k, v)] Source #

delEntry :: Eq k => k -> [(k, v)] -> [(k, v)] Source #

dirCruft :: FilePath -> Bool Source #

fsCruft :: FilePath -> Bool Source #

dirContents :: FilePath -> IO [FilePath] Source #

dirContentsRecursive :: FilePath -> IO [FilePath] Source #

dirContentsRecursiveSkipping :: (FilePath -> Bool) -> Bool -> FilePath -> IO [FilePath] Source #

dirTreeRecursiveSkipping :: (FilePath -> Bool) -> FilePath -> IO [FilePath] Source #

moveFile :: FilePath -> FilePath -> IO () Source #

nukeFile :: FilePath -> IO () Source #

data DirectoryHandle Source #

Constructors

DirectoryHandle IsOpen DirStream |

type IsOpen = MVar () Source #

openDirectory :: FilePath -> IO DirectoryHandle Source #

closeDirectory :: DirectoryHandle -> IO () Source #

readDirectory :: DirectoryHandle -> IO (Maybe FilePath) Source #

Reads the next entry from the handle. Once the end of the directory is reached, returns Nothing and automatically closes the handle.

isDirectoryEmpty :: FilePath -> IO Bool Source #

isUnpopulated :: FilePath -> IO Bool Source #

True if the directory does not exist or contains nothing. Ignores "lost+found" which can exist in an empty filesystem.

testDirectory :: FilePath -> (FilePath -> Bool) -> IO Bool Source #

Run test on entries found in directory, return False as soon as the test returns False, else return True. Throws exception if directory does not exist.

type Template = String Source #

viaTmp :: (MonadMask m, MonadIO m) => (FilePath -> String -> m ()) -> FilePath -> String -> m () Source #

withTmpFile :: (MonadIO m, MonadMask m) => Template -> (FilePath -> Handle -> m a) -> m a Source #

withTmpFileIn :: (MonadIO m, MonadMask m) => FilePath -> Template -> (FilePath -> Handle -> m a) -> m a Source #

withTmpDir :: (MonadMask m, MonadIO m) => Template -> (FilePath -> m a) -> m a Source #

withTmpDirIn :: (MonadMask m, MonadIO m) => FilePath -> Template -> (FilePath -> m a) -> m a Source #

removeTmpDir :: MonadIO m => FilePath -> m () Source #

relatedTemplate :: FilePath -> FilePath Source #

firstM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) Source #

getM :: Monad m => (a -> m (Maybe b)) -> [a] -> m (Maybe b) Source #

anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool Source #

allM :: Monad m => (a -> m Bool) -> [a] -> m Bool Source #

untilTrue :: Monad m => [a] -> (a -> m Bool) -> m Bool Source #

ifM :: Monad m => m Bool -> (m a, m a) -> m a Source #

(<||>) :: Monad m => m Bool -> m Bool -> m Bool infixr 2 Source #

(<&&>) :: Monad m => m Bool -> m Bool -> m Bool infixr 3 Source #

observe :: Monad m => (a -> m b) -> m a -> m a Source #

after :: Monad m => m b -> m a -> m a Source #

noop :: Monad m => m () Source #

hGetContentsStrict :: Handle -> IO String Source #

readFileStrict :: FilePath -> IO String Source #

separate :: (a -> Bool) -> [a] -> ([a], [a]) Source #

firstLine :: String -> String Source #

segment :: (a -> Bool) -> [a] -> [[a]] Source #

prop_segment_regressionTest :: Bool Source #

segmentDelim :: (a -> Bool) -> [a] -> [[a]] Source #

massReplace :: [(String, String)] -> String -> String Source #

hGetSomeString :: Handle -> Int -> IO String Source #

reapZombies :: IO () Source #

exitBool :: Bool -> IO a Source #