Ejemplo n.º 1
0
    def test_sort_sids(self):
        root = snapshots.RootSnapshot(self.cfg)
        new = snapshots.NewSnapshot(self.cfg)
        sid1 = snapshots.SID('20151219-010324-123', self.cfg)
        sid2 = snapshots.SID('20151219-020324-123', self.cfg)
        sid3 = snapshots.SID('20151219-030324-123', self.cfg)
        sid4 = snapshots.SID('20151219-040324-123', self.cfg)

        sids1 = [sid3, sid1, sid4, sid2]
        sids1.sort()
        self.assertEqual(sids1, [sid1, sid2, sid3, sid4])

        #RootSnapshot 'Now' should always stay on top
        sids2 = [sid3, sid1, root, sid4, sid2]
        sids2.sort()
        self.assertEqual(sids2, [sid1, sid2, sid3, sid4, root])

        sids2.sort(reverse=True)
        self.assertEqual(sids2, [root, sid4, sid3, sid2, sid1])

        #new_snapshot should always be the last
        sids3 = [sid3, sid1, new, sid4, sid2]
        sids3.sort()
        self.assertEqual(sids3, [sid1, sid2, sid3, sid4, new])

        sids3.sort(reverse=True)
        self.assertEqual(sids3, [new, sid4, sid3, sid2, sid1])
Ejemplo n.º 2
0
    def test_create_new(self):
        new = snapshots.NewSnapshot(self.cfg)
        self.assertFalse(new.exists())

        self.assertTrue(new.makeDirs())
        self.assertTrue(new.exists())
        self.assertTrue(
            os.path.isdir(
                os.path.join(self.snapshotPath, new.NEWSNAPSHOT, 'backup')))
Ejemplo n.º 3
0
    def test_no_changes(self, takeSnapshot, sleep):
        takeSnapshot.return_value = [False, False]
        self.assertFalse(self.sn.backup())
        self.assertTrue(takeSnapshot.called)

        sid = takeSnapshot.call_args[0][0]
        newSnapshot = snapshots.NewSnapshot(self.cfg)
        self.assertFalse(newSnapshot.exists())
        self.assertFalse(sid.exists())
Ejemplo n.º 4
0
 def test_takeSnapshot_exception_cleanup(self, takeSnapshot, sleep):
     takeSnapshot.side_effect = Exception('Boom')
     new = snapshots.NewSnapshot(self.cfg)
     new.makeDirs()
     self.assertTrue(new.exists())
     with self.assertRaises(Exception):
         self.sn.backup()
     self.assertFalse(new.saveToContinue)
     self.assertTrue(new.failed)
Ejemplo n.º 5
0
    def test_takeSnapshot_new_exists(self, sleep):
        new_snapshot = snapshots.NewSnapshot(self.cfg)
        new_snapshot.makeDirs()
        with open(new_snapshot.path('leftover'), 'wt') as f:
            f.write('foo')

        now = datetime.today() - timedelta(minutes = 6)
        sid1 = snapshots.SID(now, self.cfg)

        self.assertListEqual([True, False], self.sn.takeSnapshot(sid1, now, [(self.include.name, 0),]))
        self.assertTrue(sid1.exists())
        self.assertFalse(os.path.exists(sid1.path('leftover')))
Ejemplo n.º 6
0
    def test_hasChanges(self):
        now = datetime(2016, 7, 10, 16, 24, 17)

        new = snapshots.NewSnapshot(self.cfg)
        new.makeDirs()

        log = SnapshotLog(self.cfg)
        log.new(now)
        self.assertFalse(new.hasChanges)
        log.append('[I] foo', log.ALL)
        log.append('[E] bar', log.ALL)
        log.flush()
        self.assertFalse(new.hasChanges)
        log.append('[C] baz', log.ALL)
        log.flush()
        self.assertTrue(new.hasChanges)
Ejemplo n.º 7
0
    def test_saveToContinue(self):
        new = snapshots.NewSnapshot(self.cfg)
        snapshotPath = os.path.join(self.snapshotPath, new.NEWSNAPSHOT)
        saveToContinuePath = os.path.join(snapshotPath, new.SAVETOCONTINUE)
        os.makedirs(snapshotPath)

        self.assertNotExists(saveToContinuePath)
        self.assertFalse(new.saveToContinue)

        new.saveToContinue = True
        self.assertExists(saveToContinuePath)
        self.assertTrue(new.saveToContinue)

        new.saveToContinue = False
        self.assertNotExists(saveToContinuePath)
        self.assertFalse(new.saveToContinue)
Ejemplo n.º 8
0
    def new(self, date):
        """
        Create a new log file or - if the last new_snapshot can be continued -
        add a note to the current log.

        Args:
            date (datetime.datetime):   current date
        """
        if snapshots.NewSnapshot(self.config).saveToContinue:
            msg = "Last snapshot didn't finish but can be continued.\n\n"
            msg += "======== continue snapshot (profile %s): %s ========\n"
        else:
            if os.path.exists(self.logFileName):
                if self.logFile:
                    self.logFile.close()
                    self.logFile = None
                os.remove(self.logFileName)
            msg = "========== Take snapshot (profile %s): %s ==========\n"
        self.append(msg % (self.profile, date.strftime('%c')), 1)
Ejemplo n.º 9
0
    def test_new_continue(self):
        log = snapshotlog.SnapshotLog(self.cfg)
        now = datetime.today()
        with open(self.logFile, 'wt') as f:
            f.write('foo\nbar\n')
        new = snapshots.NewSnapshot(self.cfg)
        new.makeDirs()
        new.saveToContinue = True

        log.new(now)
        log.flush()
        self.assertTrue(os.path.exists(self.logFile))
        with open(self.logFile, 'rt') as f:
            self.assertRegex(f.read(), re.compile(r'''foo
bar
Last snapshot didn't finish but can be continued.

======== continue snapshot \(profile .*\): .* ========

''', re.MULTILINE))
Ejemplo n.º 10
0
    ######################
    ### Restore Dialog ###
    ######################

    mainWindow = app.MainWindow(cfg, appInstance, qapp)
    setScreenshotTimerDlg(
        mainWindow, lambda: mainWindow.confirmRestore(
            ('/home/janedoe/Documents', '/home/janedoe/Pictures')),
        '_images/restore_confirm.png')

    ########################
    ### Snapshots Dialog ###
    ########################

    snDlg = SnapshotsDialog(mainWindow, snapshots.NewSnapshot(cfg),
                            '/home/janedoe/foo')
    snDlg.addSnapshot(rootSid)
    snDlg.comboEqualTo.addSnapshotID(rootSid)
    for sid in mainWindow.snapshotsList:
        snDlg.addSnapshot(sid)
    snDlg.cbDeepCheck.setEnabled(True)
    setScreenshotTimer(snDlg, '_images/snapshotsdialog.png', None, None)

    #################################
    ### Settings Dialog - General ###
    #################################

    settings = settingsdialog.SettingsDialog(mainWindow)
    settings.editSnapshotsPath.setText('/media/janedoe/ExternalDrive')
    settings.txtHost.setText('testhost')