packages feed

HSHHelpers 0.19 → 0.20

raw patch · 5 files changed

+31/−53 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

HSH/Helpers/Email.hs view
@@ -1,10 +1,7 @@-{-# LANGUAGE ScopedTypeVariables #-}- module HSH.Helpers.Email where import HSH import HSH.Helpers.Utils import Text.StringTemplate.Helpers-import System.IO.Error  newtype PureInput = PureInput { unpureinput :: String }   deriving (Read,Show)@@ -19,19 +16,9 @@    This assumes a unixy environment,  -}---mailxEmail :: String -> String -> String -> IO (Either String ())+mailxEmail :: String -> String -> [Char] -> IO (Either String ()) mailxEmail emailBody subject "" = return . Left $ "no email recipient"-mailxEmail emailBody subject recipient = do-  etR <- try $ run $ echo emailBody -|- mailxCommand-  case etR of-    Left e -> return $ Left $ show e-    Right okmsg -> return $ Right okmsg+mailxEmail emailBody subject recipient = tryS $ runIO $ echo emailBody -|- mailxCommand   where mailxCommand = render1 [("subject",subject),("recipient",recipient)]                                "mailx -s \"$subject$\" $recipient$" --t = do-  etR <- mailxEmail "meh" "mah" "moo@gmail.com"-  case etR of-    Left e -> fail $ "error, e: " ++ e-    Right () -> return "cool"
HSH/Helpers/FileManip.hs view
@@ -4,7 +4,6 @@ import System.FilePath (takeDirectory) import qualified Data.ByteString.Char8 as B import HSH-import HSH.Helpers.Utils import Text.StringTemplate.Helpers import HSH.Helpers.UnixUsers @@ -26,7 +25,10 @@ findDirectories :: FilePath -> IO [FilePath] findDirectories d = runStrings $ render1 [("d",d)] "find $d$ -type d" -+runS :: String -> IO String+runS = run+runStrings :: String -> IO [String]+runStrings = ( return . lines =<< ) . run   -- I took this out because I don't like the behavior of doesFileExist when it comes to symlinks -- If  symlink exists, but it's to a directlry, this test is false
HSH/Helpers/Instances.hs view
@@ -4,7 +4,7 @@ import HSH import System.Exit import System.Posix.Process-+import System.Posix.Env instance RunResult (IO (Either String ()) ) where     run cmd = checkResults =<< run cmd  @@ -19,3 +19,25 @@              return $ Left $ cmd ++ ": terminated by signal " ++ show sig          Stopped sig ->              return $ Left $ cmd ++ ": stopped by signal " ++ show sig++-- Command where Change Working Directory specified at process level+data CWDCommand = CWDCommand {cwdDir :: String,+                              cwdCmd :: String}+  deriving (Read,Show)++instance ShellCommand CWDCommand where+    fdInvoke (CWDCommand dir cmdline) ifd ofd closefd forkfunc =+        do esh <- getEnv "SHELL"+           let sh = case esh of+                      Nothing -> "/bin/sh"+                      Just x -> x+           fdInvoke (sh, ["-c", "cd " ++ dir ++ "; " ++ cmdline]) ifd ofd closefd forkfunc++-- | runCD dir command+-- | useful alternative to bracketCD where bracketCD has the wrong behavior due to lazy IO+-- | note, not a drop in replacement to bracketCD because you specify an actual shell command, not arbitrary IO+runCD :: FilePath -> String -> IO ()+runCD dir cmd = run (CWDCommand dir cmd)++t :: IO ()+t = run (CWDCommand "/tmp" "ls")
HSH/Helpers/Utils.hs view
@@ -31,36 +31,3 @@   return $ case etRes of     Left e -> Left $ show e     Right r -> Right r--{- | Like tryEC in HSH, but doesn't attempt to parse error message, so all errors result in Left result type-     and nothing gets re-raised via ioError -}-{--tryECPromiscuous :: IO a -> IO (Either ProcessStatus a)-tryECPromiscuous action =-    do r <- try action-       case r of-         Left ioe ->-          if isUserError ioe then-              case (ioeGetErrorString ioe =~~ pat) of-                Nothing -> ioError ioe -- not ours; re-raise it-                Just e -> return . Left . proc $ e-          else ioError ioe      -- not ours; re-raise it-         Right result -> return (Right result)-    where pat = ": exited with code [0-9]+$|: terminated by signal ([0-9]+)$|: stopped by signal [0-9]+"-          proc :: String -> ProcessStatus-          proc e-              | e =~ "^: exited" = Exited (ExitFailure (str2ec e))-              | e =~ "^: terminated by signal" = Terminated (str2ec e)-              | e =~ "^: stopped by signal" = Stopped (str2ec e)-              | otherwise = error "Internal error in tryEC"-          str2ec e =-              read (e =~ "[0-9]+$")--}---- | like HSH.runSL, but returns all output, not just the first line.-runS :: String -> IO String-runS = run---- | like runS, but returns as list of lines-runStrings :: String -> IO [String]-runStrings = ( return . lines =<< ) . run 
HSHHelpers.cabal view
@@ -1,5 +1,5 @@ Name: HSHHelpers-Version: 0.19+Version: 0.20 License: GPL License-file: gpl.txt Description: @@ -15,7 +15,7 @@ Copyright: Copyright (c) 2008 Thomas Hartman Exposed-Modules: HSH.Helpers, HSH.Helpers.Instances, HSH.Helpers.UnixUsers, HSH.Helpers.FileManip,                   HSH.Helpers.Utils, HSH.Helpers.Email-Build-Depends: base, HSH, unix, HStringTemplateHelpers, MissingH, regex-pcre, directory, bytestring, filepath, mtl,+Build-Depends: base >= 0.4 && <5, HSH, unix, HStringTemplateHelpers, MissingH, regex-pcre, directory, bytestring, filepath, mtl,                DebugTraceHelpers Category: System Build-type: Simple