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)
def test_insureBackupHomeExists_noException(self): fn.insureBackupHomeExists(self._backupHome)