+ self.from_file = argv_to_unicode(frompath)
+ self.to_file = argv_to_unicode(topath)
+
+ synopsis = "[options] FROM_LINK TO_LINK"
+
+ description = """
+ 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.
+ """
+
+class BackupConfigurationError(Exception):
+ pass
+
+class BackupOptions(FilesystemOptions):
+ optFlags = [
+ ("verbose", "v", "Be noisy about what is happening."),
+ ("ignore-timestamps", None, "Do not use backupdb timestamps to decide whether a local file is unchanged."),
+ ]
+
+ vcs_patterns = ('CVS', 'RCS', 'SCCS', '.git', '.gitignore', '.cvsignore',
+ '.svn', '.arch-ids','{arch}', '=RELEASE-ID',
+ '=meta-update', '=update', '.bzr', '.bzrignore',
+ '.bzrtags', '.hg', '.hgignore', '_darcs')
+
+ def __init__(self):
+ super(BackupOptions, self).__init__()
+ self['exclude'] = set()
+
+ def parseArgs(self, localdir, topath):
+ self.from_dir = argv_to_abspath(localdir)
+ self.to_dir = argv_to_unicode(topath)
+
+ synopsis = "[options] FROM ALIAS:TO"
+
+ def opt_exclude(self, pattern):
+ """Ignore files matching a glob pattern. You may give multiple
+ '--exclude' options."""
+ g = argv_to_unicode(pattern).strip()
+ if g:
+ exclude = self['exclude']
+ exclude.add(g)
+
+ def opt_exclude_from(self, filepath):
+ """Ignore file matching glob patterns listed in file, one per
+ line. The file is assumed to be in the argv encoding."""
+ abs_filepath = argv_to_abspath(filepath)
+ try:
+ exclude_file = file(abs_filepath)
+ except:
+ raise BackupConfigurationError('Error opening exclude file %s.' % quote_local_unicode_path(abs_filepath))
+ try:
+ for line in exclude_file:
+ self.opt_exclude(line)
+ finally:
+ exclude_file.close()
+
+ def opt_exclude_vcs(self):
+ """Exclude files and directories used by following version control
+ systems: CVS, RCS, SCCS, Git, SVN, Arch, Bazaar(bzr), Mercurial,
+ Darcs."""
+ for pattern in self.vcs_patterns:
+ self.opt_exclude(pattern)
+
+ def filter_listdir(self, listdir):
+ """Yields non-excluded childpaths in path."""
+ exclude = self['exclude']
+ exclude_regexps = [re.compile(fnmatch.translate(pat)) for pat in exclude]
+ for filename in listdir:
+ for regexp in exclude_regexps:
+ if regexp.match(filename):
+ break
+ else:
+ yield filename
+
+ description = """
+ 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'."""
+
+class WebopenOptions(FilesystemOptions):
+ optFlags = [
+ ("info", "i", "Open the t=info page for the file"),
+ ]
+ def parseArgs(self, where=''):
+ self.where = argv_to_unicode(where)
+
+ synopsis = "[options] [ALIAS:PATH]"
+
+ description = """
+ Open a web browser to the contents of some file or
+ directory on the grid. When run without arguments, open the Welcome
+ page."""
+
+class ManifestOptions(FilesystemOptions):
+ optFlags = [
+ ("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."),
+ ]
+ def parseArgs(self, where=''):
+ self.where = argv_to_unicode(where)
+
+ synopsis = "[options] [ALIAS:PATH]"
+ description = """
+ Print a list of all files and directories reachable from the given
+ starting point."""
+
+class StatsOptions(FilesystemOptions):
+ optFlags = [
+ ("raw", "r", "Display raw JSON data instead of parsed"),
+ ]
+ def parseArgs(self, where=''):
+ self.where = argv_to_unicode(where)