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])
示例#2
0
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))
示例#3
0
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)
示例#4
0
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"])
示例#5
0
文件: diff.py 项目: inglor/caatinga
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))
示例#6
0
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)