From 1236bc3408c7625ed72c55f532f60d3787ee3682 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 20 May 2008 13:30:31 -0700 Subject: [PATCH] CLI: add 'ln', just like move but without the delete --- src/allmydata/scripts/cli.py | 23 ++++++++++++++++++++++- src/allmydata/scripts/tahoe_mv.py | 18 +++++++++++------- src/allmydata/test/test_system.py | 4 ++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 56a1b88e..f965e24b 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -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, } diff --git a/src/allmydata/scripts/tahoe_mv.py b/src/allmydata/scripts/tahoe_mv.py index d3867d8a..41bb5fd9 100644 --- a/src/allmydata/scripts/tahoe_mv.py +++ b/src/allmydata/scripts/tahoe_mv.py @@ -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 diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 843bff7f..00b4891d 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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): -- 2.45.2