uacpid 1.1 → 1.2
raw patch · 6 files changed
+32/−59 lines, 6 filesdep +time-locale-compatdep −old-localedep ~mtldep ~time
Dependencies added: time-locale-compat
Dependencies removed: old-locale
Dependency ranges changed: mtl, time
Files
- changelog.md +8/−0
- src/Uacpid/Control/Monad/Except.hs +0/−48
- src/Uacpid/Events.hs +4/−3
- src/Uacpid/Log.hs +2/−1
- src/main.hs +5/−2
- uacpid.cabal +13/−5
changelog.md view
@@ -1,3 +1,11 @@+1.2 (2015-06-30)++ * Added a lower bound for mtl dep+ * Simplified some config error handling+ * Decided to not force time >= 1.5 for now+ * Reformatted cabal file a bit++ 1.1 (2015-06-28) * Replaced deprecated Control.Monad.ErrorT with ExceptT
− src/Uacpid/Control/Monad/Except.hs
@@ -1,48 +0,0 @@--- License: BSD3 (see LICENSE)--- Author: Dino Morelli <dino@ui3.info>--{-# LANGUAGE FlexibleContexts #-}--{- |- Convenience function for turning (Maybe a) values into - (MonadError e a) actions plus functions for expressing Data.Map - lookups as MonadError actions--}-module Uacpid.Control.Monad.Except- ( maybeThrow- , lookupEWith, lookupEString- )- where--import Control.Monad.Except-import Data.Map hiding ( map )-import Prelude hiding ( lookup )---{- |- Turn an error value and a (Maybe a) into a (MonadError e a) action--}-maybeThrow :: (MonadError e m) => e -> Maybe a -> m a-maybeThrow err mval = maybe (throwError err) return mval---{- |- Look up a String key in a Map as an action in (MonadError e), - providing a function to transform key type k to error type e.-- See lookupEString below for a usage example.--}-lookupEWith :: (MonadError e m, Ord k) =>- (k -> e) -> k -> Map k a -> m a-lookupEWith f k m = maybeThrow (f k) $ lookup k m---{- |- Look up a String key in a Map as an action in (MonadError String), - with a default message that the key was not found as the- error.--}-lookupEString :: (MonadError String m) =>- String -> Map String a -> m a-lookupEString =- lookupEWith (\k -> "Key " ++ k ++ " not found")
src/Uacpid/Events.hs view
@@ -9,6 +9,7 @@ import Control.Monad.Except import Data.List+import qualified Data.Map as M import Data.Maybe import System.Directory import System.FilePath@@ -17,7 +18,6 @@ import Text.Regex ( matchRegex, mkRegex ) import Uacpid.Conf ( ConfMap, getConfDir, parseToMap )-import Uacpid.Control.Monad.Except import Uacpid.Log ( logM ) @@ -30,8 +30,9 @@ lookupHandlerE :: (MonadError String m) => String -> String -> ConfMap -> m String-lookupHandlerE name = lookupEWith- (\j -> "Handler " ++ name ++ ": key " ++ j ++ " not found")+lookupHandlerE name k m = maybe+ (throwError $ "Handler " ++ name ++ ": key " ++ k ++ " not found")+ return $ M.lookup k m loadHandler :: (String, FilePath) -> IO (Maybe Handler)
src/Uacpid/Log.hs view
@@ -9,7 +9,8 @@ import Data.Map ( lookup ) import Data.Maybe import Data.Time.Clock ( getCurrentTime )-import Data.Time.Format ( defaultTimeLocale, formatTime )+import Data.Time.Format ( formatTime )+import Data.Time.Locale.Compat ( defaultTimeLocale ) import Data.Time.LocalTime ( utcToLocalZonedTime ) import Prelude hiding ( lookup ) import System.Log.Handler.Simple ( fileHandler )
src/main.hs view
@@ -19,7 +19,6 @@ import Paths_uacpid ( version ) import Uacpid.Conf-import Uacpid.Control.Monad.Except import Uacpid.Events import Uacpid.Log ( initLogging, logM ) @@ -32,12 +31,16 @@ throwSocketFileError msgPrefix = throwError $ msgPrefix ++ " Make sure acpid is installed, is running, and that this path is correct. This config setting is in ~/.uacpid/uacpid.conf under the key acpidSocket" +lookupE :: (MonadError String m) => String -> Map String a -> m a+lookupE k m = maybe (throwError $ "Missing key: " ++ k) return $ lookup k m++ openAcpidSocket :: (MonadError String m, MonadIO m) => ConfMap -> m Handle openAcpidSocket conf = do liftIO $ logM NOTICE "Establishing connection to acpid's socket..." - acpidSocketPath <- lookupEString "acpidSocket" conf+ acpidSocketPath <- lookupE "acpidSocket" conf pathExists <- liftIO $ fileExist acpidSocketPath unless pathExists $ throwSocketFileError $
uacpid.cabal view
@@ -1,5 +1,5 @@ name: uacpid-version: 1.1+version: 1.2 cabal-version: >= 1.8 build-type: Simple license: BSD3@@ -41,12 +41,20 @@ executable uacpid main-is: main.hs- build-depends: base >= 3 && < 5, containers, directory, filepath, - hslogger, mtl, network, old-locale, process, - regex-compat, time, unix+ build-depends: base >= 3 && < 5+ , containers+ , directory+ , filepath+ , hslogger+ , mtl >= 2.2.1+ , network+ , process+ , regex-compat+ , time+ , time-locale-compat+ , unix hs-source-dirs: src other-modules: Uacpid.Conf- Uacpid.Control.Monad.Except Uacpid.Events Uacpid.Log ghc-options: -Wall