+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."""