def test_getBackupOrLastest_usingWordArgs(self):
     args = fn.parseWordArgs(["from", "backup", "1"])
     backup = fn.getBackupOrLatest(args, self._backupHome)
     self.assertEqual(
         backup,
         "2012-03-30-160006",
         "Incorrect backup returned: {0}".format(backup))
 def test_getBackupOrLastest_expectingLatest(self):
     args = fn.parseWordArgs([])
     backup = fn.getBackupOrLatest(args, self._backupHome)
     self.assertEqual(
         backup,
         "2012-05-18-160013",
         "Incorrect backup returned: {0}".format(backup))
 def test_getBackupsForArgs_all(self):
     args = fn.parseWordArgs(["from", "all"])
     backups = fn.getBackupsForArgs(args, fn.getBackups(self._backupHome))
     self.assertEqual(
         len(backups),
         3,
         "Incorrect number of backups returned: {0}".format(len(backups)))
Esempio n. 4
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))
Esempio n. 5
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)
Esempio n. 6
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"])
Esempio n. 7
0
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))
Esempio n. 8
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)
 def test_getBackupsForArgs_oneId(self):
     args = fn.parseWordArgs(["from", "backup", "2"])
     backups = fn.getBackupsForArgs(args, fn.getBackups(self._backupHome))
     self.assertEqual(backups[2], "2012-05-18-160013")
Esempio n. 10
0
 def test_getArgs_fromAll(self):
     args = fn.parseWordArgs(["from", "all"])
     self.assertEqual(args["glob"], "*")
     self.assertEqual(args["id"], "all")
     self.assertEqual(args["as"], None)
Esempio n. 11
0
 def test_getArgs_glob(self):
     args = fn.parseWordArgs(["foo"])
     self.assertEqual(args["glob"], "foo")
     self.assertEqual(args["id"], None)
     self.assertEqual(args["as"], None)
Esempio n. 12
0
 def test_getArgs_id(self):
     args = fn.parseWordArgs(["from", "backup", "43"])
     self.assertEqual(args["glob"], "*")
     self.assertEqual(args["id"], "43")
     self.assertEqual(args["as"], None)
Esempio n. 13
0
 def test_getArgs_allParameters(self):
     args = fn.parseWordArgs(["asdf", "from", "backup", "43", "as", "bar"])
     self.assertEqual(args["glob"], "asdf")
     self.assertEqual(args["id"], "43")
     self.assertEqual(args["as"], "bar")