mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
CLI: add 'ln', just like move but without the delete
This commit is contained in:
parent
f09f92c371
commit
1236bc3408
@ -160,6 +160,14 @@ class MvOptions(VDriveOptions):
|
||||
def getSynopsis(self):
|
||||
return "%s mv FROM TO" % (os.path.basename(sys.argv[0]),)
|
||||
|
||||
class LnOptions(VDriveOptions):
|
||||
def parseArgs(self, frompath, topath):
|
||||
self.from_file = frompath
|
||||
self.to_file = topath
|
||||
|
||||
def getSynopsis(self):
|
||||
return "%s ln FROM TO" % (os.path.basename(sys.argv[0]),)
|
||||
|
||||
class WebopenOptions(VDriveOptions):
|
||||
def parseArgs(self, vdrive_pathname=""):
|
||||
self['vdrive_pathname'] = vdrive_pathname
|
||||
@ -177,6 +185,7 @@ subCommands = [
|
||||
["put", None, PutOptions, "Upload a file into the virtual drive."],
|
||||
["rm", None, RmOptions, "Unlink a file or directory in the virtual drive."],
|
||||
["mv", None, MvOptions, "Move a file within the virtual drive."],
|
||||
["ln", None, LnOptions, "Make an additional link to an existing file."],
|
||||
["webopen", None, WebopenOptions, "Open a webbrowser to the root_dir"],
|
||||
["repl", None, ReplOptions, "Open a python interpreter"],
|
||||
]
|
||||
@ -258,7 +267,18 @@ def mv(config, stdout, stderr):
|
||||
config.aliases,
|
||||
config.from_file,
|
||||
config.to_file,
|
||||
stdout, stderr)
|
||||
stdout, stderr,
|
||||
mode="move")
|
||||
return rc
|
||||
|
||||
def ln(config, stdout, stderr):
|
||||
from allmydata.scripts import tahoe_mv
|
||||
rc = tahoe_mv.mv(config['node-url'],
|
||||
config.aliases,
|
||||
config.from_file,
|
||||
config.to_file,
|
||||
stdout, stderr,
|
||||
mode="link")
|
||||
return rc
|
||||
|
||||
def webopen(config, stdout, stderr):
|
||||
@ -284,6 +304,7 @@ dispatch = {
|
||||
"put": put,
|
||||
"rm": rm,
|
||||
"mv": mv,
|
||||
"ln": ln,
|
||||
"webopen": webopen,
|
||||
"repl": repl,
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import simplejson
|
||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
|
||||
from allmydata.scripts.common_http import do_http
|
||||
|
||||
def mv(nodeurl, aliases, from_file, to_file, stdout, stderr):
|
||||
# this script is used for both 'mv' and 'ln'
|
||||
|
||||
def mv(nodeurl, aliases, from_file, to_file, stdout, stderr, mode="move"):
|
||||
if nodeurl[-1] != "/":
|
||||
nodeurl += "/"
|
||||
rootcap, path = get_alias(aliases, from_file, DEFAULT_ALIAS)
|
||||
@ -35,14 +37,16 @@ def mv(nodeurl, aliases, from_file, to_file, stdout, stderr):
|
||||
if not re.search(r'^2\d\d$', str(status)):
|
||||
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
||||
print >>stderr, resp.read()
|
||||
print >>stderr, "NOT removing the original"
|
||||
if mode == "move":
|
||||
print >>stderr, "NOT removing the original"
|
||||
return
|
||||
|
||||
# now remove the original
|
||||
resp = do_http("DELETE", from_url)
|
||||
if not re.search(r'^2\d\d$', str(status)):
|
||||
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
||||
print >>stderr, resp.read()
|
||||
if mode == "move":
|
||||
# now remove the original
|
||||
resp = do_http("DELETE", from_url)
|
||||
if not re.search(r'^2\d\d$', str(status)):
|
||||
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
||||
print >>stderr, resp.read()
|
||||
|
||||
print >>stdout, "OK"
|
||||
return
|
||||
|
@ -1699,6 +1699,10 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
|
||||
d.addCallback(run, "ls")
|
||||
d.addCallback(_check_ls, ["tahoe-moved"], ["tahoe-file-stdin"])
|
||||
|
||||
d.addCallback(run, "ln", "tahoe-moved", "newlink")
|
||||
d.addCallback(run, "ls")
|
||||
d.addCallback(_check_ls, ["tahoe-moved", "newlink"])
|
||||
|
||||
# tahoe_ls doesn't currently handle the error correctly: it tries to
|
||||
# JSON-parse a traceback.
|
||||
## def _ls_missing(res):
|
||||
|
Loading…
Reference in New Issue
Block a user