status --json now shows most things
Left out the backend usage graph for now, and bad/temp directory sizes are only displayed when present. Also, disk usage is returned as a string with units, which I can see changing later.
This commit is contained in:
parent
128b4bd015
commit
d675f1c82e
3 changed files with 40 additions and 32 deletions
|
@ -11,6 +11,7 @@ import Control.Monad.State
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Set (Set)
|
import Data.Set (Set)
|
||||||
|
import Text.JSON
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Types.Backend as B
|
import qualified Types.Backend as B
|
||||||
|
@ -78,12 +79,21 @@ start = do
|
||||||
return True
|
return True
|
||||||
stop
|
stop
|
||||||
|
|
||||||
stat :: String -> StatState String -> Stat
|
stat :: String -> (String -> StatState String) -> Stat
|
||||||
stat desc a = return $ Just (desc, a)
|
stat desc a = return $ Just (desc, a desc)
|
||||||
|
|
||||||
nostat :: Stat
|
nostat :: Stat
|
||||||
nostat = return Nothing
|
nostat = return Nothing
|
||||||
|
|
||||||
|
json :: JSON j => (j -> String) -> StatState j -> String -> StatState String
|
||||||
|
json serialize a desc = do
|
||||||
|
j <- a
|
||||||
|
lift $ maybeShowJSON [(desc, j)]
|
||||||
|
return $ serialize j
|
||||||
|
|
||||||
|
nojson :: StatState String -> String -> StatState String
|
||||||
|
nojson a _ = a
|
||||||
|
|
||||||
showStat :: Stat -> StatState ()
|
showStat :: Stat -> StatState ()
|
||||||
showStat s = calc =<< s
|
showStat s = calc =<< s
|
||||||
where
|
where
|
||||||
|
@ -93,15 +103,15 @@ showStat s = calc =<< s
|
||||||
calc Nothing = return ()
|
calc Nothing = return ()
|
||||||
|
|
||||||
supported_backends :: Stat
|
supported_backends :: Stat
|
||||||
supported_backends = stat "supported backends" $
|
supported_backends = stat "supported backends" $ json unwords $
|
||||||
return $ unwords $ map B.name Backend.list
|
return $ map B.name Backend.list
|
||||||
|
|
||||||
supported_remote_types :: Stat
|
supported_remote_types :: Stat
|
||||||
supported_remote_types = stat "supported remote types" $
|
supported_remote_types = stat "supported remote types" $ json unwords $
|
||||||
return $ unwords $ map R.typename Remote.remoteTypes
|
return $ map R.typename Remote.remoteTypes
|
||||||
|
|
||||||
remote_list :: TrustLevel -> String -> Stat
|
remote_list :: TrustLevel -> String -> Stat
|
||||||
remote_list level desc = stat n $ lift $ do
|
remote_list level desc = stat n $ nojson $ lift $ do
|
||||||
us <- M.keys <$> (M.union <$> uuidMap <*> remoteMap)
|
us <- M.keys <$> (M.union <$> uuidMap <*> remoteMap)
|
||||||
rs <- fst <$> trustPartition level us
|
rs <- fst <$> trustPartition level us
|
||||||
s <- prettyPrintUUIDs n rs
|
s <- prettyPrintUUIDs n rs
|
||||||
|
@ -110,20 +120,20 @@ remote_list level desc = stat n $ lift $ do
|
||||||
n = desc ++ " repositories"
|
n = desc ++ " repositories"
|
||||||
|
|
||||||
local_annex_size :: Stat
|
local_annex_size :: Stat
|
||||||
local_annex_size = stat "local annex size" $
|
local_annex_size = stat "local annex size" $ json id $
|
||||||
keySizeSum <$> cachedKeysPresent
|
keySizeSum <$> cachedKeysPresent
|
||||||
|
|
||||||
local_annex_keys :: Stat
|
local_annex_keys :: Stat
|
||||||
local_annex_keys = stat "local annex keys" $
|
local_annex_keys = stat "local annex keys" $ json show $
|
||||||
show . S.size <$> cachedKeysPresent
|
S.size <$> cachedKeysPresent
|
||||||
|
|
||||||
visible_annex_size :: Stat
|
visible_annex_size :: Stat
|
||||||
visible_annex_size = stat "visible annex size" $
|
visible_annex_size = stat "visible annex size" $ json id $
|
||||||
keySizeSum <$> cachedKeysReferenced
|
keySizeSum <$> cachedKeysReferenced
|
||||||
|
|
||||||
visible_annex_keys :: Stat
|
visible_annex_keys :: Stat
|
||||||
visible_annex_keys = stat "visible annex keys" $
|
visible_annex_keys = stat "visible annex keys" $ json show $
|
||||||
show . S.size <$> cachedKeysReferenced
|
S.size <$> cachedKeysReferenced
|
||||||
|
|
||||||
tmp_size :: Stat
|
tmp_size :: Stat
|
||||||
tmp_size = staleSize "temporary directory size" gitAnnexTmpDir
|
tmp_size = staleSize "temporary directory size" gitAnnexTmpDir
|
||||||
|
@ -132,7 +142,8 @@ bad_data_size :: Stat
|
||||||
bad_data_size = staleSize "bad keys size" gitAnnexBadDir
|
bad_data_size = staleSize "bad keys size" gitAnnexBadDir
|
||||||
|
|
||||||
backend_usage :: Stat
|
backend_usage :: Stat
|
||||||
backend_usage = stat "backend usage" $ usage <$> cachedKeysReferenced <*> cachedKeysPresent
|
backend_usage = stat "backend usage" $ nojson $
|
||||||
|
usage <$> cachedKeysReferenced <*> cachedKeysPresent
|
||||||
where
|
where
|
||||||
usage a b = pp "" $ reverse . sort $ map swap $ splits $ S.toList $ S.union a b
|
usage a b = pp "" $ reverse . sort $ map swap $ splits $ S.toList $ S.union a b
|
||||||
splits :: [Key] -> [(String, Integer)]
|
splits :: [Key] -> [(String, Integer)]
|
||||||
|
@ -179,9 +190,9 @@ staleSize label dirspec = do
|
||||||
keys <- lift (Command.Unused.staleKeys dirspec)
|
keys <- lift (Command.Unused.staleKeys dirspec)
|
||||||
if null keys
|
if null keys
|
||||||
then nostat
|
then nostat
|
||||||
else stat label $ do
|
else do
|
||||||
let s = keySizeSum $ S.fromList keys
|
stat label $ json (++ aside "clean up with git-annex unused") $
|
||||||
return $ s ++ aside "clean up with git-annex unused"
|
return $ keySizeSum $ S.fromList keys
|
||||||
|
|
||||||
aside :: String -> String
|
aside :: String -> String
|
||||||
aside s = " (" ++ s ++ ")"
|
aside s = " (" ++ s ++ ")"
|
||||||
|
|
24
Messages.hs
24
Messages.hs
|
@ -68,17 +68,17 @@ showEndFail :: Annex ()
|
||||||
showEndFail = showEndResult False
|
showEndFail = showEndResult False
|
||||||
|
|
||||||
showEndResult :: Bool -> Annex ()
|
showEndResult :: Bool -> Annex ()
|
||||||
showEndResult b = handle (JSON.end b) $ putStrLn msg
|
showEndResult ok = handle (JSON.end ok) $ putStrLn msg
|
||||||
where
|
where
|
||||||
msg
|
msg
|
||||||
| b = "ok"
|
| ok = "ok"
|
||||||
| otherwise = "failed"
|
| otherwise = "failed"
|
||||||
|
|
||||||
showErr :: (Show a) => a -> Annex ()
|
showErr :: (Show a) => a -> Annex ()
|
||||||
showErr e = warning' $ "git-annex: " ++ show e
|
showErr e = warning' $ "git-annex: " ++ show e
|
||||||
|
|
||||||
warning :: String -> Annex ()
|
warning :: String -> Annex ()
|
||||||
warning w = warning' (indent w)
|
warning = warning' . indent
|
||||||
|
|
||||||
warning' :: String -> Annex ()
|
warning' :: String -> Annex ()
|
||||||
warning' w = do
|
warning' w = do
|
||||||
|
@ -88,7 +88,7 @@ warning' w = do
|
||||||
hPutStrLn stderr w
|
hPutStrLn stderr w
|
||||||
|
|
||||||
indent :: String -> String
|
indent :: String -> String
|
||||||
indent s = join "\n" $ map (\l -> " " ++ l) $ lines s
|
indent = join "\n" . map (\l -> " " ++ l) . lines
|
||||||
|
|
||||||
{- Shows a JSON value only when in json mode. -}
|
{- Shows a JSON value only when in json mode. -}
|
||||||
maybeShowJSON :: JSON a => [(String, a)] -> Annex ()
|
maybeShowJSON :: JSON a => [(String, a)] -> Annex ()
|
||||||
|
@ -105,9 +105,8 @@ showCustom command a = do
|
||||||
handle (JSON.end r) q
|
handle (JSON.end r) q
|
||||||
|
|
||||||
showHeader :: String -> Annex ()
|
showHeader :: String -> Annex ()
|
||||||
showHeader h = handle q $ do
|
showHeader h = handle q $
|
||||||
putStr $ h ++ ": "
|
flushed $ putStr $ h ++ ": "
|
||||||
hFlush stdout
|
|
||||||
|
|
||||||
showRaw :: String -> Annex ()
|
showRaw :: String -> Annex ()
|
||||||
showRaw s = handle q $ putStrLn s
|
showRaw s = handle q $ putStrLn s
|
||||||
|
@ -126,12 +125,11 @@ setupConsole = do
|
||||||
hSetBinaryMode stderr True
|
hSetBinaryMode stderr True
|
||||||
|
|
||||||
handle :: IO () -> IO () -> Annex ()
|
handle :: IO () -> IO () -> Annex ()
|
||||||
handle json normal = do
|
handle json normal = Annex.getState Annex.output >>= go
|
||||||
output <- Annex.getState Annex.output
|
where
|
||||||
case output of
|
go Annex.NormalOutput = liftIO normal
|
||||||
Annex.NormalOutput -> liftIO normal
|
go Annex.QuietOutput = q
|
||||||
Annex.QuietOutput -> q
|
go Annex.JSONOutput = liftIO json
|
||||||
Annex.JSONOutput -> liftIO json
|
|
||||||
|
|
||||||
q :: Monad m => m ()
|
q :: Monad m => m ()
|
||||||
q = return ()
|
q = return ()
|
||||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -11,8 +11,7 @@ git-annex (3.20111112) UNRELEASED; urgency=low
|
||||||
* status: Now displays trusted, untrusted, and semitrusted repositories
|
* status: Now displays trusted, untrusted, and semitrusted repositories
|
||||||
separately.
|
separately.
|
||||||
* status: Include all special remotes in the list of repositories.
|
* status: Include all special remotes in the list of repositories.
|
||||||
* status: Fix --json mode (only the repository lists are currently
|
* status: Fix --json mode.
|
||||||
displayed)
|
|
||||||
* status: --fast is back
|
* status: --fast is back
|
||||||
* Fix support for insteadOf url remapping. Closes: #644278
|
* Fix support for insteadOf url remapping. Closes: #644278
|
||||||
* When not run in a git repository, git-annex can still display a usage
|
* When not run in a git repository, git-annex can still display a usage
|
||||||
|
|
Loading…
Add table
Reference in a new issue