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
|
, simRebalance :: Bool
|
||||||
, simHistory :: [SimCommand]
|
, simHistory :: [SimCommand]
|
||||||
, simVectorClock :: VectorClock
|
, simVectorClock :: VectorClock
|
||||||
, simFile :: Maybe FilePath
|
, simLogFile :: Maybe FilePath
|
||||||
, simRootDirectory :: FilePath
|
, simRootDirectory :: FilePath
|
||||||
}
|
}
|
||||||
deriving (Show, Read)
|
deriving (Show, Read)
|
||||||
|
@ -90,7 +90,7 @@ emptySimState rngseed rootdir = SimState
|
||||||
, simRebalance = False
|
, simRebalance = False
|
||||||
, simHistory = []
|
, simHistory = []
|
||||||
, simVectorClock = VectorClock 0
|
, simVectorClock = VectorClock 0
|
||||||
, simFile = Nothing
|
, simLogFile = Nothing
|
||||||
, simRootDirectory = rootdir
|
, simRootDirectory = rootdir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ seek ("end":[]) = do
|
||||||
simdir <- fromRawFilePath <$> fromRepo gitAnnexSimDir
|
simdir <- fromRawFilePath <$> fromRepo gitAnnexSimDir
|
||||||
whenM (liftIO $ doesDirectoryExist simdir) $ do
|
whenM (liftIO $ doesDirectoryExist simdir) $ do
|
||||||
liftIO $ removeDirectoryRecursive simdir
|
liftIO $ removeDirectoryRecursive simdir
|
||||||
|
showLongNote $ UnquotedString "Sim ended."
|
||||||
seek ("visit":reponame:[]) = do
|
seek ("visit":reponame:[]) = do
|
||||||
simdir <- fromRepo gitAnnexSimDir
|
simdir <- fromRepo gitAnnexSimDir
|
||||||
liftIO (restoreSim simdir) >>= \case
|
liftIO (restoreSim simdir) >>= \case
|
||||||
|
@ -51,6 +52,13 @@ seek ("visit":reponame:[]) = do
|
||||||
, "Choose from:"
|
, "Choose from:"
|
||||||
, unwords $ map fromRepoName $ M.keys (simRepos st)
|
, 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
|
seek ps = case parseSimCommand ps of
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right simcmd -> do
|
Right simcmd -> do
|
||||||
|
@ -74,15 +82,14 @@ start simfile = do
|
||||||
|
|
||||||
rng <- fst . random <$> initStdGen
|
rng <- fst . random <$> initStdGen
|
||||||
let st = (emptySimState rng simdir)
|
let st = (emptySimState rng simdir)
|
||||||
{ simFile = Just simlogfile }
|
{ simLogFile = Just simlogfile }
|
||||||
case simfile of
|
case simfile of
|
||||||
Nothing -> startup simdir st []
|
Nothing -> startup simdir st []
|
||||||
Just f -> liftIO (readFile f) >>= \c ->
|
Just f -> liftIO (readFile f) >>= \c ->
|
||||||
case parseSimFile c of
|
case parseSimFile c of
|
||||||
Left err -> giveup err
|
Left err -> giveup err
|
||||||
Right cs -> startup simdir st cs
|
Right cs -> startup simdir st cs
|
||||||
showLongNote $ UnquotedString "Sim started, logging to sim file "
|
showLongNote $ UnquotedString "Sim started."
|
||||||
<> QuotedPath (toRawFilePath simlogfile)
|
|
||||||
where
|
where
|
||||||
startup simdir st cs = do
|
startup simdir st cs = do
|
||||||
repobyname <- mkGetExistingRepoByName
|
repobyname <- mkGetExistingRepoByName
|
||||||
|
@ -98,6 +105,6 @@ start simfile = do
|
||||||
saveState :: SimState SimRepo -> IO ()
|
saveState :: SimState SimRepo -> IO ()
|
||||||
saveState st = do
|
saveState st = do
|
||||||
suspendSim st
|
suspendSim st
|
||||||
case simFile st of
|
case simLogFile st of
|
||||||
Just f -> writeFile f $ generateSimFile $ reverse $ simHistory st
|
Just f -> writeFile f $ generateSimFile $ reverse $ simHistory st
|
||||||
Nothing -> noop
|
Nothing -> noop
|
||||||
|
|
|
@ -10,6 +10,8 @@ git annex sim command
|
||||||
|
|
||||||
git annex sim visit repo
|
git annex sim visit repo
|
||||||
|
|
||||||
|
git annex sim show
|
||||||
|
|
||||||
git annex sim end
|
git annex sim end
|
||||||
|
|
||||||
# DESCRIPTION
|
# 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
|
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.
|
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
|
entire simulation input, as well as the actions performed in the
|
||||||
simulation, and the results of the simulation.
|
simulation, and the results of the simulation. Use "git-annex sim show"
|
||||||
This allows re-running the same simulation later, as well as analyzing
|
to display the log. This allows re-running the same simulation later,
|
||||||
the results of the simulation.
|
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
|
"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
|
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
|
that simulated repository. This allows running any git-annex command, such
|
||||||
as `git-annex whereis` to examine the state of the simulation.
|
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.
|
Exit the subshell to end the visit.
|
||||||
|
|
||||||
Use "git annex sim end" to finish the simulation, and clean up.
|
Use "git annex sim end" to finish the simulation, and clean up.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue