2009-02-22 18:08:29 +00:00
|
|
|
import os.path, re, sys, fnmatch
|
2007-07-11 02:37:37 +00:00
|
|
|
from twisted.python import usage
|
2010-08-02 04:30:04 +00:00
|
|
|
from allmydata.scripts.common import BaseOptions, get_aliases, get_default_nodedir, DEFAULT_ALIAS
|
|
|
|
from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_output
|
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()
|
|
|
|
|
|
|
|
class VDriveOptions(BaseOptions):
|
2007-07-11 02:37:37 +00:00
|
|
|
optParameters = [
|
2010-08-02 04:30:04 +00:00
|
|
|
["node-directory", "d", None,
|
|
|
|
"Specify which Tahoe node directory should be used. The directory "
|
|
|
|
"should either contain a full Tahoe node, or a file named node.url "
|
|
|
|
"that points to some other Tahoe node. It should also contain a file "
|
2010-08-03 08:54:16 +00:00
|
|
|
"named '" + os.path.join('private', 'aliases') + "' which contains the "
|
|
|
|
"mapping from alias name to root dirnode URI." + (
|
|
|
|
_default_nodedir and (" [default: " + quote_output(_default_nodedir) + "]") or "")],
|
2007-08-16 23:53:27 +00:00
|
|
|
["node-url", "u", None,
|
2010-08-03 08:48:01 +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):
|
2007-10-11 07:30:36 +00:00
|
|
|
if self['node-directory']:
|
2010-08-02 04:30:04 +00:00
|
|
|
self['node-directory'] = argv_to_abspath(self['node-directory'])
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
class MakeDirectoryOptions(VDriveOptions):
|
|
|
|
def parseArgs(self, where=""):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-05-20 02:28:50 +00:00
|
|
|
longdesc = """Create a new directory, either unlinked or as a subdirectory."""
|
|
|
|
|
|
|
|
class AddAliasOptions(VDriveOptions):
|
|
|
|
def parseArgs(self, alias, cap):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.alias = argv_to_unicode(alias)
|
2008-05-20 02:28:50 +00:00
|
|
|
self.cap = cap
|
2007-10-11 07:30:36 +00:00
|
|
|
|
2009-02-21 01:31:06 +00:00
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s add-alias ALIAS DIRCAP" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
|
|
|
longdesc = """Add a new alias for an existing directory."""
|
|
|
|
|
2008-08-02 02:10:41 +00:00
|
|
|
class CreateAliasOptions(VDriveOptions):
|
|
|
|
def parseArgs(self, alias):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.alias = argv_to_unicode(alias)
|
2008-08-02 02:10:41 +00:00
|
|
|
|
2009-02-21 01:31:06 +00:00
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s create-alias ALIAS" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """Create a new directory and add an alias for it."""
|
2009-02-21 01:31:06 +00:00
|
|
|
|
2008-05-20 21:36:04 +00:00
|
|
|
class ListAliasOptions(VDriveOptions):
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """Display a table of all configured aliases."""
|
2008-05-20 21:36:04 +00:00
|
|
|
|
2007-07-11 02:37:37 +00:00
|
|
|
class ListOptions(VDriveOptions):
|
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."),
|
|
|
|
("uri", "u", "Show file/directory URIs."),
|
|
|
|
("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
|
|
|
|
2010-02-20 06:13:13 +00:00
|
|
|
longdesc = """
|
|
|
|
List the contents of some portion of the grid.
|
|
|
|
|
|
|
|
When the -l or --long option is used, each line is shown in the
|
|
|
|
following format:
|
|
|
|
|
|
|
|
drwx <size> <date/time> <name in this directory>
|
|
|
|
|
|
|
|
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 '?'.
|
|
|
|
|
|
|
|
The date/time shows when this link in the Tahoe filesystem was
|
|
|
|
last modified.
|
|
|
|
"""
|
2007-08-16 19:50:19 +00:00
|
|
|
|
2007-07-11 02:37:37 +00:00
|
|
|
class GetOptions(VDriveOptions):
|
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
|
|
|
|
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_file = argv_to_unicode(arg1)
|
|
|
|
|
|
|
|
if arg2:
|
|
|
|
self.to_file = argv_to_unicode(arg2)
|
|
|
|
else:
|
|
|
|
self.to_file = None
|
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
if self.to_file == "-":
|
|
|
|
self.to_file = None
|
2007-07-11 02:37:37 +00:00
|
|
|
|
2007-07-11 17:26:19 +00:00
|
|
|
def getSynopsis(self):
|
2010-01-14 20:11:19 +00:00
|
|
|
return "%s get REMOTE_FILE LOCAL_FILE" % (os.path.basename(sys.argv[0]),)
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """
|
|
|
|
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
|
|
|
|
2008-06-03 00:54:56 +00:00
|
|
|
def getUsage(self, width=None):
|
|
|
|
t = VDriveOptions.getUsage(self, width)
|
|
|
|
t += """
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
return t
|
|
|
|
|
2007-08-16 19:15:38 +00:00
|
|
|
class PutOptions(VDriveOptions):
|
2008-05-20 19:36:55 +00:00
|
|
|
optFlags = [
|
|
|
|
("mutable", "m", "Create a mutable file instead of an immutable one."),
|
|
|
|
]
|
|
|
|
|
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
|
|
|
|
|
|
|
if arg1 is not None and arg2 is not None:
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_file = argv_to_unicode(arg1)
|
|
|
|
self.to_file = argv_to_unicode(arg2)
|
2008-05-20 02:28:50 +00:00
|
|
|
elif arg1 is not None and arg2 is None:
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_file = argv_to_unicode(arg1) # might be "-"
|
2008-08-02 02:27:29 +00:00
|
|
|
self.to_file = None
|
2008-05-20 02:28:50 +00:00
|
|
|
else:
|
2008-08-02 02:27:29 +00:00
|
|
|
self.from_file = None
|
|
|
|
self.to_file = None
|
2010-05-20 00:43:56 +00:00
|
|
|
if self.from_file == u"-":
|
2008-05-20 02:28:50 +00:00
|
|
|
self.from_file = None
|
2007-08-16 19:15:38 +00:00
|
|
|
|
|
|
|
def getSynopsis(self):
|
2010-01-14 20:11:19 +00:00
|
|
|
return "%s put LOCAL_FILE REMOTE_FILE" % (os.path.basename(sys.argv[0]),)
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """
|
|
|
|
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
|
|
|
|
with tahoe: unless otherwise specified."""
|
2008-06-03 00:54:56 +00:00
|
|
|
|
|
|
|
def getUsage(self, width=None):
|
|
|
|
t = VDriveOptions.getUsage(self, width)
|
|
|
|
t += """
|
|
|
|
Examples:
|
2009-01-27 22:39:09 +00:00
|
|
|
% cat FILE | tahoe put # create unlinked file from stdin
|
|
|
|
% cat FILE | tahoe - # same
|
2008-08-02 02:27:29 +00:00
|
|
|
% tahoe put bar # create unlinked file from local 'bar'
|
2009-01-27 22:39:09 +00:00
|
|
|
% cat FILE | tahoe put - FOO # create tahoe:FOO from stdin
|
2008-08-02 02:27:29 +00:00
|
|
|
% 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
|
2008-06-03 00:54:56 +00:00
|
|
|
"""
|
|
|
|
return t
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2008-05-20 23:56:03 +00:00
|
|
|
class CpOptions(VDriveOptions):
|
|
|
|
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
|
|
|
]
|
|
|
|
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])
|
2009-06-25 23:57:51 +00:00
|
|
|
def getSynopsis(self):
|
|
|
|
return "Usage: tahoe [options] cp FROM.. TO"
|
|
|
|
longdesc = """
|
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
|
|
|
|
|
|
|
tahoe cp ~/foo.txt home: # creates tahoe-side home:foo.txt
|
|
|
|
|
|
|
|
tahoe cp ~/foo.txt /tmp/bar.txt home: # copies two files to home:
|
|
|
|
|
2009-06-26 02:45:57 +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
|
|
|
|
2010-07-21 01:05:43 +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
|
|
|
|
2009-06-26 02:38:37 +00:00
|
|
|
This command still has some limitations: symlinks, special files (device
|
|
|
|
nodes, named pipes), and non-ASCII filenames are not handled very well.
|
|
|
|
Arguments should probably not have trailing slashes. 'tahoe cp' does not
|
|
|
|
behave as much like /bin/cp as you would wish, especially with respect to
|
|
|
|
trailing slashes.
|
2009-06-25 23:57:51 +00:00
|
|
|
"""
|
2008-05-20 23:56:03 +00:00
|
|
|
|
2007-08-17 20:23:16 +00:00
|
|
|
class RmOptions(VDriveOptions):
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
2010-01-14 20:11:19 +00:00
|
|
|
return "%s rm REMOTE_FILE" % (os.path.basename(sys.argv[0]),)
|
2007-08-16 19:15:38 +00:00
|
|
|
|
2010-08-03 08:53:59 +00:00
|
|
|
class UnlinkOptions(RmOptions):
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s unlink REMOTE_FILE" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2007-10-12 03:31:48 +00:00
|
|
|
class MvOptions(VDriveOptions):
|
|
|
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s mv FROM TO" % (os.path.basename(sys.argv[0]),)
|
2009-07-20 03:45:03 +00:00
|
|
|
longdesc = """
|
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
|
|
|
|
2008-05-20 20:30:31 +00:00
|
|
|
class LnOptions(VDriveOptions):
|
|
|
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s ln FROM TO" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2009-02-22 18:08:29 +00:00
|
|
|
class BackupConfigurationError(Exception):
|
|
|
|
pass
|
|
|
|
|
2009-02-03 04:09:02 +00:00
|
|
|
class BackupOptions(VDriveOptions):
|
|
|
|
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):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.from_dir = argv_to_unicode(localdir)
|
|
|
|
self.to_dir = argv_to_unicode(topath)
|
2009-02-03 04:09:02 +00:00
|
|
|
|
|
|
|
def getSynopsis(Self):
|
|
|
|
return "%s backup FROM ALIAS:TO" % os.path.basename(sys.argv[0])
|
|
|
|
|
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:
|
2010-10-31 03:52:31 +00:00
|
|
|
raise BackupConfigurationError('Error opening exclude file %s.' % quote_output(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
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """
|
|
|
|
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
|
|
|
|
2008-01-05 01:34:10 +00:00
|
|
|
class WebopenOptions(VDriveOptions):
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s webopen [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),)
|
2008-01-05 01:34:10 +00:00
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """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
|
|
|
|
2008-11-13 03:17:25 +00:00
|
|
|
class ManifestOptions(VDriveOptions):
|
|
|
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s manifest [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """Print a list of all files and directories reachable from
|
|
|
|
the given starting point."""
|
2008-11-13 03:17:25 +00:00
|
|
|
|
2008-11-14 02:43:50 +00:00
|
|
|
class StatsOptions(VDriveOptions):
|
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
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s stats [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """Print statistics about of all files and directories
|
|
|
|
reachable from the given starting point."""
|
2008-11-14 02:43:50 +00:00
|
|
|
|
2008-11-19 02:12:10 +00:00
|
|
|
class CheckOptions(VDriveOptions):
|
|
|
|
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
|
|
|
]
|
|
|
|
def parseArgs(self, where=''):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-11-19 02:12:10 +00:00
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s check [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """
|
|
|
|
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
|
|
|
|
|
|
|
class DeepCheckOptions(VDriveOptions):
|
|
|
|
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
|
|
|
]
|
|
|
|
def parseArgs(self, where=''):
|
2010-05-20 00:43:56 +00:00
|
|
|
self.where = argv_to_unicode(where)
|
2008-11-19 02:12:10 +00:00
|
|
|
|
|
|
|
def getSynopsis(self):
|
|
|
|
return "%s deep-check [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),)
|
|
|
|
|
2010-01-14 20:11:19 +00:00
|
|
|
longdesc = """
|
|
|
|
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."],
|
|
|
|
["list-aliases", None, ListAliasOptions, "List all alias caps."],
|
|
|
|
["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."],
|
2008-05-20 23:56:03 +00:00
|
|
|
["cp", None, CpOptions, "Copy one or more files."],
|
2010-01-14 20:11:19 +00:00
|
|
|
["rm", None, RmOptions, "Unlink a file or directory on the grid."],
|
2010-08-03 08:53:59 +00:00
|
|
|
["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid (same as rm)."],
|
2010-01-14 20:11:19 +00:00
|
|
|
["mv", None, MvOptions, "Move a file within the grid."],
|
2008-05-20 20:30:31 +00:00
|
|
|
["ln", None, LnOptions, "Make an additional link to an existing file."],
|
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."],
|
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:
|
2008-08-01 18:46:24 +00:00
|
|
|
print >>options.stderr, "%s retrieved and written to %s" % \
|
|
|
|
(options.from_file, options.to_file)
|
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
|
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def rm(options):
|
2007-08-17 20:23:16 +00:00
|
|
|
from allmydata.scripts import tahoe_rm
|
2008-08-01 18:46:24 +00:00
|
|
|
rc = tahoe_rm.rm(options)
|
2007-08-16 19:15:38 +00:00
|
|
|
return rc
|
|
|
|
|
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
|
|
|
|
|
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,
|
2007-08-17 20:23:16 +00:00
|
|
|
"rm": rm,
|
2010-07-17 22:04:11 +00:00
|
|
|
"unlink": 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,
|
2007-07-11 02:37:37 +00:00
|
|
|
}
|