def test_expandGlob(self): backup = "2012-03-30-160006" cwd = "/foo" items = fn.expandGlob(self._backupHome, backup, cwd, "b*") expected = [ join(self._backupHome, backup) + cwd + sep + "bar.gz", join(self._backupHome, backup) + cwd + sep + "bed.py"] items.sort() expected.sort() for i in range(len(items)): self.assertEqual(items[i], expected[i])
def listFiles(args, settings): """ Main function for the list option. """ wordArgs = fn.parseWordArgs(args) home = fn.getBackupHome(settings.backupLocation, settings.hostName) backups = fn.getBackupsForArgs(wordArgs, fn.getBackups(home)) backupWd = fn.removeAltRoot(settings.root, os.getcwd()) for id_ in backups.keys(): items = fn.expandGlob(home, backups[id_], backupWd, wordArgs["glob"]) for item in items: _outputItemInfo(id_, fn.getInfo(item))
def remove(args, settings): """ Main function for the remove option. """ wordArgs = fn.parseWordArgs(args) _validateArgs(wordArgs) home = fn.getBackupHome(settings.backupLocation, settings.hostName) backups = fn.getBackupsForArgs(wordArgs, fn.getBackups(home)) backupWd = fn.removeAltRoot(settings.root, os.getcwd()) for id_ in backups.keys(): items = fn.expandGlob(home, backups[id_], backupWd, wordArgs["glob"]) for item in items: _delete(item)
def restore(args, settings): """ Main function for the restore option. """ wordArgs = fn.parseWordArgs(args) _validateArgs(wordArgs) home = fn.getBackupHome(settings.backupLocation, settings.hostName) fn.insureBackupHomeExists(home) backup = fn.getBackupOrLatest(wordArgs, home) cwd = os.getcwd() backupWd = fn.removeAltRoot(settings.root, cwd) items = fn.expandGlob(home, backup, backupWd, wordArgs["glob"]) _validateItems(items, wordArgs) for item in items: _restoreItem(item, cwd, wordArgs["as"])
def diff(args, settings): """ Main function for the diff option. """ wordArgs = fn.parseWordArgs(args) _validateArgs(wordArgs) home = fn.getBackupHome(settings.backupLocation, settings.hostName) fn.insureBackupHomeExists(home) backup = fn.getBackupOrLatest(wordArgs, home) cwd = os.getcwd() backupWd = fn.removeAltRoot(settings.root, cwd) items = fn.expandGlob(home, backup, backupWd, wordArgs["glob"]) _validateItems(items) localFile = _getLines(join(cwd, wordArgs["glob"])) backupFile = _getLines(items[0]) diff = _getDiff() sys.stdout.writelines(diff(backupFile, localFile))
def changes(args, settings): """ Main function for the changes option. """ wordArgs = fn.parseWordArgs(args) _validateArgs(wordArgs) home = fn.getBackupHome(settings.backupLocation, settings.hostName) fn.insureBackupHomeExists(home) backup = fn.getBackupOrLatest(wordArgs, home) cwd = os.getcwd() backupWd = fn.removeAltRoot(settings.root, cwd) backedUpFiles = fn.expandGlob(home, backup, backupWd, "*") backupDir = join(home, backup) + backupWd allFiles = set(os.listdir(cwd)).union(map(basename, backedUpFiles)) for item in allFiles: status = _getStatus(join(cwd, item), join(backupDir, item)) if status: _outputItem(item, status)