From cc532bdd8fdd53d6bb90910caca1b082780f3cec Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sun, 19 Jun 2011 13:38:32 +0300 Subject: [PATCH] htools: some lint fixes Removal of duplicate parantheses, removal of extra 'do', conversion from nested if to guards, use hierarchical imports. All per hlint. Signed-off-by: Iustin Pop Reviewed-by: Michael Hanselmann --- htools/Ganeti/HTools/CLI.hs | 2 +- htools/Ganeti/HTools/ExtLoader.hs | 2 +- htools/Ganeti/HTools/IAlloc.hs | 2 +- htools/Ganeti/HTools/Node.hs | 6 ++++-- htools/Ganeti/HTools/QC.hs | 24 ++++++++++++------------ htools/hail.hs | 4 ++-- htools/hbal.hs | 18 +++++++++--------- htools/hscan.hs | 2 +- htools/hspace.hs | 4 ++-- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/htools/Ganeti/HTools/CLI.hs b/htools/Ganeti/HTools/CLI.hs index ca286f0..bc30b89 100644 --- a/htools/Ganeti/HTools/CLI.hs +++ b/htools/Ganeti/HTools/CLI.hs @@ -74,9 +74,9 @@ module Ganeti.HTools.CLI , oVerbose ) where +import Control.Monad import Data.Maybe (fromMaybe) import qualified Data.Version -import Monad import System.Console.GetOpt import System.IO import System.Info diff --git a/htools/Ganeti/HTools/ExtLoader.hs b/htools/Ganeti/HTools/ExtLoader.hs index 0db8956..b7ca04a 100644 --- a/htools/Ganeti/HTools/ExtLoader.hs +++ b/htools/Ganeti/HTools/ExtLoader.hs @@ -33,8 +33,8 @@ module Ganeti.HTools.ExtLoader , maybeSaveData ) where +import Control.Monad import Data.Maybe (isJust, fromJust) -import Monad import System.FilePath import System.IO import System diff --git a/htools/Ganeti/HTools/IAlloc.hs b/htools/Ganeti/HTools/IAlloc.hs index f224f11..7012173 100644 --- a/htools/Ganeti/HTools/IAlloc.hs +++ b/htools/Ganeti/HTools/IAlloc.hs @@ -181,7 +181,7 @@ parseData body = do rl_names <- extrReq "instances" rl_insts <- mapM (Container.findByName map_i) rl_names let rl_idx = map Instance.idx rl_insts - rl_mode <- do + rl_mode <- case extrReq "reloc_mode" of Ok s | s == C.iallocatorMrelocKeep -> return KeepGroup | s == C.iallocatorMrelocChange -> diff --git a/htools/Ganeti/HTools/Node.hs b/htools/Ganeti/HTools/Node.hs index 3ee8799..65237e5 100644 --- a/htools/Ganeti/HTools/Node.hs +++ b/htools/Ganeti/HTools/Node.hs @@ -478,8 +478,10 @@ showField t field = "idx" -> printf "%4d" $ idx t "name" -> alias t "fqdn" -> name t - "status" -> if offline t then "-" - else if failN1 t then "*" else " " + "status" -> case () of + _ | offline t -> "-" + | failN1 t -> "*" + | otherwise -> " " "tmem" -> printf "%5.0f" $ tMem t "nmem" -> printf "%5d" $ nMem t "xmem" -> printf "%5d" $ xMem t diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index 9b130bc..a2ed78b 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -260,7 +260,7 @@ prop_Utils_fromObjWithDefault def_value random_key = -- a found key will be returned as is, not with default Utils.fromObjWithDefault [(random_key, J.showJSON def_value)] random_key (def_value+1) == Just def_value - where _types = (def_value :: Integer) + where _types = def_value :: Integer testUtils = [ run prop_Utils_commaJoinSplit @@ -487,15 +487,15 @@ prop_Text_Load_Instance name mem dsk vcpus status pnode snode pdx sdx autobal = case inst of Nothing -> False Just (_, i) -> - (Instance.name i == name && - Instance.vcpus i == vcpus && - Instance.mem i == mem && - Instance.pNode i == pdx && - Instance.sNode i == (if null snode - then Node.noSecondary - else rsdx) && - Instance.auto_balance i == autobal && - isNothing fail1) + Instance.name i == name && + Instance.vcpus i == vcpus && + Instance.mem i == mem && + Instance.pNode i == pdx && + Instance.sNode i == (if null snode + then Node.noSecondary + else rsdx) && + Instance.auto_balance i == autobal && + isNothing fail1 prop_Text_Load_InstanceFail ktn fields = length fields /= 9 ==> @@ -615,7 +615,7 @@ prop_Node_addSec node inst pdx = prop_Node_rMem node inst = -- ab = auto_balance, nb = non-auto_balance -- we use -1 as the primary node of the instance - let inst' = inst { Instance.pNode = (-1), Instance.auto_balance = True} + let inst' = inst { Instance.pNode = -1, Instance.auto_balance = True } inst_ab = setInstanceSmallerThanNode node inst' inst_nb = inst_ab { Instance.auto_balance = False } -- now we have the two instances, identical except the @@ -680,7 +680,7 @@ prop_Node_computeGroups nodes = in length nodes == sum (map (length . snd) ng) && all (\(guuid, ns) -> all ((== guuid) . Node.group) ns) ng && length (nub onlyuuid) == length onlyuuid && - if null nodes then True else not (null ng) + (null nodes || not (null ng)) testNode = [ run prop_Node_setAlias diff --git a/htools/hail.hs b/htools/hail.hs index a497b46..75f4490 100644 --- a/htools/hail.hs +++ b/htools/hail.hs @@ -25,9 +25,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Main (main) where +import Control.Monad import Data.List import Data.Maybe (isJust, fromJust) -import Monad import System (exitWith, ExitCode(..)) import System.IO import qualified System @@ -85,7 +85,7 @@ readRequest opts args = do exitWith $ ExitFailure 1 input_data <- readFile (head args) - r1 <- case (parseData input_data) of + r1 <- case parseData input_data of Bad err -> do hPutStrLn stderr $ "Error: " ++ err exitWith $ ExitFailure 1 diff --git a/htools/hbal.hs b/htools/hbal.hs index 34ee989..47696ae 100644 --- a/htools/hbal.hs +++ b/htools/hbal.hs @@ -27,10 +27,10 @@ module Main (main) where import Control.Concurrent (threadDelay) import Control.Exception (bracket) +import Control.Monad import Data.List import Data.Maybe (isJust, isNothing, fromJust) import Data.IORef -import Monad import System (exitWith, ExitCode(..)) import System.IO import System.Posix.Process @@ -366,14 +366,14 @@ main = do (optEvacMode opts) let (Cluster.Table fin_nl fin_il fin_cv fin_plc) = fin_tbl ord_plc = reverse fin_plc - sol_msg = if null fin_plc - then printf "No solution found\n" - else if verbose > 2 - then printf "Final coefficients: overall %.8f, %s\n" - fin_cv (Cluster.printStats fin_nl) - else printf "Cluster score improved from %.8f to %.8f\n" - ini_cv fin_cv - ::String + sol_msg = case () of + _ | null fin_plc -> printf "No solution found\n" + | verbose > 2 -> + printf "Final coefficients: overall %.8f, %s\n" + fin_cv (Cluster.printStats fin_nl) + | otherwise -> + printf "Cluster score improved from %.8f to %.8f\n" + ini_cv fin_cv ::String unless oneline $ putStr sol_msg diff --git a/htools/hscan.hs b/htools/hscan.hs index e057972..261fce3 100644 --- a/htools/hscan.hs +++ b/htools/hscan.hs @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Main (main) where +import Control.Monad import Data.Maybe (isJust, fromJust, fromMaybe) -import Monad import System (exitWith, ExitCode(..)) import System.IO import System.FilePath diff --git a/htools/hspace.hs b/htools/hspace.hs index d45fbd1..89d2f73 100644 --- a/htools/hspace.hs +++ b/htools/hspace.hs @@ -25,11 +25,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Main (main) where +import Control.Monad import Data.Char (toUpper, isAlphaNum) import Data.List import Data.Maybe (isJust, fromJust) import Data.Ord (comparing) -import Monad import System (exitWith, ExitCode(..)) import System.IO import qualified System @@ -171,7 +171,7 @@ printAllocationStats m_cpu ini_nl fin_nl = do -- | Ensure a value is quoted if needed ensureQuoted :: String -> String -ensureQuoted v = if not (all (\c -> (isAlphaNum c || c == '.')) v) +ensureQuoted v = if not (all (\c -> isAlphaNum c || c == '.') v) then '\'':v ++ "'" else v -- 1.7.10.4