mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 11:16:24 +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):
|
def getSynopsis(self):
|
||||||
return "%s mv FROM TO" % (os.path.basename(sys.argv[0]),)
|
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):
|
class WebopenOptions(VDriveOptions):
|
||||||
def parseArgs(self, vdrive_pathname=""):
|
def parseArgs(self, vdrive_pathname=""):
|
||||||
self['vdrive_pathname'] = vdrive_pathname
|
self['vdrive_pathname'] = vdrive_pathname
|
||||||
@ -177,6 +185,7 @@ subCommands = [
|
|||||||
["put", None, PutOptions, "Upload a file into the virtual drive."],
|
["put", None, PutOptions, "Upload a file into the virtual drive."],
|
||||||
["rm", None, RmOptions, "Unlink a file or directory in 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."],
|
["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"],
|
["webopen", None, WebopenOptions, "Open a webbrowser to the root_dir"],
|
||||||
["repl", None, ReplOptions, "Open a python interpreter"],
|
["repl", None, ReplOptions, "Open a python interpreter"],
|
||||||
]
|
]
|
||||||
@ -258,7 +267,18 @@ def mv(config, stdout, stderr):
|
|||||||
config.aliases,
|
config.aliases,
|
||||||
config.from_file,
|
config.from_file,
|
||||||
config.to_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
|
return rc
|
||||||
|
|
||||||
def webopen(config, stdout, stderr):
|
def webopen(config, stdout, stderr):
|
||||||
@ -284,6 +304,7 @@ dispatch = {
|
|||||||
"put": put,
|
"put": put,
|
||||||
"rm": rm,
|
"rm": rm,
|
||||||
"mv": mv,
|
"mv": mv,
|
||||||
|
"ln": ln,
|
||||||
"webopen": webopen,
|
"webopen": webopen,
|
||||||
"repl": repl,
|
"repl": repl,
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ import simplejson
|
|||||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
|
||||||
from allmydata.scripts.common_http import do_http
|
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] != "/":
|
if nodeurl[-1] != "/":
|
||||||
nodeurl += "/"
|
nodeurl += "/"
|
||||||
rootcap, path = get_alias(aliases, from_file, DEFAULT_ALIAS)
|
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)):
|
if not re.search(r'^2\d\d$', str(status)):
|
||||||
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
||||||
print >>stderr, resp.read()
|
print >>stderr, resp.read()
|
||||||
print >>stderr, "NOT removing the original"
|
if mode == "move":
|
||||||
|
print >>stderr, "NOT removing the original"
|
||||||
return
|
return
|
||||||
|
|
||||||
# now remove the original
|
if mode == "move":
|
||||||
resp = do_http("DELETE", from_url)
|
# now remove the original
|
||||||
if not re.search(r'^2\d\d$', str(status)):
|
resp = do_http("DELETE", from_url)
|
||||||
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
if not re.search(r'^2\d\d$', str(status)):
|
||||||
print >>stderr, resp.read()
|
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
||||||
|
print >>stderr, resp.read()
|
||||||
|
|
||||||
print >>stdout, "OK"
|
print >>stdout, "OK"
|
||||||
return
|
return
|
||||||
|
@ -1699,6 +1699,10 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
|
|||||||
d.addCallback(run, "ls")
|
d.addCallback(run, "ls")
|
||||||
d.addCallback(_check_ls, ["tahoe-moved"], ["tahoe-file-stdin"])
|
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
|
# tahoe_ls doesn't currently handle the error correctly: it tries to
|
||||||
# JSON-parse a traceback.
|
# JSON-parse a traceback.
|
||||||
## def _ls_missing(res):
|
## def _ls_missing(res):
|
||||||
|
Loading…
Reference in New Issue
Block a user