git-annex sim log
This commit is contained in:
parent
b85965cb3c
commit
02f0996e25
3 changed files with 21 additions and 11 deletions
|
@ -67,7 +67,7 @@ data SimState t = SimState
|
|||
, simRebalance :: Bool
|
||||
, simHistory :: [SimCommand]
|
||||
, simVectorClock :: VectorClock
|
||||
, simFile :: Maybe FilePath
|
||||
, simLogFile :: Maybe FilePath
|
||||
, simRootDirectory :: FilePath
|
||||
}
|
||||
deriving (Show, Read)
|
||||
|
@ -90,7 +90,7 @@ emptySimState rngseed rootdir = SimState
|
|||
, simRebalance = False
|
||||
, simHistory = []
|
||||
, simVectorClock = VectorClock 0
|
||||
, simFile = Nothing
|
||||
, simLogFile = Nothing
|
||||
, simRootDirectory = rootdir
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ seek ("end":[]) = do
|
|||
simdir <- fromRawFilePath <$> fromRepo gitAnnexSimDir
|
||||
whenM (liftIO $ doesDirectoryExist simdir) $ do
|
||||
liftIO $ removeDirectoryRecursive simdir
|
||||
showLongNote $ UnquotedString "Sim ended."
|
||||
seek ("visit":reponame:[]) = do
|
||||
simdir <- fromRepo gitAnnexSimDir
|
||||
liftIO (restoreSim simdir) >>= \case
|
||||
|
@ -51,6 +52,13 @@ seek ("visit":reponame:[]) = do
|
|||
, "Choose from:"
|
||||
, unwords $ map fromRepoName $ M.keys (simRepos st)
|
||||
]
|
||||
seek ("show":[]) = do
|
||||
simdir <- fromRepo gitAnnexSimDir
|
||||
liftIO (restoreSim simdir) >>= \case
|
||||
Left err -> giveup err
|
||||
Right st -> case simLogFile st of
|
||||
Just f -> liftIO $ putStr =<< readFile f
|
||||
Nothing -> return ()
|
||||
seek ps = case parseSimCommand ps of
|
||||
Left err -> giveup err
|
||||
Right simcmd -> do
|
||||
|
@ -74,15 +82,14 @@ start simfile = do
|
|||
|
||||
rng <- fst . random <$> initStdGen
|
||||
let st = (emptySimState rng simdir)
|
||||
{ simFile = Just simlogfile }
|
||||
{ simLogFile = Just simlogfile }
|
||||
case simfile of
|
||||
Nothing -> startup simdir st []
|
||||
Just f -> liftIO (readFile f) >>= \c ->
|
||||
case parseSimFile c of
|
||||
Left err -> giveup err
|
||||
Right cs -> startup simdir st cs
|
||||
showLongNote $ UnquotedString "Sim started, logging to sim file "
|
||||
<> QuotedPath (toRawFilePath simlogfile)
|
||||
showLongNote $ UnquotedString "Sim started."
|
||||
where
|
||||
startup simdir st cs = do
|
||||
repobyname <- mkGetExistingRepoByName
|
||||
|
@ -98,6 +105,6 @@ start simfile = do
|
|||
saveState :: SimState SimRepo -> IO ()
|
||||
saveState st = do
|
||||
suspendSim st
|
||||
case simFile st of
|
||||
case simLogFile st of
|
||||
Just f -> writeFile f $ generateSimFile $ reverse $ simHistory st
|
||||
Nothing -> noop
|
||||
|
|
|
@ -10,6 +10,8 @@ git annex sim command
|
|||
|
||||
git annex sim visit repo
|
||||
|
||||
git annex sim show
|
||||
|
||||
git annex sim end
|
||||
|
||||
# DESCRIPTION
|
||||
|
@ -24,17 +26,18 @@ run after starting it. These are in the form "git annex sim command"
|
|||
with the command in the same format used in the sim file (see sim commands
|
||||
list below). For example, "git annex sim step 1" runs the simulation one step.
|
||||
|
||||
The simulation writes to an output sim file as it runs, which contains the
|
||||
The simulation keeps a log as it runs, which contains the
|
||||
entire simulation input, as well as the actions performed in the
|
||||
simulation, and the results of the simulation.
|
||||
This allows re-running the same simulation later, as well as analyzing
|
||||
the results of the simulation.
|
||||
simulation, and the results of the simulation. Use "git-annex sim show"
|
||||
to display the log. This allows re-running the same simulation later,
|
||||
as well as analyzing the results of the simulation.
|
||||
|
||||
While a simulation is running, the command "git annex visit repo", where
|
||||
While a simulation is running, the command "git annex sim visit repo", where
|
||||
"repo" is the name of one of the repositories in the simulation, will spawn
|
||||
a subshell in a git repository whose git-annex branch contains the state of
|
||||
that simulated repository. This allows running any git-annex command, such
|
||||
as `git-annex whereis` to examine the state of the simulation.
|
||||
You should avoid making any changes to git-annex state.
|
||||
Exit the subshell to end the visit.
|
||||
|
||||
Use "git annex sim end" to finish the simulation, and clean up.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue