slashes.
"""
-class RmOptions(VDriveOptions):
+class UnlinkOptions(VDriveOptions):
def parseArgs(self, where):
self.where = argv_to_unicode(where)
def getSynopsis(self):
- return "Usage: %s rm [options] REMOTE_FILE" % (self.command_name,)
+ return "Usage: %s unlink [options] REMOTE_FILE" % (self.command_name,)
-class UnlinkOptions(RmOptions):
+class RmOptions(UnlinkOptions):
def getSynopsis(self):
- return "Usage: %s unlink [options] REMOTE_FILE" % (self.command_name,)
+ return "Usage: %s rm [options] REMOTE_FILE" % (self.command_name,)
class MvOptions(VDriveOptions):
def parseArgs(self, frompath, topath):
["get", None, GetOptions, "Retrieve a file from the grid."],
["put", None, PutOptions, "Upload a file into the grid."],
["cp", None, CpOptions, "Copy one or more files or directories."],
- ["rm", None, RmOptions, "Unlink a file or directory on the grid."],
- ["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid (same as rm)."],
+ ["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid."],
+ ["rm", None, RmOptions, "Unlink a file or directory on the grid (same as unlink)."],
["mv", None, MvOptions, "Move a file within the grid."],
["ln", None, LnOptions, "Make an additional link to an existing file or directory."],
["backup", None, BackupOptions, "Make target dir look like local dir."],
rc = tahoe_cp.copy(options)
return rc
-def rm(options):
- from allmydata.scripts import tahoe_rm
- rc = tahoe_rm.rm(options)
+def unlink(options, command="unlink"):
+ from allmydata.scripts import tahoe_unlink
+ rc = tahoe_unlink.unlink(options, command=command)
return rc
+def rm(options):
+ return unlink(options, command="rm")
+
def mv(options):
from allmydata.scripts import tahoe_mv
rc = tahoe_mv.mv(options, mode="move")
"get": get,
"put": put,
"cp": cp,
+ "unlink": unlink,
"rm": rm,
- "unlink": rm,
"mv": mv,
"ln": ln,
"backup": backup,
+++ /dev/null
-
-import urllib
-from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
-from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
- UnknownAliasError
-
-def rm(options):
- """
- @return: a Deferred which eventually fires with the exit code
- """
- nodeurl = options['node-url']
- aliases = options.aliases
- where = options.where
- stdout = options.stdout
- stderr = options.stderr
-
- if nodeurl[-1] != "/":
- nodeurl += "/"
- try:
- rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
- except UnknownAliasError, e:
- e.display(stderr)
- return 1
- if not path:
- print >>stderr, """
-'tahoe rm' can only unlink directory entries, so a path must be given."""
- return 1
-
- url = nodeurl + "uri/%s" % urllib.quote(rootcap)
- url += "/" + escape_path(path)
-
- resp = do_http("DELETE", url)
-
- if resp.status in (200,):
- print >>stdout, format_http_success(resp)
- return 0
-
- print >>stderr, format_http_error("ERROR", resp)
- return 1
--- /dev/null
+
+import urllib
+from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
+from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
+ UnknownAliasError
+
+def unlink(options, command="unlink"):
+ """
+ @return: a Deferred which eventually fires with the exit code
+ """
+ nodeurl = options['node-url']
+ aliases = options.aliases
+ where = options.where
+ stdout = options.stdout
+ stderr = options.stderr
+
+ if nodeurl[-1] != "/":
+ nodeurl += "/"
+ try:
+ rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
+ except UnknownAliasError, e:
+ e.display(stderr)
+ return 1
+ if not path:
+ print >>stderr, """
+'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,)
+ return 1
+
+ url = nodeurl + "uri/%s" % urllib.quote(rootcap)
+ url += "/" + escape_path(path)
+
+ resp = do_http("DELETE", url)
+
+ if resp.status in (200,):
+ print >>stdout, format_http_success(resp)
+ return 0
+
+ print >>stderr, format_http_error("ERROR", resp)
+ return 1
# Test that the scripts can be imported.
from allmydata.scripts import create_node, debug, keygen, startstop_node, \
tahoe_add_alias, tahoe_backup, tahoe_check, tahoe_cp, tahoe_get, tahoe_ls, \
- tahoe_manifest, tahoe_mkdir, tahoe_mv, tahoe_put, tahoe_rm, tahoe_webopen
+ tahoe_manifest, tahoe_mkdir, tahoe_mv, tahoe_put, tahoe_unlink, tahoe_webopen
_hush_pyflakes = [create_node, debug, keygen, startstop_node,
tahoe_add_alias, tahoe_backup, tahoe_check, tahoe_cp, tahoe_get, tahoe_ls,
- tahoe_manifest, tahoe_mkdir, tahoe_mv, tahoe_put, tahoe_rm, tahoe_webopen]
+ tahoe_manifest, tahoe_mkdir, tahoe_mv, tahoe_put, tahoe_unlink, tahoe_webopen]
from allmydata.scripts import common
from allmydata.scripts.common import DEFAULT_ALIAS, get_aliases, get_alias, \
return d
-class Rm(GridTestMixin, CLITestMixin, unittest.TestCase):
+class Unlink(GridTestMixin, CLITestMixin, unittest.TestCase):
+ command = "unlink"
+
def _create_test_file(self):
data = "puppies" * 1000
path = os.path.join(self.basedir, "datafile")
fileutil.write(path, data)
self.datafile = path
- def test_rm_without_alias(self):
- # 'tahoe rm' should behave sensibly when invoked without an explicit
+ def test_unlink_without_alias(self):
+ # 'tahoe unlink' should behave sensibly when invoked without an explicit
# alias before the default 'tahoe' alias has been created.
- self.basedir = "cli/Rm/rm_without_alias"
+ self.basedir = "cli/Unlink/%s_without_alias" % (self.command,)
self.set_up_grid()
- d = self.do_cli("rm", "afile")
+ d = self.do_cli(self.command, "afile")
def _check((rc, out, err)):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
d.addCallback(_check)
- d.addCallback(lambda ign: self.do_cli("unlink", "afile"))
+ d.addCallback(lambda ign: self.do_cli(self.command, "afile"))
d.addCallback(_check)
return d
- def test_rm_with_nonexistent_alias(self):
- # 'tahoe rm' should behave sensibly when invoked with an explicit
+ def test_unlink_with_nonexistent_alias(self):
+ # 'tahoe unlink' should behave sensibly when invoked with an explicit
# alias that doesn't exist.
- self.basedir = "cli/Rm/rm_with_nonexistent_alias"
+ self.basedir = "cli/Unlink/%s_with_nonexistent_alias" % (self.command,)
self.set_up_grid()
- d = self.do_cli("rm", "nonexistent:afile")
+ d = self.do_cli(self.command, "nonexistent:afile")
def _check((rc, out, err)):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
d.addCallback(_check)
- d.addCallback(lambda ign: self.do_cli("unlink", "nonexistent:afile"))
+ d.addCallback(lambda ign: self.do_cli(self.command, "nonexistent:afile"))
d.addCallback(_check)
return d
- def test_rm_without_path(self):
- # 'tahoe rm' should give a sensible error message when invoked without a path.
- self.basedir = "cli/Rm/rm_without_path"
+ def test_unlink_without_path(self):
+ # 'tahoe unlink' should give a sensible error message when invoked without a path.
+ self.basedir = "cli/Unlink/%s_without_path" % (self.command,)
self.set_up_grid()
self._create_test_file()
d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda ign: self.do_cli("put", self.datafile, "tahoe:test"))
- def _do_rm((rc, out, err)):
+ def _do_unlink((rc, out, err)):
self.failUnlessReallyEqual(rc, 0)
self.failUnless(out.startswith("URI:"), out)
- return self.do_cli("rm", out.strip('\n'))
- d.addCallback(_do_rm)
+ return self.do_cli(self.command, out.strip('\n'))
+ d.addCallback(_do_unlink)
def _check((rc, out, err)):
self.failUnlessReallyEqual(rc, 1)
+ self.failUnlessIn("'tahoe %s'" % (self.command,), err)
self.failUnlessIn("path must be given", err)
self.failUnlessReallyEqual(out, "")
d.addCallback(_check)
return d
+class Rm(Unlink):
+ """Test that 'tahoe rm' behaves in the same way as 'tahoe unlink'."""
+ command = "rm"
+
+
class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
def test_empty_directory(self):
self.basedir = "cli/Stats/empty_directory"