htools: some lint fixes
authorIustin Pop <iustin@google.com>
Sun, 19 Jun 2011 10:38:32 +0000 (13:38 +0300)
committerIustin Pop <iustin@google.com>
Tue, 28 Jun 2011 15:35:42 +0000 (17:35 +0200)
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 <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

htools/Ganeti/HTools/CLI.hs
htools/Ganeti/HTools/ExtLoader.hs
htools/Ganeti/HTools/IAlloc.hs
htools/Ganeti/HTools/Node.hs
htools/Ganeti/HTools/QC.hs
htools/hail.hs
htools/hbal.hs
htools/hscan.hs
htools/hspace.hs

index ca286f0..bc30b89 100644 (file)
@@ -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
index 0db8956..b7ca04a 100644 (file)
@@ -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
index f224f11..7012173 100644 (file)
@@ -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 ->
index 3ee8799..65237e5 100644 (file)
@@ -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
index 9b130bc..a2ed78b 100644 (file)
@@ -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
index a497b46..75f4490 100644 (file)
@@ -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
index 34ee989..47696ae 100644 (file)
@@ -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
 
index e057972..261fce3 100644 (file)
@@ -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
index d45fbd1..89d2f73 100644 (file)
@@ -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