registerurl: New plumbing command for mass-adding urls to keys.
This commit is contained in:
parent
b24bb6b435
commit
abfe3c09b2
5 changed files with 69 additions and 1 deletions
|
@ -24,6 +24,7 @@ import qualified Command.Get
|
||||||
import qualified Command.LookupKey
|
import qualified Command.LookupKey
|
||||||
import qualified Command.ExamineKey
|
import qualified Command.ExamineKey
|
||||||
import qualified Command.FromKey
|
import qualified Command.FromKey
|
||||||
|
import qualified Command.RegisterUrl
|
||||||
import qualified Command.DropKey
|
import qualified Command.DropKey
|
||||||
import qualified Command.TransferKey
|
import qualified Command.TransferKey
|
||||||
import qualified Command.TransferKeys
|
import qualified Command.TransferKeys
|
||||||
|
|
|
@ -49,7 +49,7 @@ massAdd = go True =<< map words . lines <$> liftIO getContents
|
||||||
ok <- perform' key f
|
ok <- perform' key f
|
||||||
let !status' = status && ok
|
let !status' = status && ok
|
||||||
go status' rest
|
go status' rest
|
||||||
go status (_:rest) = error "Expected pairs of key and file on stdin, but got something else."
|
go _ _ = error "Expected pairs of key and file on stdin, but got something else."
|
||||||
|
|
||||||
perform :: Key -> FilePath -> CommandPerform
|
perform :: Key -> FilePath -> CommandPerform
|
||||||
perform key file = do
|
perform key file = do
|
||||||
|
|
55
Command/RegisterUrl.hs
Normal file
55
Command/RegisterUrl.hs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
{- git-annex command
|
||||||
|
-
|
||||||
|
- Copyright 2015 Joey Hess <id@joeyh.name>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE BangPatterns #-}
|
||||||
|
|
||||||
|
module Command.RegisterUrl where
|
||||||
|
|
||||||
|
import Common.Annex
|
||||||
|
import Command
|
||||||
|
import Types.Key
|
||||||
|
import Logs.Web
|
||||||
|
import Annex.UUID
|
||||||
|
|
||||||
|
cmd :: [Command]
|
||||||
|
cmd = [notDirect $ notBareRepo $
|
||||||
|
command "registerurl" (paramPair paramKey paramUrl) seek
|
||||||
|
SectionPlumbing "registers an url for a key"]
|
||||||
|
|
||||||
|
seek :: CommandSeek
|
||||||
|
seek = withWords start
|
||||||
|
|
||||||
|
start :: [String] -> CommandStart
|
||||||
|
start (keyname:url:[]) = do
|
||||||
|
let key = fromMaybe (error "bad key") $ file2key keyname
|
||||||
|
showStart "registerurl" url
|
||||||
|
next $ perform key url
|
||||||
|
start [] = do
|
||||||
|
showStart "registerurl" "stdin"
|
||||||
|
next massAdd
|
||||||
|
start _ = error "specify a key and an url"
|
||||||
|
|
||||||
|
massAdd :: CommandPerform
|
||||||
|
massAdd = go True =<< map words . lines <$> liftIO getContents
|
||||||
|
where
|
||||||
|
go status [] = next $ return status
|
||||||
|
go status ([keyname,u]:rest) = do
|
||||||
|
let key = fromMaybe (error $ "bad key " ++ keyname) $ file2key keyname
|
||||||
|
ok <- perform' key u
|
||||||
|
let !status' = status && ok
|
||||||
|
go status' rest
|
||||||
|
go _ _ = error "Expected pairs of key and url on stdin, but got something else."
|
||||||
|
|
||||||
|
perform :: Key -> URLString -> CommandPerform
|
||||||
|
perform key url = do
|
||||||
|
ok <- perform' key url
|
||||||
|
next $ return ok
|
||||||
|
|
||||||
|
perform' :: Key -> URLString -> Annex Bool
|
||||||
|
perform' key url = do
|
||||||
|
setUrlPresent webUUID key url
|
||||||
|
return True
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -37,6 +37,7 @@ git-annex (5.2015022) UNRELEASED; urgency=medium
|
||||||
doesn't exist or git config fails for some reason.
|
doesn't exist or git config fails for some reason.
|
||||||
* fromkey --force: Skip test that the key has its content in the annex.
|
* fromkey --force: Skip test that the key has its content in the annex.
|
||||||
* fromkey: Add stdin mode.
|
* fromkey: Add stdin mode.
|
||||||
|
* registerurl: New plumbing command for mass-adding urls to keys.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Thu, 19 Feb 2015 14:16:03 -0400
|
-- Joey Hess <id@joeyh.name> Thu, 19 Feb 2015 14:16:03 -0400
|
||||||
|
|
||||||
|
|
|
@ -964,6 +964,17 @@ subdirectories).
|
||||||
instead read from stdin. Any number of lines can be provided in this
|
instead read from stdin. Any number of lines can be provided in this
|
||||||
mode, each containing a key and filename, sepearated by whitespace.
|
mode, each containing a key and filename, sepearated by whitespace.
|
||||||
|
|
||||||
|
* `registerurl [key url]`
|
||||||
|
|
||||||
|
This plumbing-level command can be used to register urls where a
|
||||||
|
key can be downloaded from.
|
||||||
|
|
||||||
|
No verification is performed of the url's contents.
|
||||||
|
|
||||||
|
If the key and url are not specified on the command line, they are
|
||||||
|
instead read from stdin. Any number of lines can be provided in this
|
||||||
|
mode, each containing a key and url, sepearated by whitespace.
|
||||||
|
|
||||||
* `dropkey [key ...]`
|
* `dropkey [key ...]`
|
||||||
|
|
||||||
This plumbing-level command drops the annexed data for the specified
|
This plumbing-level command drops the annexed data for the specified
|
||||||
|
|
Loading…
Add table
Reference in a new issue