2019-03-24 13:14:00 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2011-07-28 02:14:02 +00:00
|
|
|
import os.path, re, fnmatch
|
2007-07-11 02:37:37 +00:00
|
|
|
from twisted.python import usage
|
2012-06-18 17:43:49 +00:00
|
|
|
from allmydata.scripts.common import get_aliases, get_default_nodedir, \
|
|
|
|
DEFAULT_ALIAS, BaseOptions
|
2015-01-30 00:04:11 +00:00
|
|
|
from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_local_unicode_path
|
2016-10-19 05:17:48 +00:00
|
|
|
from .tahoe_status import TahoeStatusCommand
|
2007-07-11 02:37:37 +00:00
|
|
|
|
2010-04-30 18:56:09 +00:00
|
|
|
NODEURL_RE=re.compile("http(s?)://([^:]*)(:([1-9][0-9]*))?")
|
2007-08-17 19:54:47 +00:00
|
|
|
|
2010-08-02 04:30:04 +00:00
|
|
|
_default_nodedir = get_default_nodedir()
|
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class FileStoreOptions(BaseOptions):
|
2007-07-11 02:37:37 +00:00
|
|
|
optParameters = [
|
2007-08-16 23:53:27 +00:00
|
|
|
["node-url", "u", None,
|
2012-06-18 17:43:49 +00:00
|
|
|
"Specify the URL of the Tahoe gateway node, such as "
|
|
|
|
"'http://127.0.0.1:3456'. "
|
2007-10-11 07:30:36 +00:00
|
|
|
"This overrides the URL found in the --node-directory ."],
|
2008-05-22 00:55:32 +00:00
|
|
|
["dir-cap", None, None,
|
2010-08-03 08:48:01 +00:00
|
|
|
"Specify which dirnode URI should be used as the 'tahoe' alias."]
|
2007-07-11 02:37:37 +00:00
|
|
|
]
|
|
|
|
|
2007-08-17 19:54:47 +00:00
|
|
|
def postOptions(self):
|
2012-06-18 17:43:49 +00:00
|
|
|
self["quiet"] = self.parent["quiet"]
|
|
|
|
if self.parent['node-directory']:
|
|
|
|
self['node-directory'] = argv_to_abspath(self.parent['node-directory'])
|
2010-08-02 04:30:04 +00:00
|
|
|
else:
|
|
|
|
self['node-directory'] = _default_nodedir
|
|
|
|
|
|
|
|
# compute a node-url from the existing options, put in self['node-url']
|
2007-10-11 07:30:36 +00:00
|
|
|
if self['node-url']:
|
|
|
|
if (not isinstance(self['node-url'], basestring)
|
|
|
|
or not NODEURL_RE.match(self['node-url'])):
|
|
|
|
msg = ("--node-url is required to be a string and look like "
|
|
|
|
"\"http://HOSTNAMEORADDR:PORT\", not: %r" %
|
|
|
|
(self['node-url'],))
|
|
|
|
raise usage.UsageError(msg)
|
|
|
|
else:
|
|
|
|
node_url_file = os.path.join(self['node-directory'], "node.url")
|
|
|
|
self['node-url'] = open(node_url_file, "r").read().strip()
|
2009-02-03 04:08:56 +00:00
|
|
|
if self['node-url'][-1] != "/":
|
|
|
|
self['node-url'] += "/"
|
2007-10-11 07:30:36 +00:00
|
|
|
|
2008-05-20 21:36:04 +00:00
|
|
|
aliases = get_aliases(self['node-directory'])
|
2008-05-20 02:28:50 +00:00
|
|
|
if self['dir-cap']:
|
2010-08-02 04:30:04 +00:00
|
|
|
aliases[DEFAULT_ALIAS] = self['dir-cap']
|
2008-05-20 02:28:50 +00:00
|
|
|
self.aliases = aliases # maps alias name to dircap
|
|
|
|
|
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class MakeDirectoryOptions(FileStoreOptions):
|
2011-08-02 02:16:13 +00:00
|
|
|
optParameters = [
|
2011-10-14 03:45:59 +00:00
|
|
|
("format", None, None, "Create a directory with the given format: SDMF or MDMF (case-insensitive)"),
|
2011-08-02 02:16:13 +00:00
|
|
|
]
|
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
def parseArgs(self, where=""):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2011-07-24 22:54:40 +00:00
|
|
|
|
2011-10-14 03:15:00 +00:00
|
|
|
if self['format']:
|
2011-10-14 03:45:59 +00:00
|
|
|
if self['format'].upper() not in ("SDMF", "MDMF"):
|
2011-10-14 03:15:00 +00:00
|
|
|
raise usage.UsageError("%s is an invalid format" % self['format'])
|
2011-08-02 02:16:13 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [REMOTE_DIR]"
|
|
|
|
description = """Create a new directory, either unlinked or as a subdirectory."""
|
2008-05-20 02:28:50 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class AddAliasOptions(FileStoreOptions):
|
2008-05-20 02:28:50 +00:00
|
|
|
def parseArgs(self, alias, cap):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.alias = argv_to_unicode(alias)
|
2011-01-14 03:44:14 +00:00
|
|
|
if self.alias.endswith(u':'):
|
|
|
|
self.alias = self.alias[:-1]
|
2008-05-20 02:28:50 +00:00
|
|
|
self.cap = cap
|
2007-10-11 07:30:36 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] ALIAS[:] DIRCAP"
|
|
|
|
description = """Add a new alias for an existing directory."""
|
2009-02-21 01:31:06 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class CreateAliasOptions(FileStoreOptions):
|
2008-08-02 02:10:41 +00:00
|
|
|
def parseArgs(self, alias):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.alias = argv_to_unicode(alias)
|
2011-01-14 03:44:14 +00:00
|
|
|
if self.alias.endswith(u':'):
|
|
|
|
self.alias = self.alias[:-1]
|
2008-08-02 02:10:41 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] ALIAS[:]"
|
|
|
|
description = """Create a new directory and add an alias for it."""
|
2009-02-21 01:31:06 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class ListAliasesOptions(FileStoreOptions):
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options]"
|
|
|
|
description = """Display a table of all configured aliases."""
|
2017-01-16 20:34:26 +00:00
|
|
|
optFlags = [
|
|
|
|
("readonly-uri", None, "Show read-only dircaps instead of readwrite"),
|
2017-01-16 21:20:23 +00:00
|
|
|
("json", None, "Show JSON output"),
|
2017-01-16 20:34:26 +00:00
|
|
|
]
|
2008-05-20 21:36:04 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class ListOptions(FileStoreOptions):
|
2008-05-20 02:28:50 +00:00
|
|
|
optFlags = [
|
2010-08-03 08:48:01 +00:00
|
|
|
("long", "l", "Use long format: show file sizes, and timestamps."),
|
2016-02-02 18:45:52 +00:00
|
|
|
("uri", None, "Show file/directory URIs."),
|
2010-08-03 08:48:01 +00:00
|
|
|
("readonly-uri", None, "Show read-only file/directory URIs."),
|
|
|
|
("classify", "F", "Append '/' to directory names, and '*' to mutable."),
|
|
|
|
("json", None, "Show the raw JSON output."),
|
2008-05-20 02:28:50 +00:00
|
|
|
]
|
|
|
|
def parseArgs(self, where=""):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2007-07-11 02:37:37 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [PATH]"
|
2012-11-01 23:40:06 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-02-20 06:13:13 +00:00
|
|
|
List the contents of some portion of the grid.
|
|
|
|
|
2012-11-01 23:40:06 +00:00
|
|
|
If PATH is omitted, "tahoe:" is assumed.
|
|
|
|
|
2010-02-20 06:13:13 +00:00
|
|
|
When the -l or --long option is used, each line is shown in the
|
|
|
|
following format:
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
drwx <size> <date/time> <name in this directory>
|
2010-02-20 06:13:13 +00:00
|
|
|
|
|
|
|
where each of the letters on the left may be replaced by '-'.
|
|
|
|
If 'd' is present, it indicates that the object is a directory.
|
|
|
|
If the 'd' is replaced by a '?', the object type is unknown.
|
|
|
|
'rwx' is a Unix-like permissions mask: if the mask includes 'w',
|
2010-02-24 03:02:31 +00:00
|
|
|
then the object is writeable through its link in this directory
|
|
|
|
(note that the link might be replaceable even if the object is
|
|
|
|
not writeable through the current link).
|
2010-02-20 06:13:13 +00:00
|
|
|
The 'x' is a legacy of Unix filesystems. In Tahoe it is used
|
|
|
|
only to indicate that the contents of a directory can be listed.
|
|
|
|
|
|
|
|
Directories have no size, so their size field is shown as '-'.
|
|
|
|
Otherwise the size of the file, when known, is given in bytes.
|
|
|
|
The size of mutable files or unknown objects is shown as '?'.
|
|
|
|
|
2014-12-01 21:52:16 +00:00
|
|
|
The date/time shows when this link in the Tahoe grid was last
|
|
|
|
modified.
|
2010-02-20 06:13:13 +00:00
|
|
|
"""
|
2007-08-16 19:50:19 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class GetOptions(FileStoreOptions):
|
2008-05-20 02:28:50 +00:00
|
|
|
def parseArgs(self, arg1, arg2=None):
|
|
|
|
# tahoe get FOO |less # write to stdout
|
|
|
|
# tahoe get tahoe:FOO |less # same
|
|
|
|
# tahoe get FOO bar # write to local file
|
|
|
|
# tahoe get tahoe:FOO bar # same
|
|
|
|
|
2015-01-30 00:50:18 +00:00
|
|
|
if arg2 == "-":
|
|
|
|
arg2 = None
|
2010-05-20 00:43:56 +00:00
|
|
|
|
2015-01-30 00:50:18 +00:00
|
|
|
self.from_file = argv_to_unicode(arg1)
|
|
|
|
self.to_file = None if arg2 is None else argv_to_abspath(arg2)
|
2007-07-11 02:37:37 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] REMOTE_FILE LOCAL_FILE"
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Retrieve a file from the grid and write it to the local filesystem. If
|
|
|
|
LOCAL_FILE is omitted or '-', the contents of the file will be written to
|
|
|
|
stdout."""
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description_unwrapped = """
|
|
|
|
Examples:
|
|
|
|
% tahoe get FOO |less # write to stdout
|
|
|
|
% tahoe get tahoe:FOO |less # same
|
|
|
|
% tahoe get FOO bar # write to local file
|
|
|
|
% tahoe get tahoe:FOO bar # same
|
|
|
|
"""
|
2008-06-03 00:54:56 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class PutOptions(FileStoreOptions):
|
2008-05-20 19:36:55 +00:00
|
|
|
optFlags = [
|
2011-10-14 03:45:59 +00:00
|
|
|
("mutable", "m", "Create a mutable file instead of an immutable one (like --format=SDMF)"),
|
2008-05-20 19:36:55 +00:00
|
|
|
]
|
2011-08-02 02:16:13 +00:00
|
|
|
optParameters = [
|
2011-10-14 03:45:59 +00:00
|
|
|
("format", None, None, "Create a file with the given format: SDMF and MDMF for mutable, CHK (default) for immutable. (case-insensitive)"),
|
2011-08-02 02:16:13 +00:00
|
|
|
]
|
2008-05-20 19:36:55 +00:00
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
def parseArgs(self, arg1=None, arg2=None):
|
2010-01-14 20:11:19 +00:00
|
|
|
# see Examples below
|
2008-05-20 02:28:50 +00:00
|
|
|
|
2015-01-30 00:50:18 +00:00
|
|
|
if arg1 == "-":
|
|
|
|
arg1 = None
|
|
|
|
|
|
|
|
self.from_file = None if arg1 is None else argv_to_abspath(arg1)
|
|
|
|
self.to_file = None if arg2 is None else argv_to_unicode(arg2)
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2011-10-14 03:15:00 +00:00
|
|
|
if self['format']:
|
|
|
|
if self['format'].upper() not in ("SDMF", "MDMF", "CHK"):
|
|
|
|
raise usage.UsageError("%s is an invalid format" % self['format'])
|
2011-09-03 19:09:20 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] LOCAL_FILE REMOTE_FILE"
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Put a file into the grid, copying its contents from the local filesystem.
|
|
|
|
If REMOTE_FILE is missing, upload the file but do not link it into a
|
|
|
|
directory; also print the new filecap to stdout. If LOCAL_FILE is missing
|
|
|
|
or '-', data will be copied from stdin. REMOTE_FILE is assumed to start
|
2013-03-20 01:27:17 +00:00
|
|
|
with tahoe: unless otherwise specified.
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
If the destination file already exists and is mutable, it will be
|
|
|
|
modified in-place, whether or not --mutable is specified. (--mutable only
|
|
|
|
affects creation of new files.)
|
|
|
|
"""
|
|
|
|
|
|
|
|
description_unwrapped = """
|
|
|
|
Examples:
|
|
|
|
% cat FILE | tahoe put # create unlinked file from stdin
|
|
|
|
% cat FILE | tahoe put - # same
|
|
|
|
% tahoe put bar # create unlinked file from local 'bar'
|
|
|
|
% cat FILE | tahoe put - FOO # create tahoe:FOO from stdin
|
|
|
|
% tahoe put bar FOO # copy local 'bar' to tahoe:FOO
|
|
|
|
% tahoe put bar tahoe:FOO # same
|
|
|
|
% tahoe put bar MUTABLE-FILE-WRITECAP # modify the mutable file in-place
|
|
|
|
"""
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class CpOptions(FileStoreOptions):
|
2008-05-20 23:56:03 +00:00
|
|
|
optFlags = [
|
|
|
|
("recursive", "r", "Copy source directory recursively."),
|
2008-05-22 00:35:21 +00:00
|
|
|
("verbose", "v", "Be noisy about what is happening."),
|
2009-03-15 23:19:58 +00:00
|
|
|
("caps-only", None,
|
|
|
|
"When copying to local files, write out filecaps instead of actual "
|
2010-01-14 20:11:19 +00:00
|
|
|
"data (only useful for debugging and tree-comparison purposes)."),
|
2008-05-20 23:56:03 +00:00
|
|
|
]
|
2011-07-24 22:54:40 +00:00
|
|
|
|
2008-05-20 23:56:03 +00:00
|
|
|
def parseArgs(self, *args):
|
|
|
|
if len(args) < 2:
|
|
|
|
raise usage.UsageError("cp requires at least two arguments")
|
2010-05-20 00:43:56 +00:00
|
|
|
self.sources = map(argv_to_unicode, args[:-1])
|
|
|
|
self.destination = argv_to_unicode(args[-1])
|
2011-07-24 22:54:40 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] FROM.. TO"
|
2011-07-24 22:54:40 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Use 'tahoe cp' to copy files between a local filesystem and a Tahoe grid.
|
|
|
|
Any FROM/TO arguments that begin with an alias indicate Tahoe-side
|
|
|
|
files or non-file arguments. Directories will be copied recursively.
|
|
|
|
New Tahoe-side directories will be created when necessary. Assuming that
|
|
|
|
you have previously set up an alias 'home' with 'tahoe create-alias home',
|
|
|
|
here are some examples:
|
2009-06-25 23:57:51 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
tahoe cp ~/foo.txt home: # creates tahoe-side home:foo.txt
|
2009-06-25 23:57:51 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
tahoe cp ~/foo.txt /tmp/bar.txt home: # copies two files to home:
|
2009-06-25 23:57:51 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
tahoe cp ~/Pictures home:stuff/my-pictures # copies directory recursively
|
2009-06-25 23:57:51 +00:00
|
|
|
|
2009-06-26 05:26:27 +00:00
|
|
|
You can also use a dircap as either FROM or TO target:
|
2009-06-26 05:16:52 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
tahoe cp URI:DIR2-RO:ixqhc4kdbjxc7o65xjnveoewym:5x6lwoxghrd5rxhwunzavft2qygfkt27oj3fbxlq4c6p45z5uneq/blog.html ./ # copy Zooko's wiki page to a local file
|
2009-06-26 05:16:52 +00:00
|
|
|
|
2010-11-30 00:21:45 +00:00
|
|
|
This command still has some limitations: symlinks and special files
|
|
|
|
(device nodes, named pipes) are not handled very well. Arguments should
|
2015-05-04 04:49:34 +00:00
|
|
|
not have trailing slashes (they are ignored for directory arguments, but
|
|
|
|
trigger errors for file arguments). When copying directories, it can be
|
|
|
|
unclear whether you mean to copy the contents of a source directory, or
|
|
|
|
the source directory itself (i.e. whether the output goes under the
|
|
|
|
target directory, or one directory lower). Tahoe's rule is that source
|
|
|
|
directories with names are referring to the directory as a whole, and
|
|
|
|
source directories without names (e.g. a raw dircap) are referring to the
|
|
|
|
contents.
|
2009-06-25 23:57:51 +00:00
|
|
|
"""
|
2008-05-20 23:56:03 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class UnlinkOptions(FileStoreOptions):
|
2008-05-20 02:28:50 +00:00
|
|
|
def parseArgs(self, where):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] REMOTE_FILE"
|
|
|
|
description = "Remove a named file from its parent directory."
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class MvOptions(FileStoreOptions):
|
2007-10-12 03:31:48 +00:00
|
|
|
def parseArgs(self, frompath, topath):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_file = argv_to_unicode(frompath)
|
|
|
|
self.to_file = argv_to_unicode(topath)
|
2007-10-12 03:31:48 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] FROM TO"
|
2011-07-24 22:54:40 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Use 'tahoe mv' to move files that are already on the grid elsewhere on
|
|
|
|
the grid, e.g., 'tahoe mv alias:some_file alias:new_file'.
|
2009-07-20 03:45:03 +00:00
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
If moving a remote file into a remote directory, you'll need to append a
|
|
|
|
'/' to the name of the remote directory, e.g., 'tahoe mv tahoe:file1
|
|
|
|
tahoe:dir/', not 'tahoe mv tahoe:file1 tahoe:dir'.
|
2009-07-20 03:45:03 +00:00
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
Note that it is not possible to use this command to move local files to
|
|
|
|
the grid -- use 'tahoe cp' for that.
|
2009-07-20 03:45:03 +00:00
|
|
|
"""
|
2007-10-12 03:31:48 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class LnOptions(FileStoreOptions):
|
2008-05-20 20:30:31 +00:00
|
|
|
def parseArgs(self, frompath, topath):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_file = argv_to_unicode(frompath)
|
|
|
|
self.to_file = argv_to_unicode(topath)
|
2008-05-20 20:30:31 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] FROM_LINK TO_LINK"
|
2011-01-17 08:14:21 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2011-01-17 08:14:21 +00:00
|
|
|
Use 'tahoe ln' to duplicate a link (directory entry) already on the grid
|
|
|
|
to elsewhere on the grid. For example 'tahoe ln alias:some_file
|
|
|
|
alias:new_file'. causes 'alias:new_file' to point to the same object that
|
|
|
|
'alias:some_file' points to.
|
|
|
|
|
|
|
|
(The argument order is the same as Unix ln. To remember the order, you
|
|
|
|
can think of this command as copying a link, rather than copying a file
|
|
|
|
as 'tahoe cp' does. Then the argument order is consistent with that of
|
|
|
|
'tahoe cp'.)
|
|
|
|
|
|
|
|
When linking a remote file into a remote directory, you'll need to append
|
|
|
|
a '/' to the name of the remote directory, e.g. 'tahoe ln tahoe:file1
|
|
|
|
tahoe:dir/' (which is shorthand for 'tahoe ln tahoe:file1
|
|
|
|
tahoe:dir/file1'). If you forget the '/', e.g. 'tahoe ln tahoe:file1
|
|
|
|
tahoe:dir', the 'ln' command will refuse to overwrite the 'tahoe:dir'
|
|
|
|
directory, and will exit with an error.
|
|
|
|
|
|
|
|
Note that it is not possible to use this command to create links between
|
|
|
|
local and remote files.
|
|
|
|
"""
|
2008-05-20 20:30:31 +00:00
|
|
|
|
2009-02-22 18:08:29 +00:00
|
|
|
class BackupConfigurationError(Exception):
|
|
|
|
pass
|
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class BackupOptions(FileStoreOptions):
|
2009-02-03 04:09:02 +00:00
|
|
|
optFlags = [
|
|
|
|
("verbose", "v", "Be noisy about what is happening."),
|
2010-01-14 20:11:19 +00:00
|
|
|
("ignore-timestamps", None, "Do not use backupdb timestamps to decide whether a local file is unchanged."),
|
2009-02-03 04:09:02 +00:00
|
|
|
]
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
vcs_patterns = ('CVS', 'RCS', 'SCCS', '.git', '.gitignore', '.cvsignore',
|
|
|
|
'.svn', '.arch-ids','{arch}', '=RELEASE-ID',
|
|
|
|
'=meta-update', '=update', '.bzr', '.bzrignore',
|
|
|
|
'.bzrtags', '.hg', '.hgignore', '_darcs')
|
2009-02-22 18:08:29 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(BackupOptions, self).__init__()
|
2009-02-22 23:40:49 +00:00
|
|
|
self['exclude'] = set()
|
2009-02-22 18:08:29 +00:00
|
|
|
|
2009-02-03 04:09:02 +00:00
|
|
|
def parseArgs(self, localdir, topath):
|
2014-08-25 18:09:40 +00:00
|
|
|
self.from_dir = argv_to_abspath(localdir)
|
2010-05-20 00:43:56 +00:00
|
|
|
self.to_dir = argv_to_unicode(topath)
|
2009-02-03 04:09:02 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] FROM ALIAS:TO"
|
2009-02-03 04:09:02 +00:00
|
|
|
|
2009-02-22 18:08:29 +00:00
|
|
|
def opt_exclude(self, pattern):
|
|
|
|
"""Ignore files matching a glob pattern. You may give multiple
|
|
|
|
'--exclude' options."""
|
2010-06-17 03:39:01 +00:00
|
|
|
g = argv_to_unicode(pattern).strip()
|
2009-02-22 18:08:29 +00:00
|
|
|
if g:
|
|
|
|
exclude = self['exclude']
|
2009-02-22 23:40:49 +00:00
|
|
|
exclude.add(g)
|
2009-02-22 18:08:29 +00:00
|
|
|
|
|
|
|
def opt_exclude_from(self, filepath):
|
|
|
|
"""Ignore file matching glob patterns listed in file, one per
|
2010-06-17 03:39:01 +00:00
|
|
|
line. The file is assumed to be in the argv encoding."""
|
2010-10-31 03:52:31 +00:00
|
|
|
abs_filepath = argv_to_abspath(filepath)
|
2009-02-22 18:08:29 +00:00
|
|
|
try:
|
2010-10-31 03:52:31 +00:00
|
|
|
exclude_file = file(abs_filepath)
|
2009-02-22 18:08:29 +00:00
|
|
|
except:
|
2015-01-30 00:04:11 +00:00
|
|
|
raise BackupConfigurationError('Error opening exclude file %s.' % quote_local_unicode_path(abs_filepath))
|
2009-02-22 18:08:29 +00:00
|
|
|
try:
|
|
|
|
for line in exclude_file:
|
|
|
|
self.opt_exclude(line)
|
|
|
|
finally:
|
|
|
|
exclude_file.close()
|
|
|
|
|
|
|
|
def opt_exclude_vcs(self):
|
2010-01-27 20:10:44 +00:00
|
|
|
"""Exclude files and directories used by following version control
|
|
|
|
systems: CVS, RCS, SCCS, Git, SVN, Arch, Bazaar(bzr), Mercurial,
|
|
|
|
Darcs."""
|
2009-02-22 18:08:29 +00:00
|
|
|
for pattern in self.vcs_patterns:
|
|
|
|
self.opt_exclude(pattern)
|
|
|
|
|
|
|
|
def filter_listdir(self, listdir):
|
|
|
|
"""Yields non-excluded childpaths in path."""
|
|
|
|
exclude = self['exclude']
|
2009-02-22 23:40:49 +00:00
|
|
|
exclude_regexps = [re.compile(fnmatch.translate(pat)) for pat in exclude]
|
2009-02-22 18:08:29 +00:00
|
|
|
for filename in listdir:
|
2009-02-22 23:40:49 +00:00
|
|
|
for regexp in exclude_regexps:
|
|
|
|
if regexp.match(filename):
|
|
|
|
break
|
|
|
|
else:
|
2009-02-22 18:08:29 +00:00
|
|
|
yield filename
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Add a versioned backup of the local FROM directory to a timestamped
|
|
|
|
subdirectory of the TO/Archives directory on the grid, sharing as many
|
|
|
|
files and directories as possible with earlier backups. Create TO/Latest
|
|
|
|
as a reference to the latest backup. Behaves somewhat like 'rsync -a
|
|
|
|
--link-dest=TO/Archives/(previous) FROM TO/Archives/(new); ln -sf
|
|
|
|
TO/Archives/(new) TO/Latest'."""
|
2009-02-03 04:09:02 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class WebopenOptions(FileStoreOptions):
|
2010-04-24 23:30:03 +00:00
|
|
|
optFlags = [
|
|
|
|
("info", "i", "Open the t=info page for the file"),
|
|
|
|
]
|
CLI: rework webopen, and moreover its tests w.r.t. path handling
in the recent reconciliation of webopen patches, I wound up adjusting
webopen to 'pass through' the state of the trailing slash on the given
argument to the resultant url passed to the browser. this change
removes the requirement that arguments must be directories, and allows
webopen to be used with files. it also broke the tests that assumed
that webopen would always normalise the url to have a trailing slash.
in fixing the tests, I realised that, IMHO, there's something deeply
awry with the way tahoe handles paths; specifically in the combination
of '/' being the name of the root path within an alias, but a leading
slash on paths, e.g. 'alias:/path', is catagorically incorrect. i.e.
'tahoe:' == 'tahoe:/' == '/'
but 'tahoe:/foo' is an invalid path, and must be 'tahoe:foo'
I wound up making the internals of webopen simply spot a 'path' of
'/' and smash it to '', which 'fixes' webopen to match the behaviour
of tahoe's path handling elsewhere, but that special case sort of
points to the weirdness.
(fwiw, I personally found the fact that the leading / in a path was
disallowed to be weird - I'm just used to seeing paths qualified by
the leading / I guess - so in a debate about normalising path handling
I'd vote to include the /)
2008-09-24 16:45:23 +00:00
|
|
|
def parseArgs(self, where=''):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-09-24 15:20:02 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [ALIAS:PATH]"
|
2008-01-05 01:34:10 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
|
|
|
Open a web browser to the contents of some file or
|
2010-04-24 23:30:03 +00:00
|
|
|
directory on the grid. When run without arguments, open the Welcome
|
|
|
|
page."""
|
2007-07-11 02:37:37 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class ManifestOptions(FileStoreOptions):
|
2008-11-13 03:17:25 +00:00
|
|
|
optFlags = [
|
2010-08-03 08:48:01 +00:00
|
|
|
("storage-index", "s", "Only print storage index strings, not pathname+cap."),
|
|
|
|
("verify-cap", None, "Only print verifycap, not pathname+cap."),
|
|
|
|
("repair-cap", None, "Only print repaircap, not pathname+cap."),
|
|
|
|
("raw", "r", "Display raw JSON data instead of parsed."),
|
2008-11-13 03:17:25 +00:00
|
|
|
]
|
|
|
|
def parseArgs(self, where=''):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-11-13 03:17:25 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [ALIAS:PATH]"
|
|
|
|
description = """
|
|
|
|
Print a list of all files and directories reachable from the given
|
|
|
|
starting point."""
|
2008-11-13 03:17:25 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class StatsOptions(FileStoreOptions):
|
2008-11-18 05:02:19 +00:00
|
|
|
optFlags = [
|
2008-11-19 01:36:08 +00:00
|
|
|
("raw", "r", "Display raw JSON data instead of parsed"),
|
2008-11-18 05:02:19 +00:00
|
|
|
]
|
2008-11-14 02:43:50 +00:00
|
|
|
def parseArgs(self, where=''):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-11-14 02:43:50 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [ALIAS:PATH]"
|
|
|
|
description = """
|
|
|
|
Print statistics about of all files and directories reachable from the
|
|
|
|
given starting point."""
|
2008-11-14 02:43:50 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class CheckOptions(FileStoreOptions):
|
2008-11-19 02:12:10 +00:00
|
|
|
optFlags = [
|
2010-08-03 08:48:01 +00:00
|
|
|
("raw", None, "Display raw JSON data instead of parsed."),
|
|
|
|
("verify", None, "Verify all hashes, instead of merely querying share presence."),
|
|
|
|
("repair", None, "Automatically repair any problems found."),
|
|
|
|
("add-lease", None, "Add/renew lease on all shares."),
|
2008-11-19 02:12:10 +00:00
|
|
|
]
|
2013-04-22 06:37:39 +00:00
|
|
|
def parseArgs(self, *locations):
|
|
|
|
self.locations = map(argv_to_unicode, locations)
|
2008-11-19 02:12:10 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [ALIAS:PATH]"
|
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Check a single file or directory: count how many shares are available and
|
|
|
|
verify their hashes. Optionally repair the file if any problems were
|
|
|
|
found."""
|
2008-11-19 02:12:10 +00:00
|
|
|
|
2014-12-01 21:52:44 +00:00
|
|
|
class DeepCheckOptions(FileStoreOptions):
|
2008-11-19 02:12:10 +00:00
|
|
|
optFlags = [
|
2010-08-03 08:48:01 +00:00
|
|
|
("raw", None, "Display raw JSON data instead of parsed."),
|
|
|
|
("verify", None, "Verify all hashes, instead of merely querying share presence."),
|
|
|
|
("repair", None, "Automatically repair any problems found."),
|
|
|
|
("add-lease", None, "Add/renew lease on all shares."),
|
2009-02-18 00:15:11 +00:00
|
|
|
("verbose", "v", "Be noisy about what is happening."),
|
2008-11-19 02:12:10 +00:00
|
|
|
]
|
2013-04-22 06:37:39 +00:00
|
|
|
def parseArgs(self, *locations):
|
|
|
|
self.locations = map(argv_to_unicode, locations)
|
2008-11-19 02:12:10 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "[options] [ALIAS:PATH]"
|
|
|
|
description = """
|
2010-01-14 20:11:19 +00:00
|
|
|
Check all files and directories reachable from the given starting point
|
|
|
|
(which must be a directory), like 'tahoe check' but for multiple files.
|
|
|
|
Optionally repair any problems found."""
|
2008-11-19 02:12:10 +00:00
|
|
|
|
2007-07-11 02:37:37 +00:00
|
|
|
subCommands = [
|
2010-07-14 01:45:38 +00:00
|
|
|
["mkdir", None, MakeDirectoryOptions, "Create a new directory."],
|
|
|
|
["add-alias", None, AddAliasOptions, "Add a new alias cap."],
|
|
|
|
["create-alias", None, CreateAliasOptions, "Create a new alias cap."],
|
2011-07-24 22:54:40 +00:00
|
|
|
["list-aliases", None, ListAliasesOptions, "List all alias caps."],
|
2010-07-14 01:45:38 +00:00
|
|
|
["ls", None, ListOptions, "List a directory."],
|
2010-01-14 20:11:19 +00:00
|
|
|
["get", None, GetOptions, "Retrieve a file from the grid."],
|
|
|
|
["put", None, PutOptions, "Upload a file into the grid."],
|
2011-01-17 08:14:21 +00:00
|
|
|
["cp", None, CpOptions, "Copy one or more files or directories."],
|
2011-08-01 22:01:08 +00:00
|
|
|
["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid."],
|
2010-01-14 20:11:19 +00:00
|
|
|
["mv", None, MvOptions, "Move a file within the grid."],
|
2011-01-17 08:14:21 +00:00
|
|
|
["ln", None, LnOptions, "Make an additional link to an existing file or directory."],
|
2009-02-03 04:09:02 +00:00
|
|
|
["backup", None, BackupOptions, "Make target dir look like local dir."],
|
2010-01-14 20:11:19 +00:00
|
|
|
["webopen", None, WebopenOptions, "Open a web browser to a grid file or directory."],
|
2010-07-14 01:45:38 +00:00
|
|
|
["manifest", None, ManifestOptions, "List all files/directories in a subtree."],
|
|
|
|
["stats", None, StatsOptions, "Print statistics about all files/directories in a subtree."],
|
|
|
|
["check", None, CheckOptions, "Check a single file or directory."],
|
|
|
|
["deep-check", None, DeepCheckOptions, "Check all files/directories reachable from a starting point."],
|
2016-10-19 05:17:48 +00:00
|
|
|
["status", None, TahoeStatusCommand, "Various status information."],
|
2007-07-11 02:37:37 +00:00
|
|
|
]
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def mkdir(options):
|
2008-05-20 02:28:50 +00:00
|
|
|
from allmydata.scripts import tahoe_mkdir
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_mkdir.mkdir(options)
|
2008-05-20 02:28:50 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def add_alias(options):
|
2008-05-20 02:28:50 +00:00
|
|
|
from allmydata.scripts import tahoe_add_alias
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_add_alias.add_alias(options)
|
2008-05-20 02:28:50 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-02 02:10:41 +00:00
|
|
|
def create_alias(options):
|
|
|
|
from allmydata.scripts import tahoe_add_alias
|
|
|
|
rc = tahoe_add_alias.create_alias(options)
|
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def list_aliases(options):
|
2008-05-20 21:36:04 +00:00
|
|
|
from allmydata.scripts import tahoe_add_alias
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_add_alias.list_aliases(options)
|
2008-05-20 21:36:04 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def list(options):
|
2007-07-11 02:37:37 +00:00
|
|
|
from allmydata.scripts import tahoe_ls
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_ls.list(options)
|
2007-07-11 02:37:37 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def get(options):
|
2007-07-11 02:37:37 +00:00
|
|
|
from allmydata.scripts import tahoe_get
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_get.get(options)
|
2007-07-11 17:26:19 +00:00
|
|
|
if rc == 0:
|
2008-08-01 18:46:24 +00:00
|
|
|
if options.to_file is None:
|
2007-07-11 17:26:19 +00:00
|
|
|
# be quiet, since the file being written to stdout should be
|
|
|
|
# proof enough that it worked, unless the user is unlucky
|
|
|
|
# enough to have picked an empty file
|
|
|
|
pass
|
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%s retrieved and written to %s" % \
|
|
|
|
(options.from_file, options.to_file), file=options.stderr)
|
2007-07-11 02:37:37 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def put(options):
|
2007-08-16 19:15:38 +00:00
|
|
|
from allmydata.scripts import tahoe_put
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_put.put(options)
|
2007-08-17 20:23:16 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def cp(options):
|
2008-05-20 23:56:03 +00:00
|
|
|
from allmydata.scripts import tahoe_cp
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_cp.copy(options)
|
2008-05-20 23:56:03 +00:00
|
|
|
return rc
|
|
|
|
|
2011-08-01 22:01:08 +00:00
|
|
|
def unlink(options, command="unlink"):
|
|
|
|
from allmydata.scripts import tahoe_unlink
|
|
|
|
rc = tahoe_unlink.unlink(options, command=command)
|
2007-08-16 19:15:38 +00:00
|
|
|
return rc
|
|
|
|
|
2011-08-01 22:01:08 +00:00
|
|
|
def rm(options):
|
|
|
|
return unlink(options, command="rm")
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def mv(options):
|
2007-10-12 03:31:48 +00:00
|
|
|
from allmydata.scripts import tahoe_mv
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_mv.mv(options, mode="move")
|
2008-05-20 20:30:31 +00:00
|
|
|
return rc
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def ln(options):
|
2008-05-20 20:30:31 +00:00
|
|
|
from allmydata.scripts import tahoe_mv
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_mv.mv(options, mode="link")
|
2007-10-12 03:31:48 +00:00
|
|
|
return rc
|
|
|
|
|
2009-02-03 04:09:02 +00:00
|
|
|
def backup(options):
|
|
|
|
from allmydata.scripts import tahoe_backup
|
|
|
|
rc = tahoe_backup.backup(options)
|
|
|
|
return rc
|
|
|
|
|
2008-08-12 01:20:23 +00:00
|
|
|
def webopen(options, opener=None):
|
2008-09-24 15:20:02 +00:00
|
|
|
from allmydata.scripts import tahoe_webopen
|
|
|
|
rc = tahoe_webopen.webopen(options, opener=opener)
|
|
|
|
return rc
|
2008-01-05 01:34:10 +00:00
|
|
|
|
2008-11-13 03:17:25 +00:00
|
|
|
def manifest(options):
|
|
|
|
from allmydata.scripts import tahoe_manifest
|
|
|
|
rc = tahoe_manifest.manifest(options)
|
|
|
|
return rc
|
|
|
|
|
2008-11-14 02:43:50 +00:00
|
|
|
def stats(options):
|
|
|
|
from allmydata.scripts import tahoe_manifest
|
|
|
|
rc = tahoe_manifest.stats(options)
|
|
|
|
return rc
|
|
|
|
|
2008-11-19 02:12:10 +00:00
|
|
|
def check(options):
|
|
|
|
from allmydata.scripts import tahoe_check
|
|
|
|
rc = tahoe_check.check(options)
|
|
|
|
return rc
|
|
|
|
|
|
|
|
def deepcheck(options):
|
|
|
|
from allmydata.scripts import tahoe_check
|
|
|
|
rc = tahoe_check.deepcheck(options)
|
|
|
|
return rc
|
|
|
|
|
2016-10-19 05:17:48 +00:00
|
|
|
def status(options):
|
|
|
|
from allmydata.scripts import tahoe_status
|
|
|
|
return tahoe_status.do_status(options)
|
|
|
|
|
2007-07-11 02:37:37 +00:00
|
|
|
dispatch = {
|
2008-05-20 02:28:50 +00:00
|
|
|
"mkdir": mkdir,
|
|
|
|
"add-alias": add_alias,
|
2008-08-02 02:10:41 +00:00
|
|
|
"create-alias": create_alias,
|
2008-05-20 21:36:04 +00:00
|
|
|
"list-aliases": list_aliases,
|
2007-07-11 02:37:37 +00:00
|
|
|
"ls": list,
|
|
|
|
"get": get,
|
2007-08-16 19:15:38 +00:00
|
|
|
"put": put,
|
2008-05-20 23:56:03 +00:00
|
|
|
"cp": cp,
|
2011-08-01 22:01:08 +00:00
|
|
|
"unlink": unlink,
|
2007-08-17 20:23:16 +00:00
|
|
|
"rm": rm,
|
2007-10-12 03:31:48 +00:00
|
|
|
"mv": mv,
|
2008-05-20 20:30:31 +00:00
|
|
|
"ln": ln,
|
2009-02-03 04:09:02 +00:00
|
|
|
"backup": backup,
|
2008-01-05 01:34:10 +00:00
|
|
|
"webopen": webopen,
|
2008-11-13 03:17:25 +00:00
|
|
|
"manifest": manifest,
|
2008-11-14 02:43:50 +00:00
|
|
|
"stats": stats,
|
2008-11-19 02:12:10 +00:00
|
|
|
"check": check,
|
|
|
|
"deep-check": deepcheck,
|
2016-10-19 05:17:48 +00:00
|
|
|
"status": status,
|
2007-07-11 02:37:37 +00:00
|
|
|
}
|