findcompute --inputs
Useful for eg, generating dependency graphs.
This commit is contained in:
parent
a669b7f3ec
commit
74457b6b93
3 changed files with 80 additions and 16 deletions
|
@ -17,6 +17,10 @@ import Command.Find (showFormatted, formatVars)
|
||||||
import Remote.Compute (isComputeRemote, getComputeState, ComputeState(..))
|
import Remote.Compute (isComputeRemote, getComputeState, ComputeState(..))
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import qualified Types.Remote as Remote
|
import qualified Types.Remote as Remote
|
||||||
|
import Database.Keys
|
||||||
|
import Annex.CatFile
|
||||||
|
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = withAnnexOptions [annexedMatchingOptions] $ noCommit $ noMessages $
|
cmd = withAnnexOptions [annexedMatchingOptions] $ noCommit $ noMessages $
|
||||||
|
@ -28,6 +32,7 @@ data FindComputedOptions = FindComputedOptions
|
||||||
{ findThese :: CmdParams
|
{ findThese :: CmdParams
|
||||||
, formatOption :: Maybe Utility.Format.Format
|
, formatOption :: Maybe Utility.Format.Format
|
||||||
, keyOptions :: Maybe KeyOptions
|
, keyOptions :: Maybe KeyOptions
|
||||||
|
, inputsOption :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser FindComputedOptions
|
optParser :: CmdParamsDesc -> Parser FindComputedOptions
|
||||||
|
@ -35,6 +40,10 @@ optParser desc = FindComputedOptions
|
||||||
<$> cmdParams desc
|
<$> cmdParams desc
|
||||||
<*> optional parseFormatOption
|
<*> optional parseFormatOption
|
||||||
<*> optional parseBranchKeysOption
|
<*> optional parseBranchKeysOption
|
||||||
|
<*> switch
|
||||||
|
( long "inputs"
|
||||||
|
<> help "display input files"
|
||||||
|
)
|
||||||
|
|
||||||
parseFormatOption :: Parser Utility.Format.Format
|
parseFormatOption :: Parser Utility.Format.Format
|
||||||
parseFormatOption =
|
parseFormatOption =
|
||||||
|
@ -69,22 +78,51 @@ start o isterminal computeremotes _ file key = do
|
||||||
if null rcs
|
if null rcs
|
||||||
then stop
|
then stop
|
||||||
else startingCustomOutput key $ do
|
else startingCustomOutput key $ do
|
||||||
forM_ rcs $ \(r, c) -> do
|
forM_ rcs display
|
||||||
let computation = unwords (computeParams c)
|
|
||||||
let unformatted = fromOsPath file
|
|
||||||
<> " (" <> encodeBS (Remote.name r)
|
|
||||||
<> ") -- "
|
|
||||||
<> encodeBS computation
|
|
||||||
let formatvars =
|
|
||||||
[ ("remote", Remote.name r)
|
|
||||||
, ("computation", computation)
|
|
||||||
] ++ formatVars key (AssociatedFile (Just file))
|
|
||||||
showFormatted isterminal (formatOption o)
|
|
||||||
unformatted formatvars
|
|
||||||
next $ return True
|
next $ return True
|
||||||
where
|
where
|
||||||
get r = fmap (r, )
|
get r = fmap (r, )
|
||||||
<$> getComputeState (Remote.remoteStateHandle r) key
|
<$> getComputeState (Remote.remoteStateHandle r) key
|
||||||
|
|
||||||
|
showformatted = showFormatted isterminal (formatOption o)
|
||||||
|
|
||||||
|
unformatted r computation = fromOsPath file
|
||||||
|
<> " (" <> encodeBS (Remote.name r)
|
||||||
|
<> ") -- "
|
||||||
|
<> encodeBS computation
|
||||||
|
|
||||||
|
unformattedinputs (Right inputfile) = fromOsPath file
|
||||||
|
<> " " <> fromOsPath inputfile
|
||||||
|
unformattedinputs (Left inputkey) = fromOsPath file
|
||||||
|
<> " " <> serializeKey' inputkey
|
||||||
|
|
||||||
|
display (r, c) = do
|
||||||
|
let computation = unwords (computeParams c)
|
||||||
|
let formatvars =
|
||||||
|
[ ("remote", Remote.name r)
|
||||||
|
, ("computation", computation)
|
||||||
|
] ++ formatVars key (AssociatedFile (Just file))
|
||||||
|
if inputsOption o
|
||||||
|
then forM_ (M.elems $ computeInputs c) $ \inputkey -> do
|
||||||
|
input <- maybe (Left inputkey) Right
|
||||||
|
<$> getassociated inputkey
|
||||||
|
showformatted (unformattedinputs input) $
|
||||||
|
[ ("input", either serializeKey fromOsPath input)
|
||||||
|
, ("inputkey", serializeKey inputkey)
|
||||||
|
, ("inputfile", either (const "") fromOsPath input)
|
||||||
|
] ++ formatvars
|
||||||
|
else showformatted (unformatted r computation) formatvars
|
||||||
|
|
||||||
|
getassociated inputkey =
|
||||||
|
getAssociatedFiles inputkey
|
||||||
|
>>= mapM (fromRepo . fromTopFilePath)
|
||||||
|
>>= firstM (stillassociated inputkey)
|
||||||
|
|
||||||
|
-- Some associated files that are in the keys database may no
|
||||||
|
-- longer correspond to files in the repository.
|
||||||
|
stillassociated k f = catKeyFile f >>= return . \case
|
||||||
|
Just k' | k' == k -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
startKeys :: FindComputedOptions -> IsTerminal -> [Remote] -> (SeekInput, Key, ActionItem) -> CommandStart
|
startKeys :: FindComputedOptions -> IsTerminal -> [Remote] -> (SeekInput, Key, ActionItem) -> CommandStart
|
||||||
startKeys o isterminal computeremotes (si, key, ActionItemBranchFilePath (BranchFilePath _ topf) _) =
|
startKeys o isterminal computeremotes (si, key, ActionItemBranchFilePath (BranchFilePath _ topf) _) =
|
||||||
|
|
|
@ -70,9 +70,9 @@ start o (_, key, _) = startingCustomOutput key $ do
|
||||||
where
|
where
|
||||||
-- Some associated files that are in the keys database may no
|
-- Some associated files that are in the keys database may no
|
||||||
-- longer correspond to files in the repository.
|
-- longer correspond to files in the repository.
|
||||||
stillassociated f = catKeyFile f >>= \case
|
stillassociated f = catKeyFile f >>= return . \case
|
||||||
Just k | k == key -> return True
|
Just k | k == key -> True
|
||||||
_ -> return False
|
_ -> False
|
||||||
|
|
||||||
display :: Key -> StringContainingQuotedPath -> Annex ()
|
display :: Key -> StringContainingQuotedPath -> Annex ()
|
||||||
display key loc = do
|
display key loc = do
|
||||||
|
|
|
@ -32,18 +32,44 @@ For example:
|
||||||
|
|
||||||
List computed files in the specified branch or treeish.
|
List computed files in the specified branch or treeish.
|
||||||
|
|
||||||
|
* `--inputs`
|
||||||
|
|
||||||
|
Display each computed file followed by the input that is used to
|
||||||
|
produce it. The current location of the input file in the work tree is
|
||||||
|
displayed, but if the input file is not in the work tree, the key
|
||||||
|
is displayed instead.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
foo.jpeg file.raw
|
||||||
|
bar.gz bar
|
||||||
|
|
||||||
|
When multiple input files are needed to compute a file, outputs multiple
|
||||||
|
lines for that file:
|
||||||
|
|
||||||
|
foo bar
|
||||||
|
foo baz
|
||||||
|
|
||||||
* `--format=value`
|
* `--format=value`
|
||||||
|
|
||||||
Use custom output formatting.
|
Use custom output formatting.
|
||||||
|
|
||||||
This option works the same as in [[git-annex-find]](1), with these
|
This option works the same as in [[git-annex-find]](1), with these
|
||||||
additional variables available for use in it:
|
additional variables available for use in it:
|
||||||
remote, computation
|
"${remote}", "${computation}"
|
||||||
|
|
||||||
The default output format is the same as
|
The default output format is the same as
|
||||||
`--format='${file} (${remote}) -- ${computation}\\n'`,
|
`--format='${file} (${remote}) -- ${computation}\\n'`,
|
||||||
except when outputting to a terminal, control characters will be escaped.
|
except when outputting to a terminal, control characters will be escaped.
|
||||||
|
|
||||||
|
When `--inputs` is used, there are additional variables "${inputfile}"
|
||||||
|
which is the input filename, "${inputkey}" which is the input key,
|
||||||
|
and "${input}" which is either the filename or the key.
|
||||||
|
The default output format for `--inputs`
|
||||||
|
is the same as `--format='${file} ${input}\\n'`
|
||||||
|
To separate the pair of files by nulls instead, use eg
|
||||||
|
`--format='${file}\\000${input}\\n'
|
||||||
|
|
||||||
* `--json`
|
* `--json`
|
||||||
|
|
||||||
Output the list of files in JSON format.
|
Output the list of files in JSON format.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue